aboutsummaryrefslogtreecommitdiffstats
path: root/wkhtmltopdf
diff options
context:
space:
mode:
authorJosh <josh@halfnibble.com>2016-03-03 19:21:21 -0800
committerJosh <josh@halfnibble.com>2016-03-03 19:21:21 -0800
commit87b4aad9e9a88fafbf77dffd9694d613e721add6 (patch)
treeb2c6b8cec8b733ede94365eeb52d86e8b2decf3b /wkhtmltopdf
parent39b61bff13f41b7c779d57e16eef717dfffbe6b9 (diff)
downloaddjango-wkhtmltopdf-87b4aad9e9a88fafbf77dffd9694d613e721add6.tar.gz
django-wkhtmltopdf-87b4aad9e9a88fafbf77dffd9694d613e721add6.tar.bz2
django-wkhtmltopdf-87b4aad9e9a88fafbf77dffd9694d613e721add6.zip
Test rendered file deletion or persistence for both debug options.
Diffstat (limited to 'wkhtmltopdf')
-rw-r--r--wkhtmltopdf/tests/tests.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/wkhtmltopdf/tests/tests.py b/wkhtmltopdf/tests/tests.py
index b3c9ea1..7b48421 100644
--- a/wkhtmltopdf/tests/tests.py
+++ b/wkhtmltopdf/tests/tests.py
@@ -97,14 +97,14 @@ class TestUtils(TestCase):
temp_file.close()
def _render_file(self, template, context):
- """Helper method for test_rendered_filed_deletion test."""
+ """Helper method for testing rendered file deleted/persists tests."""
render = RenderedFile(template=template, context=context)
render.temporary_file.seek(0)
saved_content = smart_str(render.temporary_file.read())
return (saved_content, render.filename)
- def test_rendered_filed_deletion(self):
+ def test_rendered_file_deleted_on_production(self):
"""If WKHTMLTOPDF_DEBUG=False, delete rendered file on object close."""
title = 'A test template.'
template = loader.get_template('sample.html')
@@ -112,11 +112,28 @@ class TestUtils(TestCase):
saved_content, filename = self._render_file(template=template,
context={'title': title})
- # First verify temp file was actually rendered.
+ # First verify temp file was rendered correctly.
self.assertTrue(title in saved_content)
- # Then check if file is deleted when DEBUG=False.
- self.assertEqual(os.path.isfile(filename), debug)
+ # Then check if file is deleted when debug=False.
+ self.assertFalse(debug)
+ self.assertFalse(os.path.isfile(filename))
+
+ def test_rendered_file_persists_on_debug(self):
+ """If WKHTMLTOPDF_DEBUG=True, the rendered file should persist."""
+ title = 'A test template.'
+ template = loader.get_template('sample.html')
+ with self.settings(WKHTMLTOPDF_DEBUG=True):
+ debug = getattr(settings, 'WKHTMLTOPDF_DEBUG', settings.DEBUG)
+
+ saved_content, filename = self._render_file(template=template,
+ context={'title': title})
+ # First verify temp file was rendered correctly.
+ self.assertTrue(title in saved_content)
+
+ # Then check if file persists when debug=True.
+ self.assertTrue(debug)
+ self.assertTrue(os.path.isfile(filename))
class TestViews(TestCase):