Skip to content

Commit 689e5c6

Browse files
authored
Add USE_ORGANIZATIONS context variablea (#10592)
* Add USE_ORGANIZATIONS context variable * Format * Make prospector happy * Fix test fixture data * Black on all of test_notifications
1 parent 7d65c16 commit 689e5c6

File tree

2 files changed

+97
-98
lines changed

2 files changed

+97
-98
lines changed
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
21
"""Template context processors for core app."""
32

43
from django.conf import settings
54

65

76
def readthedocs_processor(request):
8-
# pylint: disable=unused-argument
97
exports = {
10-
'PUBLIC_DOMAIN': settings.PUBLIC_DOMAIN,
11-
'PRODUCTION_DOMAIN': settings.PRODUCTION_DOMAIN,
12-
'USE_SUBDOMAIN': settings.USE_SUBDOMAIN,
13-
'GLOBAL_ANALYTICS_CODE': settings.GLOBAL_ANALYTICS_CODE,
14-
'DASHBOARD_ANALYTICS_CODE': settings.DASHBOARD_ANALYTICS_CODE,
15-
'SITE_ROOT': settings.SITE_ROOT + '/',
16-
'TEMPLATE_ROOT': settings.TEMPLATE_ROOT + '/',
17-
'DO_NOT_TRACK_ENABLED': settings.DO_NOT_TRACK_ENABLED,
18-
'USE_PROMOS': settings.USE_PROMOS,
19-
'SUPPORT_EMAIL': settings.SUPPORT_EMAIL,
8+
"PUBLIC_DOMAIN": settings.PUBLIC_DOMAIN,
9+
"PRODUCTION_DOMAIN": settings.PRODUCTION_DOMAIN,
10+
"USE_SUBDOMAIN": settings.USE_SUBDOMAIN,
11+
"GLOBAL_ANALYTICS_CODE": settings.GLOBAL_ANALYTICS_CODE,
12+
"DASHBOARD_ANALYTICS_CODE": settings.DASHBOARD_ANALYTICS_CODE,
13+
"SITE_ROOT": settings.SITE_ROOT + "/",
14+
"TEMPLATE_ROOT": settings.TEMPLATE_ROOT + "/",
15+
"DO_NOT_TRACK_ENABLED": settings.DO_NOT_TRACK_ENABLED,
16+
"USE_PROMOS": settings.USE_PROMOS,
17+
"USE_ORGANIZATIONS": settings.RTD_ALLOW_ORGANIZATIONS,
18+
"SUPPORT_EMAIL": settings.SUPPORT_EMAIL,
2019
}
2120
return exports

readthedocs/rtd_tests/tests/test_notifications.py

Lines changed: 86 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -22,78 +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,
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,
7776
},
7877
)
7978

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

8889

8990
class NotificationBackendTests(TestCase):
90-
91-
@mock.patch('readthedocs.notifications.backends.send_email')
91+
@mock.patch("readthedocs.notifications.backends.send_email")
9292
def test_email_backend(self, send_email):
9393
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"
9797
level = ERROR
9898

9999
build = fixture.get(Build)
@@ -117,12 +117,12 @@ class TestNotification(Notification):
117117

118118
@mock.patch("readthedocs.notifications.notification.render_to_string")
119119
def test_message_backend(self, render_to_string):
120-
render_to_string.return_value = 'Test'
120+
render_to_string.return_value = "Test"
121121

122122
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"
126126

127127
build = fixture.get(Build)
128128
user = fixture.get(User)
@@ -140,12 +140,12 @@ class TestNotification(Notification):
140140
@mock.patch("readthedocs.notifications.notification.render_to_string")
141141
def test_message_anonymous_user(self, render_to_string):
142142
"""Anonymous user still throwns exception on persistent messages."""
143-
render_to_string.return_value = 'Test'
143+
render_to_string.return_value = "Test"
144144

145145
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"
149149

150150
build = fixture.get(Build)
151151
user = AnonymousUser()
@@ -163,11 +163,11 @@ class TestNotification(Notification):
163163
self.assertEqual(render_to_string.call_count, 1)
164164
self.assertEqual(PersistentMessage.objects.count(), 0)
165165

166-
@mock.patch('readthedocs.notifications.backends.send_email')
166+
@mock.patch("readthedocs.notifications.backends.send_email")
167167
def test_non_persistent_message(self, send_email):
168168
class TestNotification(SiteNotification):
169-
name = 'foo'
170-
success_message = 'Test success message'
169+
name = "foo"
170+
success_message = "Test success message"
171171
success_level = INFO_NON_PERSISTENT
172172

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

187187
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")
190190
self.assertEqual(PersistentMessage.objects.count(), 1)
191191
self.assertEqual(PersistentMessage.objects.filter(read=True).count(), 1)
192192

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

196196

197197
@override_settings(
198-
PRODUCTION_DOMAIN='readthedocs.org',
199-
SUPPORT_EMAIL='[email protected]',
198+
PRODUCTION_DOMAIN="readthedocs.org",
199+
SUPPORT_EMAIL="[email protected]",
200200
)
201201
class SiteNotificationTests(TestCase):
202-
203202
class TestSiteNotification(SiteNotification):
204-
name = 'foo'
205-
success_message = 'simple success message'
203+
name = "foo"
204+
success_message = "simple success message"
206205
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",
210209
}
211210
success_level = INFO_NON_PERSISTENT
212211
failure_level = WARNING_NON_PERSISTENT
213212

214213
def setUp(self):
215214
self.user = fixture.get(User)
216-
self.context = {'other': {'name': 'other name'}}
215+
self.context = {"other": {"name": "other name"}}
217216
self.n = self.TestSiteNotification(
218217
self.user,
219218
True,
220-
context_object={'name': 'object name'},
219+
context_object={"name": "object name"},
221220
extra_context=self.context,
222221
)
223222

@@ -228,16 +227,17 @@ def test_context_data(self):
228227
"production_uri": "https://readthedocs.org",
229228
"other": {"name": "other name"},
230229
# 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,
241241
}
242242
self.assertEqual(self.n.get_context_data(), context)
243243

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

251251
def test_message(self):
252252
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")
256256

257257
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")
259259
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")
263263

264264
# Invalid reason
265265
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), "")
268268
mock_log.error.assert_called_once()

0 commit comments

Comments
 (0)