Ответ 1
Если 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()