Skip to content

Commit cf829a5

Browse files
committed
tests: fixup url tests in test_privacy_urls
We have two issues. First we were checking always against the default status_code and not the one we expected, second we can't assume that integration id is always 1 but update urls with the current id. Fix #3957
1 parent 4f6123b commit cf829a5

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

readthedocs/rtd_tests/tests/test_privacy_urls.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def login(self):
3434
def is_admin(self):
3535
raise NotImplementedError
3636

37+
def get_url_path_ctx(self):
38+
return {}
39+
3740
def assertResponse(self, path, name=None, method=None, data=None, **kwargs):
3841
self.login()
3942
if method is None:
@@ -58,7 +61,7 @@ def assertResponse(self, path, name=None, method=None, data=None, **kwargs):
5861
response_data = self.response_data.get(name, {}).copy()
5962

6063
response_attrs = {
61-
'status_code': kwargs.pop('status_code', self.default_status_code),
64+
'status_code': response_data.pop('status_code', self.default_status_code),
6265
}
6366
response_attrs.update(kwargs)
6467
response_attrs.update(response_data)
@@ -99,6 +102,13 @@ def setUp(self):
99102
def _test_url(self, urlpatterns):
100103
deconstructed_urls = extract_views_from_urlpatterns(urlpatterns)
101104
added_kwargs = {}
105+
106+
# we need to format urls with proper ids
107+
url_ctx = self.get_url_path_ctx()
108+
if url_ctx:
109+
self.response_data = {
110+
url.format(**url_ctx): data for url, data in self.response_data.items()}
111+
102112
for (view, regex, namespace, name) in deconstructed_urls:
103113
request_data = self.request_data.get(name, {}).copy()
104114
for key in list(re.compile(regex).groupindex.keys()):
@@ -232,10 +242,15 @@ class PrivateProjectAdminAccessTest(PrivateProjectMixin, TestCase):
232242
'/dashboard/pip/redirects/delete/': {'status_code': 405},
233243
'/dashboard/pip/subprojects/sub/delete/': {'status_code': 405},
234244
'/dashboard/pip/integrations/sync/': {'status_code': 405},
235-
'/dashboard/pip/integrations/1/sync/': {'status_code': 405},
236-
'/dashboard/pip/integrations/1/delete/': {'status_code': 405},
245+
'/dashboard/pip/integrations/{integration_id}/sync/': {'status_code': 405},
246+
'/dashboard/pip/integrations/{integration_id}/delete/': {'status_code': 405},
237247
}
238248

249+
def get_url_path_ctx(self):
250+
return {
251+
'integration_id': self.integration.id,
252+
}
253+
239254
def login(self):
240255
return self.client.login(username='owner', password='test')
241256

@@ -261,13 +276,18 @@ class PrivateProjectUserAccessTest(PrivateProjectMixin, TestCase):
261276
'/dashboard/pip/redirects/delete/': {'status_code': 405},
262277
'/dashboard/pip/subprojects/sub/delete/': {'status_code': 405},
263278
'/dashboard/pip/integrations/sync/': {'status_code': 405},
264-
'/dashboard/pip/integrations/1/sync/': {'status_code': 405},
265-
'/dashboard/pip/integrations/1/delete/': {'status_code': 405},
279+
'/dashboard/pip/integrations/{integration_id}/sync/': {'status_code': 405},
280+
'/dashboard/pip/integrations/{integration_id}/delete/': {'status_code': 405},
266281
}
267282

268283
# Filtered out by queryset on projects that we don't own.
269284
default_status_code = 404
270285

286+
def get_url_path_ctx(self):
287+
return {
288+
'integration_id': self.integration.id,
289+
}
290+
271291
def login(self):
272292
return self.client.login(username='tester', password='test')
273293

0 commit comments

Comments
 (0)