我定义了一个API端点,可以接受文件(例如使用Django REST Framework)。在Django中,当检查响应时可以使用content disposition头部。
如果我们希望在测试端点时设置头部,该如何使用REST-Framework的APITestCase包含这个头部呢?
我所尝试的是,但它似乎不接受这些头部。
参考链接:https://docs.djangoproject.com/en/1.11/ref/request-response/#telling-the-browser-to-treat-the-response-as-a-file-attachment
如果我们希望在测试端点时设置头部,该如何使用REST-Framework的APITestCase包含这个头部呢?
我所尝试的是,但它似乎不接受这些头部。
参考链接:https://docs.djangoproject.com/en/1.11/ref/request-response/#telling-the-browser-to-treat-the-response-as-a-file-attachment
class TestSaleViews(APITestCase):
def test_sale_detail_view(self):
f = create_named_temporary_file()
files = {'archive': f}
basename = os.path.basename(f.name)
headers = {
'content-disposition': 'attachment; filename={}'.format(basename),
}
response = self.client.post(url, files, format='multipart', **headers)