diff options
author | Max Peterson <max@incuna.com> | 2015-12-01 14:39:58 +0000 |
---|---|---|
committer | Max Peterson <max@incuna.com> | 2015-12-01 14:39:58 +0000 |
commit | 09dcea6fb45dc18d17b254c047694c452fee12ed (patch) | |
tree | 2193e6ab9ebdb5e1598473e1417c947e5e7b7877 /wkhtmltopdf/tests | |
parent | 2c74c40ebc055a60d30a1424c685b6fbc96f364a (diff) | |
parent | fbf54be1da1cc90490336a57df6678a2f833a5f7 (diff) | |
download | django-wkhtmltopdf-09dcea6fb45dc18d17b254c047694c452fee12ed.tar.gz django-wkhtmltopdf-09dcea6fb45dc18d17b254c047694c452fee12ed.tar.bz2 django-wkhtmltopdf-09dcea6fb45dc18d17b254c047694c452fee12ed.zip |
Merge pull request #95 from johnraz/extract-logic
Extract logic from views
Diffstat (limited to 'wkhtmltopdf/tests')
-rw-r--r-- | wkhtmltopdf/tests/tests.py | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/wkhtmltopdf/tests/tests.py b/wkhtmltopdf/tests/tests.py index 48a8b19..c15d88f 100644 --- a/wkhtmltopdf/tests/tests.py +++ b/wkhtmltopdf/tests/tests.py @@ -6,6 +6,7 @@ import os import sys from django.conf import settings +from django.template import loader, RequestContext from django.test import TestCase from django.test.client import RequestFactory from django.utils import six @@ -13,7 +14,7 @@ from django.utils.encoding import smart_str from wkhtmltopdf.subprocess import CalledProcessError from wkhtmltopdf.utils import (_options_to_args, make_absolute_paths, - wkhtmltopdf) + wkhtmltopdf, render_to_temporary_file) from wkhtmltopdf.views import PDFResponse, PDFTemplateView, PDFTemplateResponse @@ -50,10 +51,8 @@ class TestUtils(TestCase): def test_wkhtmltopdf(self): """Should run wkhtmltopdf to generate a PDF""" title = 'A test template.' - response = PDFTemplateResponse(self.factory.get('/'), - None, - context={'title': title}) - temp_file = response.render_to_temporary_file('sample.html') + template = loader.get_template('sample.html') + temp_file = render_to_temporary_file(template, context={'title': title}) try: # Standard call pdf_output = wkhtmltopdf(pages=[temp_file.name]) @@ -76,23 +75,20 @@ class TestUtils(TestCase): def test_wkhtmltopdf_with_unicode_content(self): """A wkhtmltopdf call should render unicode content properly""" title = u'♥' - response = PDFTemplateResponse(self.factory.get('/'), - None, - context={'title': title}) - temp_file = response.render_to_temporary_file('unicode.html') + template = loader.get_template('unicode.html') + temp_file = render_to_temporary_file(template, context={'title': title}) try: pdf_output = wkhtmltopdf(pages=[temp_file.name]) self.assertTrue(pdf_output.startswith(b'%PDF'), pdf_output) finally: temp_file.close() - def test_PDFTemplateResponse_render_to_temporary_file(self): + def test_render_to_temporary_file(self): """Should render a template to a temporary file.""" title = 'A test template.' - response = PDFTemplateResponse(self.factory.get('/'), - None, - context={'title': title}) - temp_file = response.render_to_temporary_file('sample.html') + + template = loader.get_template('sample.html') + temp_file = render_to_temporary_file(template, context={'title': title}) temp_file.seek(0) saved_content = smart_str(temp_file.read()) self.assertTrue(title in saved_content) @@ -179,7 +175,8 @@ class TestViews(TestCase): self.assertFalse(response.has_header('Content-Disposition')) # Render to temporary file - tempfile = response.render_to_temporary_file(self.template) + template = loader.get_template(self.template) + tempfile = render_to_temporary_file(template, context=context) tempfile.seek(0) html_content = smart_str(tempfile.read()) self.assertTrue(html_content.startswith('<html>')) @@ -205,7 +202,8 @@ class TestViews(TestCase): self.assertEqual(response.cmd_options, cmd_options) self.assertTrue(response.has_header('Content-Disposition')) - tempfile = response.render_to_temporary_file(self.footer_template) + footer_template = loader.get_template(self.footer_template) + tempfile = render_to_temporary_file(footer_template, context=RequestContext(request, context)) tempfile.seek(0) footer_content = smart_str(tempfile.read()) footer_content = make_absolute_paths(footer_content) |