From 86a89c716d5623715fe1e7dccaa139d4f12f584a Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 16 Jul 2014 11:15:09 +0100 Subject: Show Travis test status against master branch only --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 6585a38..a8b3edb 100644 --- a/README.rst +++ b/README.rst @@ -5,7 +5,7 @@ django-wkhtmltopdf :target: http://badge.fury.io/py/django-wkhtmltopdf :alt: Latest version -.. image:: https://travis-ci.org/incuna/django-wkhtmltopdf.png +.. image:: https://travis-ci.org/incuna/django-wkhtmltopdf.png?branch=master :target: https://travis-ci.org/incuna/django-wkhtmltopdf :alt: Travis-CI -- cgit v1.2.3 From 23f08bc0d0b8ea0cd213f09c618f8cd9baabb1ed Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 16 Jul 2014 11:26:52 +0100 Subject: Fix wkhtmltox for Travis --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3f3dacc..71a5ddb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,11 +19,11 @@ before_install: - "echo '## Installing dependencies'" - "sudo apt-get update" - "sudo apt-get install -y openssl build-essential xorg libssl-dev" - - "echo '## Downloading wkhtmltopdf 0.12.0'" - - "wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.0/wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz" + - "echo '## Downloading wkhtmltopdf 0.12.1'" + - "wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.1/wkhtmltox-0.12.1.tar.bz2" - "mkdir -p $PWD" - "echo '## Extracting wkhtmltox into $PWD'" - - "tar xvJf wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz -C $PWD" + - "tar xvjf wkhtmltox-0.12.1.tar.bz2 -C $PWD" - "export WKHTMLTOPDF_CMD=$PWD/wkhtmltox/bin/wkhtmltopdf" install: - pip install $DJANGO -- cgit v1.2.3 From f51eaeed13842d90cc8f0422a597b0ac6a6f8418 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 16 Jul 2014 12:05:54 +0100 Subject: Use precompiled library not source one --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 71a5ddb..9988bd4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,15 +16,15 @@ matrix: env: DJANGO="Django>=1.4,<1.5" before_install: - PWD=`pwd` + - WHICH_WK=`which wkhtmltopdf` - "echo '## Installing dependencies'" - "sudo apt-get update" - "sudo apt-get install -y openssl build-essential xorg libssl-dev" - "echo '## Downloading wkhtmltopdf 0.12.1'" - - "wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.1/wkhtmltox-0.12.1.tar.bz2" - - "mkdir -p $PWD" - - "echo '## Extracting wkhtmltox into $PWD'" - - "tar xvjf wkhtmltox-0.12.1.tar.bz2 -C $PWD" - - "export WKHTMLTOPDF_CMD=$PWD/wkhtmltox/bin/wkhtmltopdf" + - "wget http://freefr.dl.sourceforge.net/project/wkhtmltopdf/0.12.1/wkhtmltox-0.12.1_linux-precise-amd64.deb" + - "echo '## Installing wkhtmltox'" + - "dpkg -i wkhtmltox-0.12.1_linux-precise-amd64.deb" + - "export WKHTMLTOPDF_CMD=$WHICH_WK" install: - pip install $DJANGO - pip install -r test_requirements.txt -- cgit v1.2.3 From 9913d8e6b9b410930f5108b685fb89a602664fc9 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 16 Jul 2014 12:12:56 +0100 Subject: Check for wkhtmltopdf after it was installed :D --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9988bd4..64075e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,6 @@ matrix: env: DJANGO="Django>=1.4,<1.5" before_install: - PWD=`pwd` - - WHICH_WK=`which wkhtmltopdf` - "echo '## Installing dependencies'" - "sudo apt-get update" - "sudo apt-get install -y openssl build-essential xorg libssl-dev" @@ -24,6 +23,7 @@ before_install: - "wget http://freefr.dl.sourceforge.net/project/wkhtmltopdf/0.12.1/wkhtmltox-0.12.1_linux-precise-amd64.deb" - "echo '## Installing wkhtmltox'" - "dpkg -i wkhtmltox-0.12.1_linux-precise-amd64.deb" + - WHICH_WK=`which wkhtmltopdf` - "export WKHTMLTOPDF_CMD=$WHICH_WK" install: - pip install $DJANGO -- cgit v1.2.3 From f9ce54704305bae5896f80130034ebaf2f363a7c Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 16 Jul 2014 12:23:08 +0100 Subject: Superuser privilege - Travis is picky! --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 64075e4..698a5ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ before_install: - "echo '## Downloading wkhtmltopdf 0.12.1'" - "wget http://freefr.dl.sourceforge.net/project/wkhtmltopdf/0.12.1/wkhtmltox-0.12.1_linux-precise-amd64.deb" - "echo '## Installing wkhtmltox'" - - "dpkg -i wkhtmltox-0.12.1_linux-precise-amd64.deb" + - "sudo dpkg -i wkhtmltox-0.12.1_linux-precise-amd64.deb" - WHICH_WK=`which wkhtmltopdf` - "export WKHTMLTOPDF_CMD=$WHICH_WK" install: -- cgit v1.2.3 From 3e5f6553c8e51e8304004419e48fd169f84ca91e Mon Sep 17 00:00:00 2001 From: Michel Sabchuk Date: Mon, 1 Sep 2014 10:25:11 -0300 Subject: Add failing test of unicode content. --- wkhtmltopdf/tests/tests.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wkhtmltopdf/tests/tests.py b/wkhtmltopdf/tests/tests.py index f296c8e..0c332f6 100644 --- a/wkhtmltopdf/tests/tests.py +++ b/wkhtmltopdf/tests/tests.py @@ -59,6 +59,17 @@ class TestUtils(TestCase): finally: temp_file.close() + def test_wkhtmltopdf_with_unicode_content(self): + """A wkhtmltopdf call should render unicode content properly""" + title = u'♥' + response = PDFTemplateResponse(self.factory.get('/'), None, context={'title': title}) + temp_file = response.render_to_temporary_file('unicode.html') + try: + pdf_output = wkhtmltopdf(pages=[temp_file.name]) + self.assertTrue(pdf_output.startswith(b'%PDF'), pdf_output) + finally: + temp_file.close() + def test_PDFTemplateResponse_render_to_temporary_file(self): """Should render a template to a temporary file.""" title = 'A test template.' -- cgit v1.2.3 From b6d9a18528e79673412714fb7c6d3e9826e89421 Mon Sep 17 00:00:00 2001 From: Michel Sabchuk Date: Mon, 1 Sep 2014 10:49:42 -0300 Subject: Makes unicode content views testing fails too. The view didn't define any title in context and the templates itself doen't have unicode content. I forced it making a view with a unicode title in context. --- wkhtmltopdf/tests/tests.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/wkhtmltopdf/tests/tests.py b/wkhtmltopdf/tests/tests.py index 0c332f6..e3aa869 100644 --- a/wkhtmltopdf/tests/tests.py +++ b/wkhtmltopdf/tests/tests.py @@ -17,6 +17,18 @@ from wkhtmltopdf.utils import (_options_to_args, make_absolute_paths, from wkhtmltopdf.views import PDFResponse, PDFTemplateView, PDFTemplateResponse +class UnicodeContentPDFTemplateView(PDFTemplateView): + """ + PDFTemplateView with the addition of unicode content in his context. + + Used in unicode content view testing. + """ + def get_context_data(self, **kwargs): + Base = super(UnicodeContentPDFTemplateView, self) + context = Base.get_context_data(**kwargs) + context['title'] = u'♥' + return context + class TestUtils(TestCase): def setUp(self): # Clear standard error @@ -244,11 +256,12 @@ class TestViews(TestCase): self.test_pdf_template_view(show_content=True) def test_pdf_template_view_unicode(self, show_content=False): - """Test PDFTemplateView.""" - - view = PDFTemplateView.as_view(filename=self.pdf_filename, - show_content_in_browser=show_content, - template_name=self.template) + """Test PDFTemplateView with unicode content.""" + view = UnicodeContentPDFTemplateView.as_view( + filename=self.pdf_filename, + show_content_in_browser=show_content, + template_name=self.template + ) # As PDF request = RequestFactory().get('/') -- cgit v1.2.3 From 8e1715bdbcc504a9ea815e401c064a6759077a2d Mon Sep 17 00:00:00 2001 From: Michel Sabchuk Date: Mon, 1 Sep 2014 10:51:14 -0300 Subject: Replace smart_str with smart_text/unicode for py2.x compat. --- wkhtmltopdf/views.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wkhtmltopdf/views.py b/wkhtmltopdf/views.py index 2d91224..882f4fa 100644 --- a/wkhtmltopdf/views.py +++ b/wkhtmltopdf/views.py @@ -5,8 +5,11 @@ from tempfile import NamedTemporaryFile from django.conf import settings from django.http import HttpResponse from django.template.response import TemplateResponse -from django.utils.encoding import smart_str from django.views.generic import TemplateView +try: + from django.utils.encoding import smart_text +except ImportError: + from django.utils.encoding import smart_unicode as smart_text from .utils import (content_disposition_filename, make_absolute_paths, wkhtmltopdf) @@ -72,7 +75,7 @@ class PDFTemplateResponse(TemplateResponse, PDFResponse): context = self.resolve_context(self.context_data) - content = smart_str(template.render(context)) + content = smart_text(template.render(context)) content = make_absolute_paths(content) try: -- cgit v1.2.3 From 04530dcce4489c720cf02cdfb906df0cfe6f0fed Mon Sep 17 00:00:00 2001 From: Michel Sabchuk Date: Mon, 1 Sep 2014 11:19:20 -0300 Subject: Makes tests.py lines 80 columns max. --- wkhtmltopdf/tests/tests.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/wkhtmltopdf/tests/tests.py b/wkhtmltopdf/tests/tests.py index e3aa869..48a8b19 100644 --- a/wkhtmltopdf/tests/tests.py +++ b/wkhtmltopdf/tests/tests.py @@ -50,7 +50,9 @@ class TestUtils(TestCase): def test_wkhtmltopdf(self): """Should run wkhtmltopdf to generate a PDF""" title = 'A test template.' - response = PDFTemplateResponse(self.factory.get('/'), None, context={'title': title}) + response = PDFTemplateResponse(self.factory.get('/'), + None, + context={'title': title}) temp_file = response.render_to_temporary_file('sample.html') try: # Standard call @@ -74,7 +76,9 @@ class TestUtils(TestCase): def test_wkhtmltopdf_with_unicode_content(self): """A wkhtmltopdf call should render unicode content properly""" title = u'♥' - response = PDFTemplateResponse(self.factory.get('/'), None, context={'title': title}) + response = PDFTemplateResponse(self.factory.get('/'), + None, + context={'title': title}) temp_file = response.render_to_temporary_file('unicode.html') try: pdf_output = wkhtmltopdf(pages=[temp_file.name]) @@ -85,7 +89,9 @@ class TestUtils(TestCase): def test_PDFTemplateResponse_render_to_temporary_file(self): """Should render a template to a temporary file.""" title = 'A test template.' - response = PDFTemplateResponse(self.factory.get('/'), None, context={'title': title}) + response = PDFTemplateResponse(self.factory.get('/'), + None, + context={'title': title}) temp_file = response.render_to_temporary_file('sample.html') temp_file.seek(0) saved_content = smart_str(temp_file.read()) @@ -101,7 +107,7 @@ class TestViews(TestCase): inline_fileheader = 'inline; filename="{0}"' def test_pdf_response(self): - """Should generate the correct HttpResponse object and content type.""" + """Should generate correct HttpResponse object and content type.""" # 404 response = PDFResponse(content='', status=404) self.assertEqual(response.status_code, 404) -- cgit v1.2.3 From ec709959f0a2827589bc8ff532136a8e09f40acd Mon Sep 17 00:00:00 2001 From: Michel Sabchuk Date: Mon, 1 Sep 2014 12:02:37 -0300 Subject: Being more explicit about the reason for smart_unicode. --- wkhtmltopdf/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/wkhtmltopdf/views.py b/wkhtmltopdf/views.py index 882f4fa..949ae38 100644 --- a/wkhtmltopdf/views.py +++ b/wkhtmltopdf/views.py @@ -9,6 +9,7 @@ from django.views.generic import TemplateView try: from django.utils.encoding import smart_text except ImportError: + # Django 1.4 doesn't have smart_text, we must smart_unicode in place from django.utils.encoding import smart_unicode as smart_text from .utils import (content_disposition_filename, make_absolute_paths, -- cgit v1.2.3 From 08b50680c71b903634f7137a596ac5c0fe21562f Mon Sep 17 00:00:00 2001 From: Michel Sabchuk Date: Mon, 1 Sep 2014 12:10:55 -0300 Subject: Rely only smart_text once django 1.4 also supports it. As well pointed by @mattack108, django 1.4 also haves smart_text. We don't have to do that import. --- wkhtmltopdf/views.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/wkhtmltopdf/views.py b/wkhtmltopdf/views.py index 949ae38..d5f189a 100644 --- a/wkhtmltopdf/views.py +++ b/wkhtmltopdf/views.py @@ -6,11 +6,7 @@ from django.conf import settings from django.http import HttpResponse from django.template.response import TemplateResponse from django.views.generic import TemplateView -try: - from django.utils.encoding import smart_text -except ImportError: - # Django 1.4 doesn't have smart_text, we must smart_unicode in place - from django.utils.encoding import smart_unicode as smart_text +from django.utils.encoding import smart_text from .utils import (content_disposition_filename, make_absolute_paths, wkhtmltopdf) -- cgit v1.2.3