From 1e3dfedfc4778879917970bf125c51947c367f94 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 11:14:24 +0100 Subject: Add support for Python3 --- wkhtmltopdf/tests/tests.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'wkhtmltopdf/tests') diff --git a/wkhtmltopdf/tests/tests.py b/wkhtmltopdf/tests/tests.py index b007687..f2d92aa 100644 --- a/wkhtmltopdf/tests/tests.py +++ b/wkhtmltopdf/tests/tests.py @@ -8,6 +8,7 @@ import sys from django.conf import settings from django.test import TestCase from django.test.client import RequestFactory +from django.utils.encoding import smart_str from wkhtmltopdf.subprocess import CalledProcessError from wkhtmltopdf.utils import (_options_to_args, make_absolute_paths, @@ -41,15 +42,15 @@ class TestUtils(TestCase): try: # Standard call pdf_output = wkhtmltopdf(pages=[temp_file.name]) - self.assertTrue(pdf_output.startswith('%PDF'), pdf_output) + self.assertTrue(pdf_output.startswith(b'%PDF'), pdf_output) # Single page pdf_output = wkhtmltopdf(pages=temp_file.name) - self.assertTrue(pdf_output.startswith('%PDF'), pdf_output) + self.assertTrue(pdf_output.startswith(b'%PDF'), pdf_output) # Unicode pdf_output = wkhtmltopdf(pages=[temp_file.name], title=u'♥') - self.assertTrue(pdf_output.startswith('%PDF'), pdf_output) + self.assertTrue(pdf_output.startswith(b'%PDF'), pdf_output) # Invalid arguments self.assertRaises(CalledProcessError, @@ -63,7 +64,7 @@ class TestUtils(TestCase): response = PDFTemplateResponse(self.factory.get('/'), None, context={'title': title}) temp_file = response.render_to_temporary_file('sample.html') temp_file.seek(0) - saved_content = temp_file.read() + saved_content = smart_str(temp_file.read()) self.assertTrue(title in saved_content) temp_file.close() @@ -80,11 +81,11 @@ class TestViews(TestCase): # 404 response = PDFResponse(content='', status=404) self.assertEqual(response.status_code, 404) - self.assertEqual(response.content, '') + self.assertEqual(response.content, b'') self.assertEqual(response['Content-Type'], 'application/pdf') self.assertFalse(response.has_header('Content-Disposition')) - content = '%PDF-1.4\n%%EOF' + content = b'%PDF-1.4\n%%EOF' # Without filename response = PDFResponse(content=content) self.assertEqual(response.status_code, 200) @@ -153,14 +154,14 @@ class TestViews(TestCase): # Render to temporary file tempfile = response.render_to_temporary_file(self.template) tempfile.seek(0) - html_content = tempfile.read() + html_content = smart_str(tempfile.read()) self.assertTrue(html_content.startswith('')) self.assertTrue('

{title}

'.format(**context) in html_content) pdf_content = response.rendered_content - self.assertTrue(pdf_content.startswith('%PDF-')) - self.assertTrue(pdf_content.endswith('%%EOF\n')) + self.assertTrue(pdf_content.startswith(b'%PDF-')) + self.assertTrue(pdf_content.endswith(b'%%EOF\n')) # Footer cmd_options = {'title': 'Test PDF'} @@ -179,7 +180,7 @@ class TestViews(TestCase): tempfile = response.render_to_temporary_file(self.footer_template) tempfile.seek(0) - footer_content = tempfile.read() + footer_content = smart_str(tempfile.read()) footer_content = make_absolute_paths(footer_content) media_url = 'file://{0}/'.format(settings.MEDIA_ROOT) @@ -189,8 +190,8 @@ class TestViews(TestCase): self.assertTrue(static_url in footer_content, True) pdf_content = response.rendered_content - self.assertTrue('\0'.join('{title}'.format(**cmd_options)) - in pdf_content) + self.assertTrue(pdf_content.startswith(b'%PDF-')) + self.assertTrue(pdf_content.endswith(b'%%EOF\n')) def test_pdf_template_response_to_browser(self): self.test_pdf_template_response(show_content=True) @@ -214,8 +215,8 @@ class TestViews(TestCase): fileheader = self.inline_fileheader self.assertEqual(response['Content-Disposition'], fileheader.format(self.pdf_filename)) - self.assertTrue(response.content.startswith('%PDF-')) - self.assertTrue(response.content.endswith('%%EOF\n')) + self.assertTrue(response.content.startswith(b'%PDF-')) + self.assertTrue(response.content.endswith(b'%%EOF\n')) # As HTML request = RequestFactory().get('/?as=html') @@ -223,7 +224,7 @@ class TestViews(TestCase): self.assertEqual(response.status_code, 200) response.render() self.assertFalse(response.has_header('Content-Disposition')) - self.assertTrue(response.content.startswith('')) + self.assertTrue(response.content.startswith(b'')) # POST request = RequestFactory().post('/') @@ -254,8 +255,8 @@ class TestViews(TestCase): # 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')) + self.assertTrue(response.content.startswith(b'%PDF-')) + self.assertTrue(response.content.endswith(b'%%EOF\n')) def test_pdf_template_view_unicode_to_browser(self): self.test_pdf_template_view_unicode(show_content=True) -- cgit v1.2.3 From cc6e1753a4d388e294e14c4c0805052ccd1be381 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 11:23:57 +0100 Subject: Update test reqs for Django with py3k support In near future we should support moar Djangos (and using Travis for this). --- wkhtmltopdf/tests/test_requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wkhtmltopdf/tests') diff --git a/wkhtmltopdf/tests/test_requirements.txt b/wkhtmltopdf/tests/test_requirements.txt index 3999bef..7eedf6c 100644 --- a/wkhtmltopdf/tests/test_requirements.txt +++ b/wkhtmltopdf/tests/test_requirements.txt @@ -1 +1 @@ -Django==1.4.2 +Django==1.4.13 -- cgit v1.2.3 From 61f7af8399c1ab51a0b2dff06414170947eaa228 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 11:43:43 +0100 Subject: Support moar Django The future is now ;] --- wkhtmltopdf/tests/test_requirements.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 wkhtmltopdf/tests/test_requirements.txt (limited to 'wkhtmltopdf/tests') diff --git a/wkhtmltopdf/tests/test_requirements.txt b/wkhtmltopdf/tests/test_requirements.txt deleted file mode 100644 index 7eedf6c..0000000 --- a/wkhtmltopdf/tests/test_requirements.txt +++ /dev/null @@ -1 +0,0 @@ -Django==1.4.13 -- cgit v1.2.3 From 3898e56c1f8a4cceea21e2628fdb7d93f97ca615 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 12:27:54 +0100 Subject: Make teh tests run right Because Django 1.6 and other fireworks. --- wkhtmltopdf/tests/run.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 wkhtmltopdf/tests/run.py (limited to 'wkhtmltopdf/tests') diff --git a/wkhtmltopdf/tests/run.py b/wkhtmltopdf/tests/run.py new file mode 100644 index 0000000..239f5dc --- /dev/null +++ b/wkhtmltopdf/tests/run.py @@ -0,0 +1,43 @@ +#! /usr/bin/env python +import os +import sys + +from colour_runner.django_runner import ColourRunnerMixin +from django.conf import settings + +DIRNAME = os.path.abspath(os.path.dirname(__file__)) + + +settings.configure( + DEBUG=True, + DATABASES={ + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:', + } + }, + INSTALLED_APPS=( + 'wkhtmltopdf.tests', + 'wkhtmltopdf', + ), + MEDIA_ROOT=os.path.join(DIRNAME, 'media'), + MEDIA_URL='/media/', + STATIC_ROOT=os.path.join(DIRNAME, 'static'), + STATIC_URL='/static/', + WKHTMLTOPDF_DEBUG=True, +) + +try: + from django.test.runner import DiscoverRunner +except ImportError: + from discover_runner.runner import DiscoverRunner + + +class TestRunner(ColourRunnerMixin, DiscoverRunner): + pass + + +test_runner = TestRunner(verbosity=1) +failures = test_runner.run_tests(['wkhtmltopdf']) +if failures: + sys.exit(1) -- cgit v1.2.3 From 8ff65e95d59ea46d05b8b44d2551f1085a4834f7 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 12:33:06 +0100 Subject: colour-runner dependency doesn't work on py2.6 DAMN IT --- wkhtmltopdf/tests/run.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'wkhtmltopdf/tests') diff --git a/wkhtmltopdf/tests/run.py b/wkhtmltopdf/tests/run.py index 239f5dc..a840e68 100644 --- a/wkhtmltopdf/tests/run.py +++ b/wkhtmltopdf/tests/run.py @@ -2,7 +2,6 @@ import os import sys -from colour_runner.django_runner import ColourRunnerMixin from django.conf import settings DIRNAME = os.path.abspath(os.path.dirname(__file__)) @@ -33,11 +32,7 @@ except ImportError: from discover_runner.runner import DiscoverRunner -class TestRunner(ColourRunnerMixin, DiscoverRunner): - pass - - -test_runner = TestRunner(verbosity=1) +test_runner = DiscoverRunner(verbosity=1) failures = test_runner.run_tests(['wkhtmltopdf']) if failures: sys.exit(1) -- cgit v1.2.3 From 301bef0d6931582583a156b3195b8b13f54d2875 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Thu, 19 Jun 2014 11:26:05 +0100 Subject: Bring back the test assert for title in content --- wkhtmltopdf/tests/tests.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'wkhtmltopdf/tests') diff --git a/wkhtmltopdf/tests/tests.py b/wkhtmltopdf/tests/tests.py index f2d92aa..7365d05 100644 --- a/wkhtmltopdf/tests/tests.py +++ b/wkhtmltopdf/tests/tests.py @@ -8,6 +8,7 @@ import sys from django.conf import settings from django.test import TestCase from django.test.client import RequestFactory +from django.utils import six from django.utils.encoding import smart_str from wkhtmltopdf.subprocess import CalledProcessError @@ -190,8 +191,8 @@ class TestViews(TestCase): self.assertTrue(static_url in footer_content, True) pdf_content = response.rendered_content - self.assertTrue(pdf_content.startswith(b'%PDF-')) - self.assertTrue(pdf_content.endswith(b'%%EOF\n')) + title = '\0'.join(cmd_options['title']) + self.assertIn(six.b(title), pdf_content) def test_pdf_template_response_to_browser(self): self.test_pdf_template_response(show_content=True) -- cgit v1.2.3