aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Tamlyn <marc.tamlyn@gmail.com>2012-07-27 14:48:37 +0100
committerMarc Tamlyn <marc.tamlyn@gmail.com>2012-07-27 14:48:37 +0100
commitd236427edccbd2fcb5dac438845d7de48ed2398d (patch)
tree38f8a70b84af4ca9a877662442d9fb4cd26c0787
parent3a4201aeb1c8f7727a333f07eccd763624337e94 (diff)
downloaddjango-wkhtmltopdf-d236427edccbd2fcb5dac438845d7de48ed2398d.tar.gz
django-wkhtmltopdf-d236427edccbd2fcb5dac438845d7de48ed2398d.tar.bz2
django-wkhtmltopdf-d236427edccbd2fcb5dac438845d7de48ed2398d.zip
Update tests to remove deprecateded functions.
-rw-r--r--wkhtmltopdf/tests.py36
1 files changed, 16 insertions, 20 deletions
diff --git a/wkhtmltopdf/tests.py b/wkhtmltopdf/tests.py
index c55d6f9..cd0213d 100644
--- a/wkhtmltopdf/tests.py
+++ b/wkhtmltopdf/tests.py
@@ -9,10 +9,8 @@ from django.test import TestCase
from django.test.client import RequestFactory
from .subprocess import CalledProcessError
-from .utils import (override_settings,
- _options_to_args, template_to_temp_file, wkhtmltopdf)
-from .views import (PDFResponse, PdfResponse, PDFTemplateResponse,
- PDFTemplateView, PdfTemplateView)
+from .utils import override_settings, _options_to_args, wkhtmltopdf
+from .views import PDFResponse, PDFTemplateView, PDFTemplateResponse
class TestUtils(TestCase):
@@ -20,6 +18,7 @@ class TestUtils(TestCase):
# Clear standard error
self._stderr = sys.stderr
sys.stderr = open(os.devnull, 'w')
+ self.factory = RequestFactory()
def tearDown(self):
sys.stderr = self._stderr
@@ -35,39 +34,36 @@ class TestUtils(TestCase):
def test_wkhtmltopdf(self):
"""Should run wkhtmltopdf to generate a PDF"""
title = 'A test template.'
- temp_file = template_to_temp_file('sample.html', {'title': title})
- pdf_output = None
+ response = PDFTemplateResponse(self.factory.get('/'), None, context={'title': title})
+ temp_file = response.render_to_temporary_file('sample.html')
try:
# Standard call
- pdf_output = wkhtmltopdf(pages=[temp_file])
+ pdf_output = wkhtmltopdf(pages=[temp_file.name])
self.assertTrue(pdf_output.startswith('%PDF'), pdf_output)
# Single page
- pdf_output = wkhtmltopdf(pages=temp_file)
+ pdf_output = wkhtmltopdf(pages=temp_file.name)
self.assertTrue(pdf_output.startswith('%PDF'), pdf_output)
# Unicode
- pdf_output = wkhtmltopdf(pages=[temp_file], title=u'♥')
+ pdf_output = wkhtmltopdf(pages=[temp_file.name], title=u'♥')
self.assertTrue(pdf_output.startswith('%PDF'), pdf_output)
# Invalid arguments
self.assertRaises(CalledProcessError,
wkhtmltopdf, pages=[])
finally:
- if os.path.exists(temp_file):
- os.remove(temp_file)
+ temp_file.close()
- def test_template_to_temp_file(self):
+ def test_PDFTemplateResponse_render_to_temporary_file(self):
"""Should render a template to a temporary file."""
title = 'A test template.'
- temp_file = template_to_temp_file('sample.html', {'title': title})
- try:
- with open(temp_file, 'r') as f:
- saved_content = f.read()
- self.assertTrue(title in saved_content)
- finally:
- if os.path.exists(temp_file):
- os.remove(temp_file)
+ 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()
+ self.assertTrue(title in saved_content)
+ temp_file.close()
class TestViews(TestCase):