Skip to content

Commit

Permalink
tests: fixup url tests in test_privacy_urls
Browse files Browse the repository at this point in the history
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 readthedocs#3957
  • Loading branch information
xrmx committed Apr 18, 2018
1 parent cc390fa commit e72ce29
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions readthedocs/rtd_tests/tests/test_privacy_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def login(self):
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:
Expand All @@ -58,7 +61,7 @@ def assertResponse(self, path, name=None, method=None, data=None, **kwargs):
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)
Expand Down Expand Up @@ -99,6 +102,13 @@ def setUp(self):
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()):
Expand Down Expand Up @@ -232,10 +242,15 @@ 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):
return self.client.login(username='owner', password='test')

Expand All @@ -261,13 +276,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')

Expand Down

0 comments on commit e72ce29

Please sign in to comment.