aboutsummaryrefslogtreecommitdiffstats
path: root/wkhtmltopdf
diff options
context:
space:
mode:
authorJosh <josh@halfnibble.com>2016-03-02 04:54:50 -0800
committerJosh <josh@halfnibble.com>2016-03-02 04:54:50 -0800
commit39b61bff13f41b7c779d57e16eef717dfffbe6b9 (patch)
tree0fcce870d8faf246e2624c75fd7db091ea5a7206 /wkhtmltopdf
parentca8b99207a8a135ea1b970bd610ac8fa8fe2741a (diff)
downloaddjango-wkhtmltopdf-39b61bff13f41b7c779d57e16eef717dfffbe6b9.tar.gz
django-wkhtmltopdf-39b61bff13f41b7c779d57e16eef717dfffbe6b9.tar.bz2
django-wkhtmltopdf-39b61bff13f41b7c779d57e16eef717dfffbe6b9.zip
Add test for temporary file is closed/deleted.
Diffstat (limited to 'wkhtmltopdf')
-rw-r--r--wkhtmltopdf/tests/tests.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/wkhtmltopdf/tests/tests.py b/wkhtmltopdf/tests/tests.py
index 822f529..b3c9ea1 100644
--- a/wkhtmltopdf/tests/tests.py
+++ b/wkhtmltopdf/tests/tests.py
@@ -14,7 +14,8 @@ from django.utils.encoding import smart_str
from wkhtmltopdf.subprocess import CalledProcessError
from wkhtmltopdf.utils import (_options_to_args, make_absolute_paths,
- wkhtmltopdf, render_to_temporary_file)
+ wkhtmltopdf, render_to_temporary_file,
+ RenderedFile)
from wkhtmltopdf.views import PDFResponse, PDFTemplateView, PDFTemplateResponse
@@ -30,6 +31,7 @@ class UnicodeContentPDFTemplateView(PDFTemplateView):
context['title'] = u'♥'
return context
+
class TestUtils(TestCase):
def setUp(self):
# Clear standard error
@@ -94,6 +96,28 @@ class TestUtils(TestCase):
self.assertTrue(title in saved_content)
temp_file.close()
+ def _render_file(self, template, context):
+ """Helper method for test_rendered_filed_deletion test."""
+ 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):
+ """If WKHTMLTOPDF_DEBUG=False, delete rendered file on object close."""
+ title = 'A test template.'
+ template = loader.get_template('sample.html')
+ debug = getattr(settings, 'WKHTMLTOPDF_DEBUG', settings.DEBUG)
+
+ saved_content, filename = self._render_file(template=template,
+ context={'title': title})
+ # First verify temp file was actually rendered.
+ self.assertTrue(title in saved_content)
+
+ # Then check if file is deleted when DEBUG=False.
+ self.assertEqual(os.path.isfile(filename), debug)
+
class TestViews(TestCase):
template = 'sample.html'