问题描述
我正在测试一个将图像上传到用户个人资料的API调用。下面的测试用例返回状态代码400。如果我从数据中删除了image_filename键,则测试用例成功。如何在pytest中测试图片上传?
def test_edit_user_profile(db,client):
# stream the image into binary
with open('C:/...../test.png','rb') as consultant_image:
image_binary = BytesIO(consultant_image.read())
userdetail_response = client.patch(path=reverse('user-detail',args="1"),data={"full_name": "James edited","image_filename": (image_binary,'test2.png')},content_type='multipart/form-data',HTTP_AUTHORIZATION='Token ' + data.json()['token_key'])
assert userdetail_response.status_code == status.HTTP_200_OK
解决方法
此解决方案有效
x=var('x')
R.<x>=PolynomialRing(QQ)
def div(p,q):
if q==0:
return("NaN")
elif q!=0:
l=0
r=p
while r!=0 and q.degree()<=r.degree():
t=r.leading_coefficient()/q.leading_coefficient()
m=x^r.degree()/x^q.degree()
m=R(m)
l=l+t*m
r=r-(t*m*q)
print(l,r)
return(l,r)