From e876828399e06654d8a1c336fbde65477b3c27c4 Mon Sep 17 00:00:00 2001 From: Marc Tamlyn Date: Fri, 31 Aug 2012 11:51:23 +0100 Subject: Add a test for unicode. This isn't great but better than nothing... --- wkhtmltopdf/tests/templates/unicode.html | 8 ++++++++ wkhtmltopdf/tests/tests.py | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 wkhtmltopdf/tests/templates/unicode.html (limited to 'wkhtmltopdf/tests') diff --git a/wkhtmltopdf/tests/templates/unicode.html b/wkhtmltopdf/tests/templates/unicode.html new file mode 100644 index 0000000..62968bb --- /dev/null +++ b/wkhtmltopdf/tests/templates/unicode.html @@ -0,0 +1,8 @@ + + + + + +

+ + diff --git a/wkhtmltopdf/tests/tests.py b/wkhtmltopdf/tests/tests.py index 6d8f3ac..16e89ba 100644 --- a/wkhtmltopdf/tests/tests.py +++ b/wkhtmltopdf/tests/tests.py @@ -253,6 +253,39 @@ class TestViews(TestCase): response = view(request) self.assertEqual(response.status_code, 405) + def test_pdf_template_view_unicode(self): + """Test PDFTemplateView.""" + with override_settings( + MEDIA_URL='/media/', + STATIC_URL='/static/', + TEMPLATE_CONTEXT_PROCESSORS=[ + 'django.core.context_processors.media', + 'django.core.context_processors.static', + ], + TEMPLATE_LOADERS=['django.template.loaders.filesystem.Loader'], + TEMPLATE_DIRS=[os.path.join(os.path.dirname(__file__), + '_testproject', 'templates')], + WKHTMLTOPDF_DEBUG=False, + ): + # Setup sample.html + template = 'unicode.html' + filename = 'output.pdf' + view = PDFTemplateView.as_view(filename=filename, + template_name=template) + + # As PDF + request = RequestFactory().get('/') + response = view(request) + self.assertEqual(response.status_code, 200) + response.render() + self.assertEqual(response['Content-Disposition'], + 'attachment; filename="{0}"'.format(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('%PDF-')) + self.assertTrue(response.content.endswith('%%EOF\n')) + def test_get_cmd_options(self): # Default cmd_options view = PDFTemplateView() -- cgit v1.2.3