def test_pdf_template_view_unicode(self, show_content=False):
"""Test PDFTemplateView with unicode content."""
view = UnicodeContentPDFTemplateView.as_view(
filename=self.pdf_filename,
show_content_in_browser=show_content,
template_name=self.template
)
# As PDF
request = RequestFactory().get('/')
response = view(request)
self.assertEqual(response.status_code, 200)
response.render()
fileheader = self.attached_fileheader
if show_content:
fileheader = self.inline_fileheader
self.assertEqual(response['Content-Disposition'],
fileheader.format(self.pdf_filename))
# not sure how we can test this as the contents is all encoded...
# best we can do for the moment is check it's a pdf and it worked.
# self.assertTrue('?' in response.content)
self.assertTrue(response.content.startswith(b'%PDF-'))
self.assertTrue(response.content.endswith(b'%%EOF\n'))
评论列表
文章目录