From 8149d53678edb29a7bfca08d5ab97cc023f8ce65 Mon Sep 17 00:00:00 2001 From: Quique Porta Date: Wed, 13 Jun 2018 18:30:10 +0200 Subject: [PATCH 1/2] Fix for Django 1.11 --- .gitignore | 2 ++ mailviews/messages.py | 3 +-- mailviews/tests/emails/views.py | 6 +++--- mailviews/tests/templates/content.html | 1 + mailviews/tests/tests.py | 22 +++++++++++----------- mailviews/utils.py | 2 +- 6 files changed, 19 insertions(+), 17 deletions(-) create mode 100644 mailviews/tests/templates/content.html diff --git a/.gitignore b/.gitignore index ac88a07..8946220 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ dist/ docs/_build/ htmlcov/ node_modules/ +.idea/ +.vscode/ diff --git a/mailviews/messages.py b/mailviews/messages.py index c327629..d5bcf38 100644 --- a/mailviews/messages.py +++ b/mailviews/messages.py @@ -1,6 +1,5 @@ from django.core.exceptions import ImproperlyConfigured from django.core.mail.message import EmailMessage, EmailMultiAlternatives -from django.template import Context from django.template.loader import get_template, select_template from mailviews.utils import unescape @@ -34,7 +33,7 @@ def get_context_data(self, **kwargs): :rtype: :class:`django.template.Context` """ - return Context(kwargs) + return kwargs def render_to_message(self, extra_context=None, **kwargs): """ diff --git a/mailviews/tests/emails/views.py b/mailviews/tests/emails/views.py index b087f8f..45f5588 100644 --- a/mailviews/tests/emails/views.py +++ b/mailviews/tests/emails/views.py @@ -5,8 +5,8 @@ class TemplateContextMixin(object): - subject_template = Template('{{ subject }}') - body_template = Template('{{ content }}') + subject_template_name = 'subject.txt' + body_template_name = 'body.txt' def __init__(self, subject, content): self.subject = subject @@ -26,4 +26,4 @@ class BasicEmailMessageView(TemplateContextMixin, TemplatedEmailMessageView): class BasicHTMLEmailMessageView(TemplateContextMixin, TemplatedHTMLEmailMessageView): - html_body_template = Template('{{ content|linebreaks }}') + html_body_template_name = 'content.html' diff --git a/mailviews/tests/templates/content.html b/mailviews/tests/templates/content.html new file mode 100644 index 0000000..0b5f6b6 --- /dev/null +++ b/mailviews/tests/templates/content.html @@ -0,0 +1 @@ +{{ content|linebreaks }} diff --git a/mailviews/tests/tests.py b/mailviews/tests/tests.py index 1b82df4..6b04902 100644 --- a/mailviews/tests/tests.py +++ b/mailviews/tests/tests.py @@ -6,7 +6,7 @@ from django.core.urlresolvers import reverse from django.test import TestCase from django.test.client import Client -from django.template import Context, Template, TemplateDoesNotExist +from django.template import TemplateDoesNotExist from django.template.loader import get_template from mailviews.messages import (TemplatedEmailMessageView, @@ -67,17 +67,17 @@ def setUp(self): self.template = 'Hello, world!' self.subject = 'subject' - self.subject_template = Template('{{ subject }}') + self.subject_template = get_template('subject.txt') self.body = 'body' - self.body_template = Template('{{ body }}') + self.body_template = get_template('body.txt') self.context_dict = { 'subject': self.subject, 'body': self.body, } - self.context = Context(self.context_dict) + self.context = self.context_dict self.render_subject = functools.partial(self.message.render_subject, context=self.context) @@ -131,13 +131,13 @@ def test_body_template_name(self): def test_body_template(self): self.message.body_template = self.body_template - self.assertEqual(self.render_body(), self.body) + self.assertEqual(self.render_body(), "body\n") def test_render_to_message(self): self.add_templates_to_message() message = self.message.render_to_message(self.context_dict) self.assertEqual(message.subject, self.subject) - self.assertEqual(message.body, self.body) + self.assertEqual(message.body, "body\n") def test_send(self): self.add_templates_to_message() @@ -167,7 +167,7 @@ def setUp(self): super(TemplatedHTMLEmailMessageViewTestCase, self).setUp() self.html_body = 'html body' - self.html_body_template = Template('{{ html }}') + self.html_body_template = get_template('body.html') self.context_dict['html'] = self.html_body self.context['html'] = self.html_body @@ -203,14 +203,14 @@ def test_html_body_template_name(self): def test_html_body_template(self): self.message.html_body_template = self.html_body_template - self.assertEqual(self.render_html_body(), self.html_body) + self.assertEqual(self.render_html_body(), "html body\n") def test_render_to_message(self): self.add_templates_to_message() message = self.message.render_to_message(self.context_dict) self.assertEqual(message.subject, self.subject) - self.assertEqual(message.body, self.body) - self.assertEqual(message.alternatives, [(self.html_body, 'text/html')]) + self.assertEqual(message.body, "body\n") + self.assertEqual(message.alternatives, [("html body\n", 'text/html')]) def test_send(self): self.add_templates_to_message() @@ -267,4 +267,4 @@ def test_customizable_preview(self): self.assertEqual(response.status_code, 200) self.assertContains(response, ' Date: Thu, 14 Jun 2018 09:08:18 +0200 Subject: [PATCH 2/2] Add circle ci file --- .circleci/config.yml | 14 ++++++++++++++ mailviews/tests/tests.py | 14 ++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..5005602 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,14 @@ +version: 2 +jobs: + build: + docker: + - image: circleci/python:2.7-jessie + + steps: + - checkout + - run: + name: install dependencies + command: pip install --user Django==1.11.13 + - run: + name: run tests + command: python -m mailviews.tests diff --git a/mailviews/tests/tests.py b/mailviews/tests/tests.py index 6b04902..6650d74 100644 --- a/mailviews/tests/tests.py +++ b/mailviews/tests/tests.py @@ -70,6 +70,7 @@ def setUp(self): self.subject_template = get_template('subject.txt') self.body = 'body' + self.expected_body = 'body\n' self.body_template = get_template('body.txt') self.context_dict = { @@ -127,17 +128,17 @@ def test_body_template_name(self): self.assertTemplateExists(template) self.message.body_template_name = template - self.assertEqual(self.render_body(), self.body + '\n') + self.assertEqual(self.render_body(), self.expected_body) def test_body_template(self): self.message.body_template = self.body_template - self.assertEqual(self.render_body(), "body\n") + self.assertEqual(self.render_body(), self.expected_body) def test_render_to_message(self): self.add_templates_to_message() message = self.message.render_to_message(self.context_dict) self.assertEqual(message.subject, self.subject) - self.assertEqual(message.body, "body\n") + self.assertEqual(message.body, self.expected_body) def test_send(self): self.add_templates_to_message() @@ -167,6 +168,7 @@ def setUp(self): super(TemplatedHTMLEmailMessageViewTestCase, self).setUp() self.html_body = 'html body' + self.expected_html_body = 'html body\n' self.html_body_template = get_template('body.html') self.context_dict['html'] = self.html_body @@ -203,14 +205,14 @@ def test_html_body_template_name(self): def test_html_body_template(self): self.message.html_body_template = self.html_body_template - self.assertEqual(self.render_html_body(), "html body\n") + self.assertEqual(self.render_html_body(), self.expected_html_body) def test_render_to_message(self): self.add_templates_to_message() message = self.message.render_to_message(self.context_dict) self.assertEqual(message.subject, self.subject) - self.assertEqual(message.body, "body\n") - self.assertEqual(message.alternatives, [("html body\n", 'text/html')]) + self.assertEqual(message.body, self.expected_body) + self.assertEqual(message.alternatives, [(self.expected_html_body, 'text/html')]) def test_send(self): self.add_templates_to_message()