From a0da923c093f79e2205529c5f12fad620f3159a7 Mon Sep 17 00:00:00 2001 From: Simon Law Date: Tue, 24 Jul 2012 16:18:39 -0400 Subject: 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. --- wkhtmltopdf/tests.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'wkhtmltopdf/tests.py') 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)) -- cgit v1.2.3