Passed
Push — master ( 95313c...be9045 )
by Piotr
57s
created

test_get_context_data_with_insecure_request()   A

Complexity

Conditions 1

Size

Total Lines 17

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 17
loc 17
rs 9.4285
1
from unittest import mock
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
3
from django.contrib.auth.models import AnonymousUser
0 ignored issues
show
introduced by
Unable to import 'django.contrib.auth.models'
Loading history...
4
from django.contrib.sites.shortcuts import get_current_site
0 ignored issues
show
introduced by
Unable to import 'django.contrib.sites.shortcuts'
Loading history...
5
from django.core import mail
0 ignored issues
show
introduced by
Unable to import 'django.core'
Loading history...
6
from django.test import RequestFactory, TestCase
0 ignored issues
show
introduced by
Unable to import 'django.test'
Loading history...
7
8
from templated_mail.mail import BaseEmailMessage
9
10
11
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...
12
    def setUp(self):
0 ignored issues
show
Coding Style Naming introduced by
The name setUp 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...
13
        self.factory = RequestFactory()
14
        self.recipients = ['[email protected]']
15
16 View Code Duplication
    @mock.patch('django.core.handlers.wsgi.WSGIRequest.is_secure')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
17
    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...
18
        is_secure_mock.return_value = False
19
20
        request = self.factory.get('/')
21
        request.user = AnonymousUser()
22
23
        email_message = BaseEmailMessage(
24
            request=request, template_name='text_mail.html'
25
        )
26
        context = email_message.get_context_data()
27
        site = get_current_site(request)
28
29
        self.assertEquals(context['domain'], site.domain)
30
        self.assertEquals(context['protocol'], 'http')
31
        self.assertEquals(context['site_name'], site.name)
32
        self.assertEquals(context['user'], request.user)
33
34 View Code Duplication
    @mock.patch('django.core.handlers.wsgi.WSGIRequest.is_secure')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
35
    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...
36
        is_secure_mock.return_value = True
37
38
        request = self.factory.get('/')
39
        request.user = AnonymousUser()
40
41
        email_message = BaseEmailMessage(
42
            request=request, template_name='text_mail.html'
43
        )
44
        context = email_message.get_context_data()
45
        site = get_current_site(request)
46
47
        self.assertEquals(context['domain'], site.domain)
48
        self.assertEquals(context['protocol'], 'https')
49
        self.assertEquals(context['site_name'], site.name)
50
        self.assertEquals(context['user'], request.user)
51
52
    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...
53
        email_message = BaseEmailMessage(template_name='text_mail.html')
54
        context = email_message.get_context_data()
55
56
        self.assertEquals(context['domain'], '')
57
        self.assertEquals(context['protocol'], 'http')
58
        self.assertEquals(context['site_name'], '')
59
        self.assertEquals(context['user'], None)
60
61
    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...
62
        user = AnonymousUser()
63
        email_message = BaseEmailMessage(
64
            context={'user': user}, template_name='text_mail.html'
65
        )
66
        context = email_message.get_context_data()
67
68
        self.assertEquals(context['domain'], '')
69
        self.assertEquals(context['protocol'], 'http')
70
        self.assertEquals(context['site_name'], '')
71
        self.assertEquals(context['user'], user)
72
73 View Code Duplication
    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...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
74
        request = self.factory.get('/')
75
        request.user = AnonymousUser()
76
77
        BaseEmailMessage(
78
            request=request, template_name='text_mail.html'
79
        ).send(to=self.recipients)
80
81
        self.assertEqual(len(mail.outbox), 1)
82
        self.assertEqual(mail.outbox[0].recipients(), self.recipients)
83
        self.assertEqual(mail.outbox[0].subject, 'Text mail subject')
84
        self.assertEqual(mail.outbox[0].body, 'Foobar email content')
85
        self.assertEqual(mail.outbox[0].alternatives, [])
