4
4
from django .urls import reverse
5
5
6
6
from readthedocs .builds .constants import EXTERNAL
7
+ from readthedocs .projects .constants import PRIVATE , PUBLIC
7
8
from readthedocs .subscriptions .constants import TYPE_CONCURRENT_BUILDS
8
9
from readthedocs .subscriptions .products import RTDProductFeature
9
10
@@ -114,27 +115,96 @@ def test_external_version_projects_versions_builds_list_post(self):
114
115
expected ["version" ]["urls" ]["vcs" ] = "https://github.com/rtfd/project/pull/v1.0"
115
116
self .assertDictEqual (response_json , expected )
116
117
117
- def test_projects_builds_notifications_list (self ):
118
+ def test_projects_builds_notifications_list_anonymous_user (self ):
118
119
url = reverse (
119
120
"projects-builds-notifications-list" ,
120
121
kwargs = {
121
122
"parent_lookup_project__slug" : self .project .slug ,
122
123
"parent_lookup_build__id" : self .build .pk ,
123
124
},
124
125
)
126
+ expected_response = self ._get_response_dict (
127
+ "projects-builds-notifications-list"
128
+ )
125
129
126
130
self .client .logout ()
131
+
132
+ # Project and version are public.
127
133
response = self .client .get (url )
128
- self .assertEqual (response .status_code , 401 )
134
+ self .assertEqual (response .status_code , 200 )
135
+ self .assertDictEqual (response .json (), expected_response )
136
+
137
+ # Project is private, version is public.
138
+ self .project .privacy_level = PRIVATE
139
+ self .project .save ()
140
+ self .version .privacy_level = PUBLIC
141
+ self .version .save ()
142
+ response = self .client .get (url )
143
+ self .assertEqual (response .status_code , 404 )
144
+
145
+ # Project and version are private.
146
+ self .project .privacy_level = PRIVATE
147
+ self .project .save ()
148
+ self .version .privacy_level = PRIVATE
149
+ self .version .save ()
150
+ response = self .client .get (url )
151
+ self .assertEqual (response .status_code , 404 )
152
+
153
+ # Project is public, but version is private.
154
+ self .project .privacy_level = PUBLIC
155
+ self .project .save ()
156
+ self .version .privacy_level = PRIVATE
157
+ self .version .save ()
158
+ response = self .client .get (url )
159
+ self .assertEqual (response .status_code , 404 )
160
+
161
+ def test_projects_builds_notifications_list (self ):
162
+ url = reverse (
163
+ "projects-builds-notifications-list" ,
164
+ kwargs = {
165
+ "parent_lookup_project__slug" : self .project .slug ,
166
+ "parent_lookup_build__id" : self .build .pk ,
167
+ },
168
+ )
169
+ expected_response = self ._get_response_dict (
170
+ "projects-builds-notifications-list"
171
+ )
172
+
173
+ self .client .logout ()
129
174
130
175
self .client .credentials (HTTP_AUTHORIZATION = f"Token { self .token .key } " )
131
176
response = self .client .get (url )
177
+
178
+ # Project and version are public.
132
179
self .assertEqual (response .status_code , 200 )
180
+ self .assertDictEqual (response .json (), expected_response )
133
181
134
- self .assertDictEqual (
135
- response .json (),
136
- self ._get_response_dict ("projects-builds-notifications-list" ),
137
- )
182
+ # Project is private, version is public.
183
+ self .project .privacy_level = PRIVATE
184
+ self .project .save ()
185
+ self .version .privacy_level = PUBLIC
186
+ self .version .save ()
187
+ response = self .client .get (url )
188
+ self .assertEqual (response .status_code , 200 )
189
+ self .assertDictEqual (response .json (), expected_response )
190
+
191
+ # Project and version are private.
192
+ self .project .privacy_level = PRIVATE
193
+ self .project .save ()
194
+ self .version .privacy_level = PRIVATE
195
+ self .version .save ()
196
+ response = self .client .get (url )
197
+ self .assertEqual (response .status_code , 200 )
198
+ self .assertDictEqual (response .json (), expected_response )
199
+
200
+ # Project is public, but version is private.
201
+ self .project .privacy_level = PUBLIC
202
+ self .project .save ()
203
+ self .version .privacy_level = PRIVATE
204
+ self .version .save ()
205
+ response = self .client .get (url )
206
+ self .assertEqual (response .status_code , 200 )
207
+ self .assertDictEqual (response .json (), expected_response )
138
208
139
209
def test_projects_builds_notifications_list_other_user (self ):
140
210
url = reverse (
@@ -144,10 +214,40 @@ def test_projects_builds_notifications_list_other_user(self):
144
214
"parent_lookup_build__id" : self .build .pk ,
145
215
},
146
216
)
147
-
217
+ expected_response = self ._get_response_dict (
218
+ "projects-builds-notifications-list"
219
+ )
220
+ self .client .logout ()
148
221
self .client .credentials (HTTP_AUTHORIZATION = f"Token { self .others_token .key } " )
222
+
223
+ # Project and version are public.
224
+ response = self .client .get (url )
225
+ self .assertEqual (response .status_code , 200 )
226
+ self .assertDictEqual (response .json (), expected_response )
227
+
228
+ # Project is private, version is public.
229
+ self .project .privacy_level = PRIVATE
230
+ self .project .save ()
231
+ self .version .privacy_level = PUBLIC
232
+ self .version .save ()
149
233
response = self .client .get (url )
150
- self .assertEqual (response .status_code , 403 )
234
+ self .assertEqual (response .status_code , 404 )
235
+
236
+ # Project and version are private.
237
+ self .project .privacy_level = PRIVATE
238
+ self .project .save ()
239
+ self .version .privacy_level = PRIVATE
240
+ self .version .save ()
241
+ response = self .client .get (url )
242
+ self .assertEqual (response .status_code , 404 )
243
+
244
+ # Project is public, but version is private.
245
+ self .project .privacy_level = PUBLIC
246
+ self .project .save ()
247
+ self .version .privacy_level = PRIVATE
248
+ self .version .save ()
249
+ response = self .client .get (url )
250
+ self .assertEqual (response .status_code , 404 )
151
251
152
252
# User can see their own notifications.
153
253
url = reverse (
@@ -191,6 +291,49 @@ def test_projects_builds_notifications_list_post(self):
191
291
# We don't allow POST on this endpoint
192
292
self .assertEqual (response .status_code , 405 )
193
293
294
+ def test_projects_builds_notifitications_detail_anonymous_user (self ):
295
+ url = reverse (
296
+ "projects-builds-notifications-detail" ,
297
+ kwargs = {
298
+ "parent_lookup_project__slug" : self .project .slug ,
299
+ "parent_lookup_build__id" : self .build .pk ,
300
+ "notification_pk" : self .notification_build .pk ,
301
+ },
302
+ )
303
+ expected_response = self ._get_response_dict (
304
+ "projects-builds-notifications-detail"
305
+ )
306
+ self .client .logout ()
307
+
308
+ # Project and version are public.
309
+ response = self .client .get (url )
310
+ self .assertEqual (response .status_code , 200 )
311
+ self .assertDictEqual (response .json (), expected_response )
312
+
313
+ # Project is private, version is public.
314
+ self .project .privacy_level = PRIVATE
315
+ self .project .save ()
316
+ self .version .privacy_level = PUBLIC
317
+ self .version .save ()
318
+ response = self .client .get (url )
319
+ self .assertEqual (response .status_code , 404 )
320
+
321
+ # Project and version are private.
322
+ self .project .privacy_level = PRIVATE
323
+ self .project .save ()
324
+ self .version .privacy_level = PRIVATE
325
+ self .version .save ()
326
+ response = self .client .get (url )
327
+ self .assertEqual (response .status_code , 404 )
328
+
329
+ # Project is public, but version is private.
330
+ self .project .privacy_level = PUBLIC
331
+ self .project .save ()
332
+ self .version .privacy_level = PRIVATE
333
+ self .version .save ()
334
+ response = self .client .get (url )
335
+ self .assertEqual (response .status_code , 404 )
336
+
194
337
def test_projects_builds_notifitications_detail (self ):
195
338
url = reverse (
196
339
"projects-builds-notifications-detail" ,
@@ -200,19 +343,44 @@ def test_projects_builds_notifitications_detail(self):
200
343
"notification_pk" : self .notification_build .pk ,
201
344
},
202
345
)
346
+ expected_response = self ._get_response_dict (
347
+ "projects-builds-notifications-detail"
348
+ )
203
349
204
350
self .client .logout ()
351
+ self .client .credentials (HTTP_AUTHORIZATION = f"Token { self .token .key } " )
352
+
353
+ # Project and version are public.
205
354
response = self .client .get (url )
206
- self .assertEqual (response .status_code , 401 )
355
+ self .assertEqual (response .status_code , 200 )
356
+ self .assertDictEqual (response .json (), expected_response )
207
357
208
- self .client .credentials (HTTP_AUTHORIZATION = f"Token { self .token .key } " )
358
+ # Project is private, version is public.
359
+ self .project .privacy_level = PRIVATE
360
+ self .project .save ()
361
+ self .version .privacy_level = PUBLIC
362
+ self .version .save ()
209
363
response = self .client .get (url )
210
364
self .assertEqual (response .status_code , 200 )
365
+ self .assertDictEqual (response .json (), expected_response )
211
366
212
- self .assertDictEqual (
213
- response .json (),
214
- self ._get_response_dict ("projects-builds-notifications-detail" ),
215
- )
367
+ # Project and version are private.
368
+ self .project .privacy_level = PRIVATE
369
+ self .project .save ()
370
+ self .version .privacy_level = PRIVATE
371
+ self .version .save ()
372
+ response = self .client .get (url )
373
+ self .assertEqual (response .status_code , 200 )
374
+ self .assertDictEqual (response .json (), expected_response )
375
+
376
+ # Project is public, but version is private.
377
+ self .project .privacy_level = PUBLIC
378
+ self .project .save ()
379
+ self .version .privacy_level = PRIVATE
380
+ self .version .save ()
381
+ response = self .client .get (url )
382
+ self .assertEqual (response .status_code , 200 )
383
+ self .assertDictEqual (response .json (), expected_response )
216
384
217
385
def test_projects_builds_notifitications_detail_other_user (self ):
218
386
url = reverse (
@@ -223,10 +391,40 @@ def test_projects_builds_notifitications_detail_other_user(self):
223
391
"notification_pk" : self .notification_build .pk ,
224
392
},
225
393
)
226
-
394
+ expected_response = self ._get_response_dict (
395
+ "projects-builds-notifications-detail"
396
+ )
397
+ self .client .logout ()
227
398
self .client .credentials (HTTP_AUTHORIZATION = f"Token { self .others_token .key } " )
399
+
400
+ # Project and version are public.
401
+ response = self .client .get (url )
402
+ self .assertEqual (response .status_code , 200 )
403
+ self .assertDictEqual (response .json (), expected_response )
404
+
405
+ # Project is private, version is public.
406
+ self .project .privacy_level = PRIVATE
407
+ self .project .save ()
408
+ self .version .privacy_level = PUBLIC
409
+ self .version .save ()
228
410
response = self .client .get (url )
229
- self .assertEqual (response .status_code , 403 )
411
+ self .assertEqual (response .status_code , 404 )
412
+
413
+ # Project and version are private.
414
+ self .project .privacy_level = PRIVATE
415
+ self .project .save ()
416
+ self .version .privacy_level = PRIVATE
417
+ self .version .save ()
418
+ response = self .client .get (url )
419
+ self .assertEqual (response .status_code , 404 )
420
+
421
+ # Project is public, but version is private.
422
+ self .project .privacy_level = PUBLIC
423
+ self .project .save ()
424
+ self .version .privacy_level = PRIVATE
425
+ self .version .save ()
426
+ response = self .client .get (url )
427
+ self .assertEqual (response .status_code , 404 )
230
428
231
429
def test_projects_builds_notifitications_detail_post (self ):
232
430
url = reverse (
0 commit comments