GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

test_notify_admins()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
c 2
b 0
f 0
dl 0
loc 10
rs 9.4285
1
# -*- coding: utf-8 -*-
2
from __future__ import unicode_literals
3
"""
4
"""
5
__author__ = 'Alisue <[email protected]>'
6
from django.test import TestCase
7
from django.conf import settings
8
from django.core import mail
9
from registration.backends.default import DefaultRegistrationBackend
10
from registration.tests.mock import mock_request
11
from registration.tests.compat import override_settings
12
13
14
@override_settings(
15
        ACCOUNT_ACTIVATION_DAYS=7,
16
        ADMINS=(
17
            ('admin1', '[email protected]'),
18
            ('admin2', '[email protected]'),
19
        ),
20
        MANAGERS=(
21
            ('manager1', '[email protected]'), 
22
            ('manager2', '[email protected]'),
23
        ),
24
        REGISTRATION_OPEN=True,
25
        REGISTRATION_SUPPLEMENT_CLASS=None,
26
        REGISTRATION_BACKEND_CLASS=(
27
            'registration.backends.default.DefaultRegistrationBackend'),
28
        REGISTRATION_REGISTRATION_EMAIL=False,
29
        REGISTRATION_NOTIFICATION=True,
30
        REGISTRATION_NOTIFICATION_ADMINS=True,
31
        REGISTRATION_NOTIFICATION_MANAGERS=True,
32
        REGISTRATION_NOTIFICATION_RECIPIENTS=False,
33
        _REGISTRATION_NOTIFICATION_IN_TESTS=True,
34
    )
35
class RegistrationNotificationTestCase(TestCase):
36
    backend = DefaultRegistrationBackend()
37
    mock_request = mock_request()
38
39
    def test_notify_admins(self):
40
        with override_settings(REGISTRATION_NOTIFICATION_MANAGERS=False):
41
            self.backend.register(
42
                    'bob', '[email protected]', request=self.mock_request
43
                )
44
45
            self.assertEqual(len(mail.outbox), 1)
46
            self.assertEqual(sorted(mail.outbox[0].to), sorted([
47
                    '[email protected]',
48
                    '[email protected]',
49
                ]))
50
51
    def test_notify_managers(self):
52
        with override_settings(REGISTRATION_NOTIFICATION_ADMINS=False):
53
            self.backend.register(
54
                    'bob', '[email protected]', request=self.mock_request
55
                )
56
57
            self.assertEqual(len(mail.outbox), 1)
58
            self.assertEqual(sorted(mail.outbox[0].to), sorted([
59
                    '[email protected]',
60
                    '[email protected]',
61
                ]))
62
63
    def test_notify_recipients_iterable(self):
64
        with override_settings(
65
            REGISTRATION_NOTIFICATION_ADMINS = False,
66
            REGISTRATION_NOTIFICATION_MANAGERS = False,
67
            REGISTRATION_NOTIFICATION_RECIPIENTS=(
68
                    '[email protected]',
69
                    '[email protected]',
70
                )):
71
            self.backend.register(
72
                    'bob', '[email protected]', request=self.mock_request
73
                )
74
75
            self.assertEqual(len(mail.outbox), 1)
76
            self.assertEqual(sorted(mail.outbox[0].to), sorted([
77
                    '[email protected]',
78
                    '[email protected]',
79
                ]))
80
81
    def test_notify_recipients_function(self):
82
        with override_settings(
83
            REGISTRATION_NOTIFICATION_ADMINS=False,
84
            REGISTRATION_NOTIFICATION_MANAGERS=False,
85
            REGISTRATION_NOTIFICATION_RECIPIENTS=lambda:(
86
                    '[email protected]',
87
                    '[email protected]',
88
                )):
89
            self.backend.register(
90
                    'bob', '[email protected]', request=self.mock_request
91
                )
92
93
            self.assertEqual(len(mail.outbox), 1)
94
            self.assertEqual(sorted(mail.outbox[0].to), sorted([
95
                    '[email protected]',
96
                    '[email protected]',
97
                ]))
98
99
    def test_notify_all(self):
100
        with override_settings(
101
            REGISTRATION_NOTIFICATION_ADMINS=True,
102
            REGISTRATION_NOTIFICATION_MANAGERS=True,
103
            REGISTRATION_NOTIFICATION_RECIPIENTS=(
104
                    '[email protected]',
105
                    '[email protected]',
106
                )):
107
            self.backend.register(
108
                    'bob', '[email protected]', request=self.mock_request
109
                )
110
111
            self.assertEqual(len(mail.outbox), 1)
112
            self.assertEqual(sorted(mail.outbox[0].to), sorted([
113
                    '[email protected]',
114
                    '[email protected]',
115
                    '[email protected]',
116
                    '[email protected]',
117
                    '[email protected]',
118
                    '[email protected]',
119
                ]))
120
121
    def test_notify_duplicated(self):
122
        with override_settings(
123
            REGISTRATION_NOTIFICATION_ADMINS=True,
124
            REGISTRATION_NOTIFICATION_MANAGERS=True,
125
            REGISTRATION_NOTIFICATION_RECIPIENTS=(
126
                    '[email protected]',
127
                    '[email protected]',
128
                    '[email protected]',
129
                    '[email protected]',
130
                    '[email protected]',
131
                    '[email protected]',
132
                ),
133
            ADMINS=(
134
                    ('admin1', '[email protected]'),
135
                    ('admin2', '[email protected]'),
136
                    ('manager1', '[email protected]'), 
137
                    ('manager2', '[email protected]'),
138
                    ('recipient1', '[email protected]'), 
139
                    ('recipient2', '[email protected]'),
140
                ),
141
            MANAGERS=(
142
                    ('admin1', '[email protected]'),
143
                    ('admin2', '[email protected]'),
144
                    ('manager1', '[email protected]'), 
145
                    ('manager2', '[email protected]'),
146
                    ('recipient1', '[email protected]'), 
147
                    ('recipient2', '[email protected]'),
148
                )):
149
            self.backend.register(
150
                    'bob', '[email protected]', request=self.mock_request
151
                )
152
153
            self.assertEqual(len(mail.outbox), 1)
154
            self.assertEqual(sorted(mail.outbox[0].to), sorted([
155
                    '[email protected]',
156
                    '[email protected]',
157
                    '[email protected]',
158
                    '[email protected]',
159
                    '[email protected]',
160
                    '[email protected]',
161
                ]))
162