Passed
Pull Request — master (#3)
by
unknown
01:21
created

test_extending_mail_with_context_mixin()   A

Complexity

Conditions 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 1
1
try:
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
    from unittest import mock
3
except ImportError:
4
    import mock
5
6
from django.contrib.auth.models import AnonymousUser
7
from django.contrib.sites.shortcuts import get_current_site
8
from django.core import mail
9
from django.test import RequestFactory, TestCase
10
from templated_mail.mail import BaseEmailMessage
11
12
from .helpers import MockMail
13
14
15
class TestBaseEmailMessage(TestCase):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
16
    def setUp(self):
17
        self.factory = RequestFactory()
18
        self.recipients = ['[email protected]']
19
20
    @mock.patch('django.core.handlers.wsgi.WSGIRequest.is_secure')
21
    def test_get_context_data_with_insecure_request(self, is_secure_mock):
0 ignored issues
show
Coding Style Naming introduced by
The name test_get_context_data_with_insecure_request does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
22
        is_secure_mock.return_value = False
23
24
        request = self.factory.get('/')
25
        request.user = AnonymousUser()
26
27
        email_message = BaseEmailMessage(
28
            request=request, template_name='text_mail.html'
29
        )
30
        context = email_message.get_context_data()
31
        site = get_current_site(request)
32
33
        self.assertEquals(context['domain'], site.domain)
0 ignored issues
show
introduced by
Using deprecated method assertEquals()
Loading history...
34
        self.assertEquals(context['protocol'], 'http')
0 ignored issues
show
introduced by
Using deprecated method assertEquals()
Loading history...
35
        self.assertEquals(context['site_name'], site.name)
0 ignored issues
show
introduced by
Using deprecated method assertEquals()
Loading history...
36
        self.assertEquals(context['user'], request.user)
0 ignored issues
show
introduced by
Using deprecated method assertEquals()
Loading history...
37
38
    @mock.patch('django.core.handlers.wsgi.WSGIRequest.is_secure')
39
    def test_get_context_data_with_secure_request(self, is_secure_mock):
0 ignored issues
show
Coding Style Naming introduced by
The name test_get_context_data_with_secure_request does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
40
        is_secure_mock.return_value = True
41
42
        request = self.factory.get('/')
43
        request.user = AnonymousUser()
44
45
        email_message = BaseEmailMessage(
46
            request=request, template_name='text_mail.html'
47
        )
48
        context = email_message.get_context_data()
49
        site = get_current_site(request)
50
51
        self.assertEquals(context['domain'], site.domain)
0 ignored issues
show
introduced by
Using deprecated method assertEquals()
Loading history...
52
        self.assertEquals(context['protocol'], 'https')
0 ignored issues
show
introduced by
Using deprecated method assertEquals()
Loading history...
53
        self.assertEquals(context['site_name'], site.name)
0 ignored issues
show
introduced by
Using deprecated method assertEquals()
Loading history...
54
        self.assertEquals(context['user'], request.user)
0 ignored issues
show
introduced by
Using deprecated method assertEquals()
Loading history...
55
56
    def test_get_context_data_without_request_no_context(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_get_context_data_without_request_no_context does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
57
        email_message = BaseEmailMessage(template_name='text_mail.html')
58
        context = email_message.get_context_data()
59
60
        self.assertEquals(context['domain'], '')
0 ignored issues
show
introduced by
Using deprecated method assertEquals()
Loading history...
61
        self.assertEquals(context['protocol'], 'http')
0 ignored issues
show
introduced by
Using deprecated method assertEquals()
Loading history...
62
        self.assertEquals(context['site_name'], '')
0 ignored issues
show
introduced by
Using deprecated method assertEquals()
Loading history...
63
        self.assertEquals(context['user'], None)
0 ignored issues
show
introduced by
Using deprecated method assertEquals()
Loading history...
64
65
    def test_get_context_data_without_request_user_context(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_get_context_data_without_request_user_context does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
66
        user = AnonymousUser()
67
        email_message = BaseEmailMessage(
68
            context={'user': user}, template_name='text_mail.html'
69
        )
70
        context = email_message.get_context_data()
71
72
        self.assertEquals(context['domain'], '')
0 ignored issues
show
introduced by
Using deprecated method assertEquals()
Loading history...
73
        self.assertEquals(context['protocol'], 'http')
0 ignored issues
show
introduced by
Using deprecated method assertEquals()
Loading history...
74
        self.assertEquals(context['site_name'], '')
0 ignored issues
show
introduced by
Using deprecated method assertEquals()
Loading history...
75
        self.assertEquals(context['user'], user)
0 ignored issues
show
introduced by
Using deprecated method assertEquals()
Loading history...
76
77
    def test_text_mail_contains_valid_data(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_text_mail_contains_valid_data does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
78
        request = self.factory.get('/')
79
        request.user = AnonymousUser()
80
81
        BaseEmailMessage(
82
            request=request, template_name='text_mail.html'
83
        ).send(to=self.recipients)
84
85
        self.assertEqual(len(mail.outbox), 1)
86
        self.assertEqual(mail.outbox[0].recipients(), self.recipients)
87
        self.assertEqual(mail.outbox[0].subject, 'Text mail subject')
88 View Code Duplication
        self.assertEqual(mail.outbox[0].body, 'Foobar email content')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
89
        self.assertEqual(mail.outbox[0].alternatives, [])
90
        self.assertEqual(mail.outbox[0].content_subtype, 'plain')
91
92
    def test_html_mail_contains_valid_data(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_html_mail_contains_valid_data does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
93
        request = self.factory.get('/')
94
        request.user = AnonymousUser()
95
96
        BaseEmailMessage(
97
            request=request, template_name='html_mail.html'
98
        ).send(to=self.recipients)
99
100
        self.assertEqual(len(mail.outbox), 1)
101
        self.assertEqual(mail.outbox[0].recipients(), self.recipients)
102
        self.assertEqual(mail.outbox[0].subject, 'HTML mail subject')
103 View Code Duplication
        self.assertEqual(mail.outbox[0].body, '<p>Foobar email content</p>')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
104
        self.assertEqual(mail.outbox[0].alternatives, [])
105
        self.assertEqual(mail.outbox[0].content_subtype, 'html')
106
107
    def test_text_and_html_mail_contains_valid_data(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_text_and_html_mail_contains_valid_data does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
108
        request = self.factory.get('/')
109
        request.user = AnonymousUser()
110
111
        BaseEmailMessage(
112
            request=request, template_name='text_and_html_mail.html'
113
        ).send(to=self.recipients)
114
115
        self.assertEqual(len(mail.outbox), 1)
116
        self.assertEqual(mail.outbox[0].recipients(), self.recipients)
117
        self.assertEqual(mail.outbox[0].subject, 'Text and HTML mail subject')
118
        self.assertEqual(mail.outbox[0].body, 'Foobar email content')
119
        self.assertEqual(
120
            mail.outbox[0].alternatives,
121
            [('<p>Foobar email content</p>', 'text/html')]
122
        )
123
        self.assertEqual(mail.outbox[0].content_subtype, 'plain')
124
125
    def test_can_send_mail_with_none_request(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_can_send_mail_with_none_request does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
126
        BaseEmailMessage(
127
            request=None, template_name='text_mail.html'
128
        ).send(to=self.recipients)
129
130
        self.assertEqual(len(mail.outbox), 1)
131
        self.assertEqual(mail.outbox[0].recipients(), self.recipients)
132
        self.assertEqual(mail.outbox[0].subject, 'Text mail subject')
133 View Code Duplication
        self.assertEqual(mail.outbox[0].body, 'Foobar email content')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
134
        self.assertEqual(mail.outbox[0].alternatives, [])
135
        self.assertEqual(mail.outbox[0].content_subtype, 'plain')
136
137
    def test_mail_cc_is_sent_to_valid_cc(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_mail_cc_is_sent_to_valid_cc does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
138
        request = self.factory.get('/')
139
        request.user = AnonymousUser()
140
141
        cc = ['[email protected]']
0 ignored issues
show
Coding Style Naming introduced by
The name cc does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
142
143
        BaseEmailMessage(
144
            request=request, template_name='text_mail.html'
145
        ).send(to=self.recipients, cc=cc)
146
147
        self.assertEqual(len(mail.outbox), 1)
148
        self.assertEqual(mail.outbox[0].to, self.recipients)
149
        self.assertEqual(mail.outbox[0].cc, cc)
150
        self.assertEqual(mail.outbox[0].subject, 'Text mail subject')
151 View Code Duplication
        self.assertEqual(mail.outbox[0].body, 'Foobar email content')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
152
        self.assertEqual(mail.outbox[0].alternatives, [])
153
        self.assertEqual(mail.outbox[0].content_subtype, 'plain')
154
155
    def test_mail_bcc_is_sent_to_valid_bcc(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_mail_bcc_is_sent_to_valid_bcc does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
156
        request = self.factory.get('/')
157
        request.user = AnonymousUser()
158
159
        bcc = ['[email protected]']
160
161
        BaseEmailMessage(
162
            request=request, template_name='text_mail.html'
163
        ).send(to=self.recipients, bcc=bcc)
164
165
        self.assertEqual(len(mail.outbox), 1)
166
        self.assertEqual(mail.outbox[0].to, self.recipients)
167
        self.assertEqual(mail.outbox[0].bcc, bcc)
168
        self.assertEqual(mail.outbox[0].subject, 'Text mail subject')
169
        self.assertEqual(mail.outbox[0].body, 'Foobar email content')
170
        self.assertEqual(mail.outbox[0].alternatives, [])
171
        self.assertEqual(mail.outbox[0].content_subtype, 'plain')
172
173
    def test_mail_reply_to_is_sent_with_valid_reply_to(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_mail_reply_to_is_sent_with_valid_reply_to does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
174
        request = self.factory.get('/')
175
        request.user = AnonymousUser()
176
177
        reply_to = ['[email protected]']
178
179
        BaseEmailMessage(
180
            request=request, template_name='text_mail.html'
181
        ).send(to=self.recipients, reply_to=reply_to)
182
183
        self.assertEqual(len(mail.outbox), 1)
184
        self.assertEqual(mail.outbox[0].to, self.recipients)
185
        self.assertEqual(mail.outbox[0].reply_to, reply_to)
186
        self.assertEqual(mail.outbox[0].subject, 'Text mail subject')
187
        self.assertEqual(mail.outbox[0].body, 'Foobar email content')
188
        self.assertEqual(mail.outbox[0].alternatives, [])
189
        self.assertEqual(mail.outbox[0].content_subtype, 'plain')
190
191
    def test_mail_from_email_is_sent_with_valid_from_email(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_mail_from_email_is_sent_with_valid_from_email does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
192
        request = self.factory.get('/')
193
        request.user = AnonymousUser()
194
195
        from_email = '<Example - [email protected]>'
196
197
        BaseEmailMessage(
198
            request=request, template_name='text_mail.html'
199
        ).send(to=self.recipients, from_email=from_email)
200
201
        self.assertEqual(len(mail.outbox), 1)
202
        self.assertEqual(mail.outbox[0].to, self.recipients)
203
        self.assertEqual(mail.outbox[0].from_email, from_email)
204
        self.assertEqual(mail.outbox[0].subject, 'Text mail subject')
205
        self.assertEqual(mail.outbox[0].body, 'Foobar email content')
206
        self.assertEqual(mail.outbox[0].alternatives, [])
207
        self.assertEqual(mail.outbox[0].content_subtype, 'plain')
208
209
    def test_extending_mail_with_context_mixin(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_extending_mail_with_context_mixin does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
210
        email_message = MockMail(
211
            template_name='text_mail.html', context={'foo': 'bar'}
212
        )
213
214
        context = email_message.get_context_data()
215
216
        self.assertEquals(context['foo'], 'bar')
0 ignored issues
show
introduced by
Using deprecated method assertEquals()
Loading history...
217
        self.assertEquals(context['thing'], 42)
0 ignored issues
show
introduced by
Using deprecated method assertEquals()
Loading history...
218