自己搞错接口地址了,删除问题。

来源:7-3 实战:上传文件-修改个人头像用例编写

慕粉3558621

2023-04-03

接口上传的头像,没有更新,头像地址没有存入数据库
postman上传头像,头像会更新,头像地址会存入数据库
为啥呢?

写回答

1回答

william

2023-04-03

看看你的代码。或者进qq群直接提问。
0
2
慕粉3558621
import allure from urllib3 import encode_multipart_formdata from common.common_requests import Requests from common.tools import sep, get_project_path class TestApi: @allure.feature("product") @allure.story("upload_img") @allure.description("上传头像图片") def test_upload_image(self, token): img_path = get_project_path() + sep(["img", "head.jpg"], add_sep_before=True) file_data = {"file": ("upload_img", open(img_path, "rb").read())} #接口格式 file : with open()as upload_img encode_data = encode_multipart_formdata(file_data) #转为url格式 # print(encode_data) # print(encode_data[0]) # print(encode_data[1]) data = encode_data[0] headers = {"token": token("miaozz"), "Content-Type": encode_data[1]} res = Requests(headers).post("/api/product/upload_img", data=data) print(res.json()) assert res.json()["code"] == 200 assert res.json()["msg"] == "成功" 写错了调用接口,没想到也能调用成功,{'code': 200, 'data': 'http://192.168.1.73:9090/product/product_img/16801476474095ad508a8-4681-4e3f-98ff-7380d05b095d', 'msg': '成功'} 就是不是头像的,所以我一直看头像有没有更新,最后发现是自己的接口地址写错了。
2023-04-03
共2条回复

轻松掌握Python+主流测试框架,快速转型自动化测试

Python3+Pytest+Requests+Allure零基础入门Python接口自动化测试

440 学习 · 78 问题

查看课程