Skip to content

Commit e393011

Browse files
authored
Merge pull request #3966 from italia/fixuppgtests
tests: fixup url tests in test_privacy_urls
2 parents b10c493 + a58999d commit e393011

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

readthedocs/rtd_tests/tests/test_privacy_urls.py

+25-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ def login(self):
3333
def is_admin(self):
3434
raise NotImplementedError
3535

36+
def get_url_path_ctx(self):
37+
return {}
38+
3639
def assertResponse(self, path, name=None, method=None, data=None, **kwargs):
3740
self.login()
3841
if method is None:
@@ -57,7 +60,7 @@ def assertResponse(self, path, name=None, method=None, data=None, **kwargs):
5760
response_data = self.response_data.get(name, {}).copy()
5861

5962
response_attrs = {
60-
'status_code': kwargs.pop('status_code', self.default_status_code),
63+
'status_code': response_data.pop('status_code', self.default_status_code),
6164
}
6265
response_attrs.update(kwargs)
6366
response_attrs.update(response_data)
@@ -98,6 +101,13 @@ def setUp(self):
98101
def _test_url(self, urlpatterns):
99102
deconstructed_urls = extract_views_from_urlpatterns(urlpatterns)
100103
added_kwargs = {}
104+
105+
# we need to format urls with proper ids
106+
url_ctx = self.get_url_path_ctx()
107+
if url_ctx:
108+
self.response_data = {
109+
url.format(**url_ctx): data for url, data in self.response_data.items()}
110+
101111
for (view, regex, namespace, name) in deconstructed_urls:
102112
request_data = self.request_data.get(name, {}).copy()
103113
for key in list(re.compile(regex).groupindex.keys()):
@@ -231,10 +241,15 @@ class PrivateProjectAdminAccessTest(PrivateProjectMixin, TestCase):
231241
'/dashboard/pip/redirects/delete/': {'status_code': 405},
232242
'/dashboard/pip/subprojects/sub/delete/': {'status_code': 405},
233243
'/dashboard/pip/integrations/sync/': {'status_code': 405},
234-
'/dashboard/pip/integrations/1/sync/': {'status_code': 405},
235-
'/dashboard/pip/integrations/1/delete/': {'status_code': 405},
244+
'/dashboard/pip/integrations/{integration_id}/sync/': {'status_code': 405},
245+
'/dashboard/pip/integrations/{integration_id}/delete/': {'status_code': 405},
236246
}
237247

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

@@ -260,13 +275,18 @@ class PrivateProjectUserAccessTest(PrivateProjectMixin, TestCase):
260275
'/dashboard/pip/redirects/delete/': {'status_code': 405},
261276
'/dashboard/pip/subprojects/sub/delete/': {'status_code': 405},
262277
'/dashboard/pip/integrations/sync/': {'status_code': 405},
263-
'/dashboard/pip/integrations/1/sync/': {'status_code': 405},
264-
'/dashboard/pip/integrations/1/delete/': {'status_code': 405},
278+
'/dashboard/pip/integrations/{integration_id}/sync/': {'status_code': 405},
279+
'/dashboard/pip/integrations/{integration_id}/delete/': {'status_code': 405},
265280
}
266281

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

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

0 commit comments

Comments
 (0)