22
22
23
23
@override_settings (
24
24
NOTIFICATION_BACKENDS = [
25
- ' readthedocs.notifications.backends.EmailBackend' ,
26
- ' readthedocs.notifications.backends.SiteBackend' ,
25
+ " readthedocs.notifications.backends.EmailBackend" ,
26
+ " readthedocs.notifications.backends.SiteBackend" ,
27
27
],
28
- PRODUCTION_DOMAIN = ' readthedocs.org' ,
29
- SUPPORT_EMAIL = ' [email protected] ' ,
28
+ PRODUCTION_DOMAIN = " readthedocs.org" ,
29
+ SUPPORT_EMAIL = " [email protected] " ,
30
30
)
31
- @mock .patch (' readthedocs.notifications.notification.render_to_string' )
32
- @mock .patch .object (Notification , ' send' )
31
+ @mock .patch (" readthedocs.notifications.notification.render_to_string" )
32
+ @mock .patch .object (Notification , " send" )
33
33
class NotificationTests (TestCase ):
34
-
35
34
def test_notification_custom (self , send , render_to_string ):
36
- render_to_string .return_value = ' Test'
35
+ render_to_string .return_value = " Test"
37
36
38
37
class TestNotification (Notification ):
39
- name = ' foo'
40
- subject = ' This is {{ foo.id }}'
41
- context_object_name = ' foo'
38
+ name = " foo"
39
+ subject = " This is {{ foo.id }}"
40
+ context_object_name = " foo"
42
41
43
42
build = fixture .get (Build )
44
43
req = mock .MagicMock ()
45
44
notify = TestNotification (context_object = build , request = req )
46
45
47
46
self .assertEqual (
48
- notify .get_template_names (' email' ),
49
- [' builds/notifications/foo_email.html' ],
47
+ notify .get_template_names (" email" ),
48
+ [" builds/notifications/foo_email.html" ],
50
49
)
51
50
self .assertEqual (
52
- notify .get_template_names (' site' ),
53
- [' builds/notifications/foo_site.html' ],
51
+ notify .get_template_names (" site" ),
52
+ [" builds/notifications/foo_site.html" ],
54
53
)
55
54
self .assertEqual (
56
55
notify .get_subject (),
57
- ' This is {}' .format (build .id ),
56
+ " This is {}" .format (build .id ),
58
57
)
59
58
self .assertEqual (
60
59
notify .get_context_data (),
61
60
{
62
- 'foo' : build ,
63
- 'production_uri' : 'https://readthedocs.org' ,
64
- 'request' : req ,
65
-
61
+ "foo" : build ,
62
+ "production_uri" : "https://readthedocs.org" ,
63
+ "request" : req ,
66
64
# readthedocs_processor context
67
- ' DASHBOARD_ANALYTICS_CODE' : mock .ANY ,
68
- ' DO_NOT_TRACK_ENABLED' : mock .ANY ,
69
- ' GLOBAL_ANALYTICS_CODE' : mock .ANY ,
70
- ' PRODUCTION_DOMAIN' : ' readthedocs.org' ,
71
- ' PUBLIC_DOMAIN' : mock .ANY ,
72
- ' SITE_ROOT' : mock .ANY ,
73
- ' SUPPORT_EMAIL' : ' [email protected] ' ,
74
- ' TEMPLATE_ROOT' : mock .ANY ,
75
- ' USE_PROMOS' : mock .ANY ,
76
- ' USE_SUBDOMAIN' : mock .ANY ,
77
- ' USE_ORGANIZATIONS' : mock .ANY ,
65
+ " DASHBOARD_ANALYTICS_CODE" : mock .ANY ,
66
+ " DO_NOT_TRACK_ENABLED" : mock .ANY ,
67
+ " GLOBAL_ANALYTICS_CODE" : mock .ANY ,
68
+ " PRODUCTION_DOMAIN" : " readthedocs.org" ,
69
+ " PUBLIC_DOMAIN" : mock .ANY ,
70
+ " SITE_ROOT" : mock .ANY ,
71
+ " SUPPORT_EMAIL" : " [email protected] " ,
72
+ " TEMPLATE_ROOT" : mock .ANY ,
73
+ " USE_PROMOS" : mock .ANY ,
74
+ " USE_SUBDOMAIN" : mock .ANY ,
75
+ " USE_ORGANIZATIONS" : mock .ANY ,
78
76
},
79
77
)
80
78
81
- notify .render ('site' )
82
- render_to_string .assert_has_calls ([
83
- mock .call (
84
- context = mock .ANY ,
85
- template_name = ['builds/notifications/foo_site.html' ],
86
- ),
87
- ])
79
+ notify .render ("site" )
80
+ render_to_string .assert_has_calls (
81
+ [
82
+ mock .call (
83
+ context = mock .ANY ,
84
+ template_name = ["builds/notifications/foo_site.html" ],
85
+ ),
86
+ ]
87
+ )
88
88
89
89
90
90
class NotificationBackendTests (TestCase ):
91
-
92
- @mock .patch ('readthedocs.notifications.backends.send_email' )
91
+ @mock .patch ("readthedocs.notifications.backends.send_email" )
93
92
def test_email_backend (self , send_email ):
94
93
class TestNotification (Notification ):
95
- name = ' foo'
96
- subject = ' This is {{ foo.id }}'
97
- context_object_name = ' foo'
94
+ name = " foo"
95
+ subject = " This is {{ foo.id }}"
96
+ context_object_name = " foo"
98
97
level = ERROR
99
98
100
99
build = fixture .get (Build )
@@ -118,12 +117,12 @@ class TestNotification(Notification):
118
117
119
118
@mock .patch ("readthedocs.notifications.notification.render_to_string" )
120
119
def test_message_backend (self , render_to_string ):
121
- render_to_string .return_value = ' Test'
120
+ render_to_string .return_value = " Test"
122
121
123
122
class TestNotification (Notification ):
124
- name = ' foo'
125
- subject = ' This is {{ foo.id }}'
126
- context_object_name = ' foo'
123
+ name = " foo"
124
+ subject = " This is {{ foo.id }}"
125
+ context_object_name = " foo"
127
126
128
127
build = fixture .get (Build )
129
128
user = fixture .get (User )
@@ -141,12 +140,12 @@ class TestNotification(Notification):
141
140
@mock .patch ("readthedocs.notifications.notification.render_to_string" )
142
141
def test_message_anonymous_user (self , render_to_string ):
143
142
"""Anonymous user still throwns exception on persistent messages."""
144
- render_to_string .return_value = ' Test'
143
+ render_to_string .return_value = " Test"
145
144
146
145
class TestNotification (Notification ):
147
- name = ' foo'
148
- subject = ' This is {{ foo.id }}'
149
- context_object_name = ' foo'
146
+ name = " foo"
147
+ subject = " This is {{ foo.id }}"
148
+ context_object_name = " foo"
150
149
151
150
build = fixture .get (Build )
152
151
user = AnonymousUser ()
@@ -164,11 +163,11 @@ class TestNotification(Notification):
164
163
self .assertEqual (render_to_string .call_count , 1 )
165
164
self .assertEqual (PersistentMessage .objects .count (), 0 )
166
165
167
- @mock .patch (' readthedocs.notifications.backends.send_email' )
166
+ @mock .patch (" readthedocs.notifications.backends.send_email" )
168
167
def test_non_persistent_message (self , send_email ):
169
168
class TestNotification (SiteNotification ):
170
- name = ' foo'
171
- success_message = ' Test success message'
169
+ name = " foo"
170
+ success_message = " Test success message"
172
171
success_level = INFO_NON_PERSISTENT
173
172
174
173
user = fixture .get (User )
@@ -186,39 +185,38 @@ class TestNotification(SiteNotification):
186
185
self .assertEqual (PersistentMessage .objects .filter (read = False ).count (), 1 )
187
186
188
187
self .client .force_login (user )
189
- response = self .client .get (' /dashboard/' )
190
- self .assertContains (response , ' Test success message' )
188
+ response = self .client .get (" /dashboard/" )
189
+ self .assertContains (response , " Test success message" )
191
190
self .assertEqual (PersistentMessage .objects .count (), 1 )
192
191
self .assertEqual (PersistentMessage .objects .filter (read = True ).count (), 1 )
193
192
194
- response = self .client .get (' /dashboard/' )
195
- self .assertNotContains (response , ' Test success message' )
193
+ response = self .client .get (" /dashboard/" )
194
+ self .assertNotContains (response , " Test success message" )
196
195
197
196
198
197
@override_settings (
199
- PRODUCTION_DOMAIN = ' readthedocs.org' ,
200
- SUPPORT_EMAIL = ' [email protected] ' ,
198
+ PRODUCTION_DOMAIN = " readthedocs.org" ,
199
+ SUPPORT_EMAIL = " [email protected] " ,
201
200
)
202
201
class SiteNotificationTests (TestCase ):
203
-
204
202
class TestSiteNotification (SiteNotification ):
205
- name = ' foo'
206
- success_message = ' simple success message'
203
+ name = " foo"
204
+ success_message = " simple success message"
207
205
failure_message = {
208
- 1 : ' simple failure message' ,
209
- 2 : ' {{ object.name }} object name' ,
210
- ' three' : ' {{ object.name }} and {{ other.name }} render' ,
206
+ 1 : " simple failure message" ,
207
+ 2 : " {{ object.name }} object name" ,
208
+ " three" : " {{ object.name }} and {{ other.name }} render" ,
211
209
}
212
210
success_level = INFO_NON_PERSISTENT
213
211
failure_level = WARNING_NON_PERSISTENT
214
212
215
213
def setUp (self ):
216
214
self .user = fixture .get (User )
217
- self .context = {' other' : {' name' : ' other name' }}
215
+ self .context = {" other" : {" name" : " other name" }}
218
216
self .n = self .TestSiteNotification (
219
217
self .user ,
220
218
True ,
221
- context_object = {' name' : ' object name' },
219
+ context_object = {" name" : " object name" },
222
220
extra_context = self .context ,
223
221
)
224
222
@@ -229,17 +227,17 @@ def test_context_data(self):
229
227
"production_uri" : "https://readthedocs.org" ,
230
228
"other" : {"name" : "other name" },
231
229
# readthedocs_processor context
232
- ' DASHBOARD_ANALYTICS_CODE' : mock .ANY ,
233
- ' DO_NOT_TRACK_ENABLED' : mock .ANY ,
234
- ' GLOBAL_ANALYTICS_CODE' : mock .ANY ,
235
- ' PRODUCTION_DOMAIN' : ' readthedocs.org' ,
236
- ' PUBLIC_DOMAIN' : mock .ANY ,
237
- ' SITE_ROOT' : mock .ANY ,
238
- ' SUPPORT_EMAIL' : ' [email protected] ' ,
239
- ' TEMPLATE_ROOT' : mock .ANY ,
240
- ' USE_PROMOS' : mock .ANY ,
241
- ' USE_SUBDOMAIN' : mock .ANY ,
242
- ' USE_ORGANIZATIONS' : mock .ANY ,
230
+ " DASHBOARD_ANALYTICS_CODE" : mock .ANY ,
231
+ " DO_NOT_TRACK_ENABLED" : mock .ANY ,
232
+ " GLOBAL_ANALYTICS_CODE" : mock .ANY ,
233
+ " PRODUCTION_DOMAIN" : " readthedocs.org" ,
234
+ " PUBLIC_DOMAIN" : mock .ANY ,
235
+ " SITE_ROOT" : mock .ANY ,
236
+ " SUPPORT_EMAIL" : " [email protected] " ,
237
+ " TEMPLATE_ROOT" : mock .ANY ,
238
+ " USE_PROMOS" : mock .ANY ,
239
+ " USE_SUBDOMAIN" : mock .ANY ,
240
+ " USE_ORGANIZATIONS" : mock .ANY ,
243
241
}
244
242
self .assertEqual (self .n .get_context_data (), context )
245
243
@@ -252,19 +250,19 @@ def test_message_level(self):
252
250
253
251
def test_message (self ):
254
252
self .n .reason = 1
255
- self .assertEqual (self .n .get_message (True ), ' simple success message' )
256
- self .n .reason = ' three'
257
- self .assertEqual (self .n .get_message (True ), ' simple success message' )
253
+ self .assertEqual (self .n .get_message (True ), " simple success message" )
254
+ self .n .reason = " three"
255
+ self .assertEqual (self .n .get_message (True ), " simple success message" )
258
256
259
257
self .n .reason = 1
260
- self .assertEqual (self .n .get_message (False ), ' simple failure message' )
258
+ self .assertEqual (self .n .get_message (False ), " simple failure message" )
261
259
self .n .reason = 2
262
- self .assertEqual (self .n .get_message (False ), ' object name object name' )
263
- self .n .reason = ' three'
264
- self .assertEqual (self .n .get_message (False ), ' object name and other name render' )
260
+ self .assertEqual (self .n .get_message (False ), " object name object name" )
261
+ self .n .reason = " three"
262
+ self .assertEqual (self .n .get_message (False ), " object name and other name render" )
265
263
266
264
# Invalid reason
267
265
self .n .reason = None
268
- with mock .patch (' readthedocs.notifications.notification.log' ) as mock_log :
269
- self .assertEqual (self .n .get_message (False ), '' )
266
+ with mock .patch (" readthedocs.notifications.notification.log" ) as mock_log :
267
+ self .assertEqual (self .n .get_message (False ), "" )
270
268
mock_log .error .assert_called_once ()
0 commit comments