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 ,
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 ,
77
76
},
78
77
)
79
78
80
- notify .render ('site' )
81
- render_to_string .assert_has_calls ([
82
- mock .call (
83
- context = mock .ANY ,
84
- template_name = ['builds/notifications/foo_site.html' ],
85
- ),
86
- ])
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
+ )
87
88
88
89
89
90
class NotificationBackendTests (TestCase ):
90
-
91
- @mock .patch ('readthedocs.notifications.backends.send_email' )
91
+ @mock .patch ("readthedocs.notifications.backends.send_email" )
92
92
def test_email_backend (self , send_email ):
93
93
class TestNotification (Notification ):
94
- name = ' foo'
95
- subject = ' This is {{ foo.id }}'
96
- context_object_name = ' foo'
94
+ name = " foo"
95
+ subject = " This is {{ foo.id }}"
96
+ context_object_name = " foo"
97
97
level = ERROR
98
98
99
99
build = fixture .get (Build )
@@ -117,12 +117,12 @@ class TestNotification(Notification):
117
117
118
118
@mock .patch ("readthedocs.notifications.notification.render_to_string" )
119
119
def test_message_backend (self , render_to_string ):
120
- render_to_string .return_value = ' Test'
120
+ render_to_string .return_value = " Test"
121
121
122
122
class TestNotification (Notification ):
123
- name = ' foo'
124
- subject = ' This is {{ foo.id }}'
125
- context_object_name = ' foo'
123
+ name = " foo"
124
+ subject = " This is {{ foo.id }}"
125
+ context_object_name = " foo"
126
126
127
127
build = fixture .get (Build )
128
128
user = fixture .get (User )
@@ -140,12 +140,12 @@ class TestNotification(Notification):
140
140
@mock .patch ("readthedocs.notifications.notification.render_to_string" )
141
141
def test_message_anonymous_user (self , render_to_string ):
142
142
"""Anonymous user still throwns exception on persistent messages."""
143
- render_to_string .return_value = ' Test'
143
+ render_to_string .return_value = " Test"
144
144
145
145
class TestNotification (Notification ):
146
- name = ' foo'
147
- subject = ' This is {{ foo.id }}'
148
- context_object_name = ' foo'
146
+ name = " foo"
147
+ subject = " This is {{ foo.id }}"
148
+ context_object_name = " foo"
149
149
150
150
build = fixture .get (Build )
151
151
user = AnonymousUser ()
@@ -163,11 +163,11 @@ class TestNotification(Notification):
163
163
self .assertEqual (render_to_string .call_count , 1 )
164
164
self .assertEqual (PersistentMessage .objects .count (), 0 )
165
165
166
- @mock .patch (' readthedocs.notifications.backends.send_email' )
166
+ @mock .patch (" readthedocs.notifications.backends.send_email" )
167
167
def test_non_persistent_message (self , send_email ):
168
168
class TestNotification (SiteNotification ):
169
- name = ' foo'
170
- success_message = ' Test success message'
169
+ name = " foo"
170
+ success_message = " Test success message"
171
171
success_level = INFO_NON_PERSISTENT
172
172
173
173
user = fixture .get (User )
@@ -185,39 +185,38 @@ class TestNotification(SiteNotification):
185
185
self .assertEqual (PersistentMessage .objects .filter (read = False ).count (), 1 )
186
186
187
187
self .client .force_login (user )
188
- response = self .client .get (' /dashboard/' )
189
- self .assertContains (response , ' Test success message' )
188
+ response = self .client .get (" /dashboard/" )
189
+ self .assertContains (response , " Test success message" )
190
190
self .assertEqual (PersistentMessage .objects .count (), 1 )
191
191
self .assertEqual (PersistentMessage .objects .filter (read = True ).count (), 1 )
192
192
193
- response = self .client .get (' /dashboard/' )
194
- self .assertNotContains (response , ' Test success message' )
193
+ response = self .client .get (" /dashboard/" )
194
+ self .assertNotContains (response , " Test success message" )
195
195
196
196
197
197
@override_settings (
198
- PRODUCTION_DOMAIN = ' readthedocs.org' ,
199
- SUPPORT_EMAIL = ' [email protected] ' ,
198
+ PRODUCTION_DOMAIN = " readthedocs.org" ,
199
+ SUPPORT_EMAIL = " [email protected] " ,
200
200
)
201
201
class SiteNotificationTests (TestCase ):
202
-
203
202
class TestSiteNotification (SiteNotification ):
204
- name = ' foo'
205
- success_message = ' simple success message'
203
+ name = " foo"
204
+ success_message = " simple success message"
206
205
failure_message = {
207
- 1 : ' simple failure message' ,
208
- 2 : ' {{ object.name }} object name' ,
209
- ' 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" ,
210
209
}
211
210
success_level = INFO_NON_PERSISTENT
212
211
failure_level = WARNING_NON_PERSISTENT
213
212
214
213
def setUp (self ):
215
214
self .user = fixture .get (User )
216
- self .context = {' other' : {' name' : ' other name' }}
215
+ self .context = {" other" : {" name" : " other name" }}
217
216
self .n = self .TestSiteNotification (
218
217
self .user ,
219
218
True ,
220
- context_object = {' name' : ' object name' },
219
+ context_object = {" name" : " object name" },
221
220
extra_context = self .context ,
222
221
)
223
222
@@ -228,16 +227,17 @@ def test_context_data(self):
228
227
"production_uri" : "https://readthedocs.org" ,
229
228
"other" : {"name" : "other name" },
230
229
# readthedocs_processor context
231
- 'DASHBOARD_ANALYTICS_CODE' : mock .ANY ,
232
- 'DO_NOT_TRACK_ENABLED' : mock .ANY ,
233
- 'GLOBAL_ANALYTICS_CODE' : mock .ANY ,
234
- 'PRODUCTION_DOMAIN' : 'readthedocs.org' ,
235
- 'PUBLIC_DOMAIN' : mock .ANY ,
236
- 'SITE_ROOT' : mock .ANY ,
237
- 'SUPPORT_EMAIL' :
'[email protected] ' ,
238
- 'TEMPLATE_ROOT' : mock .ANY ,
239
- 'USE_PROMOS' : mock .ANY ,
240
- 'USE_SUBDOMAIN' : 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 ,
241
241
}
242
242
self .assertEqual (self .n .get_context_data (), context )
243
243
@@ -250,19 +250,19 @@ def test_message_level(self):
250
250
251
251
def test_message (self ):
252
252
self .n .reason = 1
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' )
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" )
256
256
257
257
self .n .reason = 1
258
- self .assertEqual (self .n .get_message (False ), ' simple failure message' )
258
+ self .assertEqual (self .n .get_message (False ), " simple failure message" )
259
259
self .n .reason = 2
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' )
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" )
263
263
264
264
# Invalid reason
265
265
self .n .reason = None
266
- with mock .patch (' readthedocs.notifications.notification.log' ) as mock_log :
267
- 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 ), "" )
268
268
mock_log .error .assert_called_once ()
0 commit comments