Если URL-адрес предназначен для создания файла, а не «обычного» http-ответа, то его content-type
и / или content-disposition
будут другими.
объект ответа - это в основном словарь, так что вы могли бы что-то вроде
self.assertEquals(
response.get('Content-Disposition'),
"attachment; filename=mypic.jpg"
)
больше информации:
https://docs.djangoproject.com/en/dev/ref/request-response/#telling-the-browser-to-treat-the-response-as-a-file-attachment
UPD:
Если вы хотите прочитать фактическое содержимое вложенного файла, вы можете использовать response.content. Пример для zip-файла:
try:
f = io.BytesIO(response.content)
zipped_file = zipfile.ZipFile(f, 'r')
self.assertIsNone(zipped_file.testzip())
self.assertIn('my_file.txt', zipped_file.namelist())
finally:
zipped_file.close()
f.close()