aboutsummaryrefslogtreecommitdiffstats
path: root/wkhtmltopdf/tests/tests.py
diff options
context:
space:
mode:
authorPadraic Harley <padraic.harley@ecometrica.com>2015-12-18 19:33:32 +0000
committerPadraic Harley <padraic.harley@ecometrica.com>2015-12-18 19:33:40 +0000
commitc51068cd1864d995e81ee5fd248b8a2027e56c35 (patch)
tree2513bea67f69056e74385f55f8f3e10d9dcbaabf /wkhtmltopdf/tests/tests.py
parent87be0aaafb59fca5540a300c8e6262fbe023fce5 (diff)
downloaddjango-wkhtmltopdf-c51068cd1864d995e81ee5fd248b8a2027e56c35.tar.gz
django-wkhtmltopdf-c51068cd1864d995e81ee5fd248b8a2027e56c35.tar.bz2
django-wkhtmltopdf-c51068cd1864d995e81ee5fd248b8a2027e56c35.zip
Fix unidecode bytes error on python2
`bytes` takes no additional args in python2 unlike it's taking an encoding in python3. Unidecode returns a unicode string in python3 and a bytestring in python2 which, I believe, was the main cause of error #71. Now, regardless of whether unidecode is included, all strings passing through http_quote will be encoded to ascii which should fix both issues. Also included is a fix for a failing test when unidecode is used. Unidecode's `_unidecode` function ignores characters greater than 0xefff, which '\xe2\x99\xa5' (the heart symbol) is. This caused users with unidecode to fail '.pdf' was produced rather than the expected '?.pdf'.
Diffstat (limited to 'wkhtmltopdf/tests/tests.py')
-rw-r--r--wkhtmltopdf/tests/tests.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/wkhtmltopdf/tests/tests.py b/wkhtmltopdf/tests/tests.py
index c15d88f..fc1545d 100644
--- a/wkhtmltopdf/tests/tests.py
+++ b/wkhtmltopdf/tests/tests.py
@@ -130,8 +130,14 @@ class TestViews(TestCase):
self.assertEqual(response['Content-Disposition'],
'attachment; filename="4\'5.pdf"')
response = PDFResponse(content=content, filename=u"♥.pdf")
- self.assertEqual(response['Content-Disposition'],
- 'attachment; filename="?.pdf"')
+ try:
+ import unidecode
+ except ImportError:
+ self.assertEqual(response['Content-Disposition'],
+ 'attachment; filename="?.pdf"')
+ else:
+ self.assertEqual(response['Content-Disposition'],
+ 'attachment; filename=".pdf"')
# Content as a direct output
response = PDFResponse(content=content, filename="nospace.pdf",
@@ -148,8 +154,14 @@ class TestViews(TestCase):
'inline; filename="4\'5.pdf"')
response = PDFResponse(content=content, filename=u"♥.pdf",
show_content_in_browser=True)
- self.assertEqual(response['Content-Disposition'],
- 'inline; filename="?.pdf"')
+ try:
+ import unidecode
+ except ImportError:
+ self.assertEqual(response['Content-Disposition'],
+ 'inline; filename="?.pdf"')
+ else:
+ self.assertEqual(response['Content-Disposition'],
+ 'inline; filename=".pdf"')
# Content-Type
response = PDFResponse(content=content,