Skip to content

Commit

Permalink
tests: don't hardcode pip project build id test_privacy_urls
Browse files Browse the repository at this point in the history
Fixes these tests running against postgres
  • Loading branch information
xrmx committed Apr 17, 2018
1 parent 6803769 commit fa39836
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions readthedocs/rtd_tests/tests/test_privacy_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,25 @@ class URLAccessMixin(object):
context_data = []
default_status_code = 200

def get_response_data_url_ctx(self):
return {}

def login(self):
raise NotImplementedError

def is_admin(self):
raise NotImplementedError

def get_response_data(self, path, name):
response_data = self.response_data.get(path, {})
if not response_data:
response_data = self.response_data.get(name, {})
ctx = self.get_response_data_url_ctx()
if ctx:
return {k.format(**ctx): v for k,v in response_data.items()}
else:
return response_data.copy()

def assertResponse(self, path, name=None, method=None, data=None, **kwargs):
self.login()
if method is None:
Expand All @@ -53,9 +66,7 @@ def assertResponse(self, path, name=None, method=None, data=None, **kwargs):
response = method(path, data=data)

# Get response specific test data
response_data = self.response_data.get(path, {}).copy()
if not response_data:
response_data = self.response_data.get(name, {}).copy()
response_data = self.get_response_data(path, name)

response_attrs = {
'status_code': kwargs.pop('status_code', self.default_status_code),
Expand Down Expand Up @@ -232,10 +243,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/{pip_id}/sync/': {'status_code': 405},
'/dashboard/pip/integrations/{pip_id}/delete/': {'status_code': 405},
}

def get_response_data_url_ctx(self):
return {
'pip_id': self.pip.id
}

def login(self):
return self.client.login(username='owner', password='test')

Expand All @@ -261,10 +277,15 @@ 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/{pip_id}/sync/': {'status_code': 405},
'/dashboard/pip/integrations/{pip_id}/delete/': {'status_code': 405},
}

def get_response_data_url_ctx(self):
return {
'pip_id': self.pip.id
}

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

Expand Down

0 comments on commit fa39836

Please sign in to comment.