aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Tamlyn <marc.tamlyn@gmail.com>2012-08-31 11:51:23 +0100
committerMarc Tamlyn <marc.tamlyn@gmail.com>2012-08-31 11:51:23 +0100
commite876828399e06654d8a1c336fbde65477b3c27c4 (patch)
tree7c34158205eb9f2f209987a59a450719ece161bf
parentef5678ce4ff518b7e3dfbda87563b7ffac6d7816 (diff)
downloaddjango-wkhtmltopdf-e876828399e06654d8a1c336fbde65477b3c27c4.tar.gz
django-wkhtmltopdf-e876828399e06654d8a1c336fbde65477b3c27c4.tar.bz2
django-wkhtmltopdf-e876828399e06654d8a1c336fbde65477b3c27c4.zip
Add a test for unicode.
This isn't great but better than nothing...
-rw-r--r--wkhtmltopdf/tests/templates/unicode.html8
-rw-r--r--wkhtmltopdf/tests/tests.py33
2 files changed, 41 insertions, 0 deletions
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 @@
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ </head>
+ <body>
+ <h1>☃</h1>
+ </body>
+</html>
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()