【发布时间】:2015-02-05 03:23:29
【问题描述】:
我正在尝试使用 django 1.7、DRF 2.4.3 和 Pillow 2.6.1 测试图像上传字段。
文件上传在管理员和我使用 curl 测试时正常工作
curl -X POST -S -H 'Accept: application/json' -F 'my_image=@hm.jpg;type=image/jpg' http://localhost:8000/api/randomresource/
当我在APITestCase 中进行类似测试时
temp_file = open('hm.jpg',"r")
response = self.client.post('randomresource', {"my_image":temp_file}, format='multipart')
self.assertEqual(response.status_code,status.HTTP_201_CREATED)
我明白了
{'my_image': [u'Upload a valid image. The file you uploaded was either not an image or a corrupted image.']}
感谢任何帮助。 谢谢。
【问题讨论】:
-
您是否尝试过使用
rb标志而不是r? -
工作!发表一个答案,我会接受的。
标签: django unit-testing django-rest-framework