Skip to content

Commit 87a8a85

Browse files
committed
Black on all of test_notifications
1 parent 4e89d01 commit 87a8a85

File tree

1 file changed

+86
-88
lines changed

1 file changed

+86
-88
lines changed

readthedocs/rtd_tests/tests/test_notifications.py

+86-88
Original file line numberDiff line numberDiff line change
@@ -22,79 +22,78 @@
2222

2323
@override_settings(
2424
NOTIFICATION_BACKENDS=[
25-
'readthedocs.notifications.backends.EmailBackend',
26-
'readthedocs.notifications.backends.SiteBackend',
25+
"readthedocs.notifications.backends.EmailBackend",
26+
"readthedocs.notifications.backends.SiteBackend",
2727
],
28-
PRODUCTION_DOMAIN='readthedocs.org',
29-
SUPPORT_EMAIL='[email protected]',
28+
PRODUCTION_DOMAIN="readthedocs.org",
29+
SUPPORT_EMAIL="[email protected]",
3030
)
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")
3333
class NotificationTests(TestCase):
34-
3534
def test_notification_custom(self, send, render_to_string):
36-
render_to_string.return_value = 'Test'
35+
render_to_string.return_value = "Test"
3736

3837
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"
4241

4342
build = fixture.get(Build)
4443
req = mock.MagicMock()
4544
notify = TestNotification(context_object=build, request=req)
4645

4746
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"],
5049
)
5150
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"],
5453
)
5554
self.assertEqual(
5655
notify.get_subject(),
57-
'This is {}'.format(build.id),
56+
"This is {}".format(build.id),
5857
)
5958
self.assertEqual(
6059
notify.get_context_data(),
6160
{
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,
6664
# 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,
7876
},
7977
)
8078

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+
)
8888

8989

9090
class NotificationBackendTests(TestCase):
91-
92-
@mock.patch('readthedocs.notifications.backends.send_email')
91+
@mock.patch("readthedocs.notifications.backends.send_email")
9392
def test_email_backend(self, send_email):
9493
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"
9897
level = ERROR
9998

10099
build = fixture.get(Build)
@@ -118,12 +117,12 @@ class TestNotification(Notification):
118117

119118
@mock.patch("readthedocs.notifications.notification.render_to_string")
120119
def test_message_backend(self, render_to_string):
121-
render_to_string.return_value = 'Test'
120+
render_to_string.return_value = "Test"
122121

123122
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"
127126

128127
build = fixture.get(Build)
129128
user = fixture.get(User)
@@ -141,12 +140,12 @@ class TestNotification(Notification):
141140
@mock.patch("readthedocs.notifications.notification.render_to_string")
142141
def test_message_anonymous_user(self, render_to_string):
143142
"""Anonymous user still throwns exception on persistent messages."""
144-
render_to_string.return_value = 'Test'
143+
render_to_string.return_value = "Test"
145144

146145
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"
150149

151150
build = fixture.get(Build)
152151
user = AnonymousUser()
@@ -164,11 +163,11 @@ class TestNotification(Notification):
164163
self.assertEqual(render_to_string.call_count, 1)
165164
self.assertEqual(PersistentMessage.objects.count(), 0)
166165

167-
@mock.patch('readthedocs.notifications.backends.send_email')
166+
@mock.patch("readthedocs.notifications.backends.send_email")
168167
def test_non_persistent_message(self, send_email):
169168
class TestNotification(SiteNotification):
170-
name = 'foo'
171-
success_message = 'Test success message'
169+
name = "foo"
170+
success_message = "Test success message"
172171
success_level = INFO_NON_PERSISTENT
173172

174173
user = fixture.get(User)
@@ -186,39 +185,38 @@ class TestNotification(SiteNotification):
186185
self.assertEqual(PersistentMessage.objects.filter(read=False).count(), 1)
187186

188187
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")
191190
self.assertEqual(PersistentMessage.objects.count(), 1)
192191
self.assertEqual(PersistentMessage.objects.filter(read=True).count(), 1)
193192

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")
196195

197196

198197
@override_settings(
199-
PRODUCTION_DOMAIN='readthedocs.org',
200-
SUPPORT_EMAIL='[email protected]',
198+
PRODUCTION_DOMAIN="readthedocs.org",
199+
SUPPORT_EMAIL="[email protected]",
201200
)
202201
class SiteNotificationTests(TestCase):
203-
204202
class TestSiteNotification(SiteNotification):
205-
name = 'foo'
206-
success_message = 'simple success message'
203+
name = "foo"
204+
success_message = "simple success message"
207205
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",
211209
}
212210
success_level = INFO_NON_PERSISTENT
213211
failure_level = WARNING_NON_PERSISTENT
214212

215213
def setUp(self):
216214
self.user = fixture.get(User)
217-
self.context = {'other': {'name': 'other name'}}
215+
self.context = {"other": {"name": "other name"}}
218216
self.n = self.TestSiteNotification(
219217
self.user,
220218
True,
221-
context_object={'name': 'object name'},
219+
context_object={"name": "object name"},
222220
extra_context=self.context,
223221
)
224222

@@ -229,17 +227,17 @@ def test_context_data(self):
229227
"production_uri": "https://readthedocs.org",
230228
"other": {"name": "other name"},
231229
# 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,
243241
}
244242
self.assertEqual(self.n.get_context_data(), context)
245243

@@ -252,19 +250,19 @@ def test_message_level(self):
252250

253251
def test_message(self):
254252
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")
258256

259257
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")
261259
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")
265263

266264
# Invalid reason
267265
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), "")
270268
mock_log.error.assert_called_once()

0 commit comments

Comments
 (0)