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
@@ -33,6 +33,9 @@ class URLAccessMixin(object):
def is_admin(self):
raise NotImplementedError
+ def get_url_path_ctx(self):
+ return {}
+
def assertResponse(self, path, name=None, method=None, data=None, **kwargs):
self.login()
if method is None:
@@ -57,7 +60,7 @@ class URLAccessMixin(object):
response_data = self.response_data.get(name, {}).copy()
response_attrs = {
- 'status_code': kwargs.pop('status_code', self.default_status_code),
+ 'status_code': response_data.pop('status_code', self.default_status_code),
}
response_attrs.update(kwargs)
response_attrs.update(response_data)
@@ -98,6 +101,13 @@ class URLAccessMixin(object):
def _test_url(self, urlpatterns):
deconstructed_urls = extract_views_from_urlpatterns(urlpatterns)
added_kwargs = {}
+
+ # we need to format urls with proper ids
+ url_ctx = self.get_url_path_ctx()
+ if url_ctx:
+ self.response_data = {
+ url.format(**url_ctx): data for url, data in self.response_data.items()}
+
for (view, regex, namespace, name) in deconstructed_urls:
request_data = self.request_data.get(name, {}).copy()
for key in list(re.compile(regex).groupindex.keys()):
@@ -231,8 +241,13 @@ class PrivateProjectAdminAccessTest(PrivateProjectMixin, TestCase):
'/dashboard/pip/redirects/delete/': {'status_code': 405},
'/dashboard/pip/subprojects/sub/delete/': {'status_code': 405},
'/dashboard/pip/integrations/sync/': {'status_code': 405},
- '/dashboard/pip/integrations/1/sync/': {'status_code': 405},
- '/dashboard/pip/integrations/1/delete/': {'status_code': 405},
+ '/dashboard/pip/integrations/{integration_id}/sync/': {'status_code': 405},
+ '/dashboard/pip/integrations/{integration_id}/delete/': {'status_code': 405},
+ }
+
+ def get_url_path_ctx(self):
+ return {
+ 'integration_id': self.integration.id,
}
def login(self):
@@ -260,13 +275,18 @@ class PrivateProjectUserAccessTest(PrivateProjectMixin, TestCase):
'/dashboard/pip/redirects/delete/': {'status_code': 405},
'/dashboard/pip/subprojects/sub/delete/': {'status_code': 405},
'/dashboard/pip/integrations/sync/': {'status_code': 405},
- '/dashboard/pip/integrations/1/sync/': {'status_code': 405},
- '/dashboard/pip/integrations/1/delete/': {'status_code': 405},
+ '/dashboard/pip/integrations/{integration_id}/sync/': {'status_code': 405},
+ '/dashboard/pip/integrations/{integration_id}/delete/': {'status_code': 405},
}
# Filtered out by queryset on projects that we don't own.
default_status_code = 404
+ def get_url_path_ctx(self):
+ return {
+ 'integration_id': self.integration.id,
+ }
+
def login(self):
return self.client.login(username='tester', password='test')