86
        self.assertEqual(mail.outbox[0].content_subtype, 'plain')
87
88 View Code Duplication
    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...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
89
        request = self.factory.get('/')
90
        request.user = AnonymousUser()
91
92
        BaseEmailMessage(
93
            request=request, template_name='html_mail.html'
94
        ).send(to=self.recipients)
95
96
        self.assertEqual(len(mail.outbox), 1)
97
        self.assertEqual(mail.outbox[0].recipients(), self.recipients)
98
        self.assertEqual(mail.outbox[0].subject, 'HTML mail subject')
99
        self.assertEqual(mail.outbox[0].body, '<p>Foobar email content</p>')
100
        self.assertEqual(mail.outbox[0].alternatives, [])
101
        self.assertEqual(mail.outbox[0].content_subtype, 'html')
102
103 View Code Duplication
    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...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
104
        request = self.factory.get('/')
105
        request.user = AnonymousUser()
106
107
        BaseEmailMessage(
108
            request=request, template_name='text_and_html_mail.html'
109
        ).send(to=self.recipients)
110
111
        self.assertEqual(len(mail.outbox), 1)
112
        self.assertEqual(mail.outbox[0].recipients(), self.recipients)
113
        self.assertEqual(mail.outbox[0].subject, 'Text and HTML mail subject')
114
        self.assertEqual(mail.outbox[0].body, 'Foobar email content')
115
        self.assertEqual(
116
            mail.outbox[0].alternatives,
117
            [('<p>Foobar email content</p>', 'text/html')]
118
        )
119
        self.assertEqual(mail.outbox[0].content_subtype, 'plain')
120
121
    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...
122
        BaseEmailMessage(
123
            request=None, template_name='text_mail.html'
124
        ).send(to=self.recipients)
125
126
        self.assertEqual(len(mail.outbox), 1)
127
        self.assertEqual(mail.outbox[0].recipients(), self.recipients)
128
        self.assertEqual(mail.outbox[0].subject, 'Text mail subject')
129
        self.assertEqual(mail.outbox[0].body, 'Foobar email content')
130
        self.assertEqual(mail.outbox[0].alternatives, [])
131
        self.assertEqual(mail.outbox[0].content_subtype, 'plain')
132
133 View Code Duplication
    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...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
134
        request = self.factory.get('/')
135
        request.user = AnonymousUser()
136
137
        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...
138
139
        BaseEmailMessage(
140
            request=request, template_name='text_mail.html'
141
        ).send(to=self.recipients, cc=cc)
142
143
        self.assertEqual(len(mail.outbox), 1)
144
        self.assertEqual(mail.outbox[0].to, self.recipients)
145
        self.assertEqual(mail.outbox[0].cc, cc)
146
        self.assertEqual(mail.outbox[0].subject, 'Text mail subject')
147
        self.assertEqual(mail.outbox[0].body, 'Foobar email content')
148
        self.assertEqual(mail.outbox[0].alternatives, [])
149
        self.assertEqual(mail.outbox[0].content_subtype, 'plain')
150
151 View Code Duplication
    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...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
152
        request = self.factory.get('/')
153
        request.user = AnonymousUser()
154
155
        bcc = ['[email protected]']
156
157
        BaseEmailMessage(
158
            request=request, template_name='text_mail.html'
159
        ).send(to=self.recipients, bcc=bcc)
160
161
        self.assertEqual(len(mail.outbox), 1)
162
        self.assertEqual(mail.outbox[0].to, self.recipients)
163
        self.assertEqual(mail.outbox[0].bcc, bcc)
164
        self.assertEqual(mail.outbox[0].subject, 'Text mail subject')
165
        self.assertEqual(mail.outbox[0].body, 'Foobar email content')
166
        self.assertEqual(mail.outbox[0].alternatives, [])
167
        self.assertEqual(mail.outbox[0].content_subtype, 'plain')
168