我有一个django测试方法,它检查作为httpresponse返回的图像是否等于在将http请求发送到视图之前打开的图像:
def test_uploaded_file(self):
c = Client()
originalFilePath = '../static_cdn/test_img.jpg'
image_data = open(originalFilePath, "rb")
with open(originalFilePath, "rb") as fp:
response = c.post('/', {'image': fp})
self.assertEqual(image_data,response)
由于某些原因,测试返回以下错误:
^{pr2}$我认为这个问题与以下事实有关:从视图返回的图像是httpresponse,而在测试方法中打开的另一个图像则不是。为什么这个测试会失败?能否从响应中提取图像?
您正在将打开的文件与http响应进行比较。从http响应中获取图像,然后打开它并进行比较。在
相关问题 更多 >
编程相关推荐