aboutsummaryrefslogtreecommitdiffstats
path: root/wkhtmltopdf/tests.py
diff options
context:
space:
mode:
authorSimon Law <simon.law@ecometrica.com>2012-07-24 16:18:39 -0400
committerSimon Law <simon.law@ecometrica.com>2012-07-24 16:18:39 -0400
commita0da923c093f79e2205529c5f12fad620f3159a7 (patch)
tree58a4bba8a961b4bbedcc378eedab3e02d9185c6e /wkhtmltopdf/tests.py
parentbde096a028c2705b8f56fb5fdcbbaed4b318862d (diff)
downloaddjango-wkhtmltopdf-a0da923c093f79e2205529c5f12fad620f3159a7.tar.gz
django-wkhtmltopdf-a0da923c093f79e2205529c5f12fad620f3159a7.tar.bz2
django-wkhtmltopdf-a0da923c093f79e2205529c5f12fad620f3159a7.zip
PDFTemplateView.cmd_options contains all the options to pass to wkhtmltopdf
Before, command-line arguments were class-based. Unfortunately, this means that you cannot add new command-line arguments without subclassing. Instead, PDFTemplateView.cmd_options is a dictionary of all command-line arguments. PDFTemplateView.as_view(cmd_options={...}) now works as expected. !!!! WARNING !!!! cmd_options is now empty, leaving wkhtmltopdf with its default behaviour. Explicitly add the options you want. Existing subclasses of PDFTemplateView will now break, but a PendingDeprecationWarning will be issued. Margins will now be wkhtmltopdf's default of 10mm. PdfTemplateView contains a compatibility shim with the old default values for margins and orientation.
Diffstat (limited to 'wkhtmltopdf/tests.py')
-rw-r--r--wkhtmltopdf/tests.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/wkhtmltopdf/tests.py b/wkhtmltopdf/tests.py
index 19fde76..1802440 100644
--- a/wkhtmltopdf/tests.py
+++ b/wkhtmltopdf/tests.py
@@ -218,6 +218,24 @@ class TestViews(TestCase):
response = view(request)
self.assertEqual(response.status_code, 405)
+ def test_get_cmd_options(self):
+ # Default cmd_options
+ view = PDFTemplateView()
+ self.assertEqual(view.cmd_options, PDFTemplateView.cmd_options)
+ self.assertEqual(PDFTemplateView.cmd_options, {})
+
+ # Instantiate with new cmd_options
+ cmd_options = {'orientation': 'landscape'}
+ view = PDFTemplateView(cmd_options=cmd_options)
+ self.assertEqual(view.cmd_options, cmd_options)
+ self.assertEqual(PDFTemplateView.cmd_options, {})
+
+ # Update local instance of cmd_options
+ view = PDFTemplateView()
+ view.cmd_options.update(cmd_options)
+ self.assertEqual(view.cmd_options, cmd_options)
+ self.assertEqual(PDFTemplateView.cmd_options, {})
+
def test_deprecated(self):
"""Should warn when using deprecated views."""
with warnings.catch_warnings(record=True) as w:
@@ -236,3 +254,11 @@ class TestViews(TestCase):
self.assertTrue(
'PDFResponse' in str(w[0].message),
"'PDFResponse' not in {!r}".format(w[0].message))
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter('always')
+ PDFTemplateView().get_pdf_kwargs()
+ self.assertEqual(len(w), 1)
+ self.assertEqual(w[0].category, PendingDeprecationWarning)
+ self.assertTrue(
+ 'get_pdf_kwargs()' in str(w[0].message),
+ "'get_pdf_kwargs()' not in {!r}".format(w[0].message))