Refactor the tests to be less ugly.
This commit is contained in:
parent
ff7cd2f0a5
commit
161a6284f0
4 changed files with 201 additions and 465 deletions
|
@ -140,6 +140,8 @@ class TestConfig(FlaskConfig, FakeStorage, EphemeralDB, FakeUserfiles,
|
||||||
'format': LOG_FORMAT
|
'format': LOG_FORMAT
|
||||||
}
|
}
|
||||||
POPULATE_DB_TEST_DATA = True
|
POPULATE_DB_TEST_DATA = True
|
||||||
|
TESTING = True
|
||||||
|
INCLUDE_TEST_ENDPOINTS = True
|
||||||
|
|
||||||
|
|
||||||
class DebugConfig(FlaskConfig, MailConfig, LocalStorage, SQLiteDB,
|
class DebugConfig(FlaskConfig, MailConfig, LocalStorage, SQLiteDB,
|
||||||
|
|
707
test/specs.py
707
test/specs.py
|
@ -28,514 +28,231 @@ NEW_ORG_REPO_DETAILS = {
|
||||||
'namespace': ORG,
|
'namespace': ORG,
|
||||||
}
|
}
|
||||||
|
|
||||||
class hashabledict(dict):
|
NEW_USER_DETAILS = {
|
||||||
def __hash__(self):
|
'username': 'bob',
|
||||||
return hash(tuple(sorted(self.items())))
|
'password': 'password',
|
||||||
|
'email': 'jake@devtable.com',
|
||||||
|
}
|
||||||
|
|
||||||
|
SEND_RECOVERY_DETAILS = {
|
||||||
|
'email': 'jacob.moshenko@gmail.com',
|
||||||
|
}
|
||||||
|
|
||||||
def open_kwargs(method='GET', json_object=None):
|
SIGNIN_DETAILS = {
|
||||||
kwargs = hashabledict([
|
'username': 'devtable',
|
||||||
('method', method),
|
'password': 'password',
|
||||||
])
|
}
|
||||||
|
|
||||||
if json_object is not None:
|
FILE_DROP_DETAILS = {
|
||||||
kwargs['data'] = json.dumps(json_object)
|
'mimeType': 'application/zip',
|
||||||
kwargs['content_type'] = 'application/json'
|
}
|
||||||
|
|
||||||
elif method == 'POST' or method == 'PUT':
|
CHANGE_PERMISSION_DETAILS = {
|
||||||
kwargs['data'] = json.dumps({
|
'role': 'admin',
|
||||||
'fake': 'json',
|
}
|
||||||
'data': 'here',
|
|
||||||
})
|
|
||||||
kwargs['content_type'] = 'application/json'
|
|
||||||
|
|
||||||
return kwargs
|
CREATE_BUILD_DETAILS = {
|
||||||
|
'file_id': str(uuid4()),
|
||||||
|
}
|
||||||
|
|
||||||
|
CHANGE_VISIBILITY_DETAILS = {
|
||||||
|
'visibility': 'public',
|
||||||
|
}
|
||||||
|
|
||||||
def build_anon_spec():
|
CREATE_TOKEN_DETAILS = {
|
||||||
return OrderedDict([
|
'friendlyName': 'A new token',
|
||||||
((url_for('welcome'), open_kwargs()), 200),
|
}
|
||||||
|
|
||||||
((url_for('plans_list'), open_kwargs()), 200),
|
UPDATE_REPO_DETAILS = {
|
||||||
|
'description': 'A new description',
|
||||||
|
}
|
||||||
|
|
||||||
((url_for('get_logged_in_user'), open_kwargs()), 200),
|
|
||||||
|
|
||||||
((url_for('change_user_details'), open_kwargs('PUT')), 401),
|
class TestSpec(object):
|
||||||
|
def __init__(self, url, anon_code=401, no_access_code=403, read_code=403,
|
||||||
|
admin_code=200):
|
||||||
|
self._url = url
|
||||||
|
self._data = None
|
||||||
|
self._method = 'GET'
|
||||||
|
|
||||||
((url_for('create_user_api'), open_kwargs('POST')), 400),
|
self.anon_code = anon_code
|
||||||
|
self.no_access_code = no_access_code
|
||||||
|
self.read_code = read_code
|
||||||
|
self.admin_code = admin_code
|
||||||
|
|
||||||
((url_for('signin_api'), open_kwargs('POST')), 400),
|
def set_data_from_obj(self, json_serializable):
|
||||||
|
self._data = json.dumps(json_serializable)
|
||||||
|
return self
|
||||||
|
|
||||||
((url_for('send_recovery'), open_kwargs('POST')), 400),
|
def set_method(self, method):
|
||||||
|
self._method = method
|
||||||
|
return self
|
||||||
|
|
||||||
((url_for('get_matching_users', prefix='dev'), open_kwargs()), 401),
|
def get_client_args(self):
|
||||||
|
kwargs = {
|
||||||
|
'method': self._method
|
||||||
|
}
|
||||||
|
|
||||||
((url_for('get_matching_entities', prefix='dev'), open_kwargs()), 401),
|
if self._data or self._method == 'POST' or self._method == 'PUT':
|
||||||
|
kwargs['data'] = self._data if self._data else '{}'
|
||||||
((url_for('get_organization', orgname=ORG), open_kwargs()), 401),
|
kwargs['content_type'] = 'application/json'
|
||||||
|
|
||||||
((url_for('get_organization_private_allowed', orgname=ORG),
|
return self._url, kwargs
|
||||||
open_kwargs()), 401),
|
|
||||||
|
|
||||||
((url_for('update_organization_team', orgname=ORG, teamname=ORG_OWNERS),
|
def build_specs():
|
||||||
open_kwargs('PUT')), 401),
|
return [
|
||||||
((url_for('update_organization_team', orgname=ORG, teamname=ORG_READERS),
|
TestSpec(url_for('welcome'), 200, 200, 200, 200),
|
||||||
open_kwargs('PUT')), 401),
|
|
||||||
|
TestSpec(url_for('plans_list'), 200, 200, 200, 200),
|
||||||
((url_for('delete_organization_team', orgname=ORG, teamname=ORG_OWNERS),
|
|
||||||
open_kwargs('DELETE')), 401),
|
TestSpec(url_for('get_logged_in_user'), 200, 200, 200, 200),
|
||||||
((url_for('delete_organization_team', orgname=ORG, teamname=ORG_READERS),
|
|
||||||
open_kwargs('DELETE')), 401),
|
TestSpec(url_for('change_user_details'), 401, 200, 200, 200).set_method('PUT'),
|
||||||
|
|
||||||
((url_for('get_organization_team_members', orgname=ORG,
|
TestSpec(url_for('create_user_api'), 201, 201, 201, 201).set_method('POST').set_data_from_obj(NEW_USER_DETAILS),
|
||||||
teamname=ORG_OWNERS), open_kwargs()), 401),
|
|
||||||
((url_for('get_organization_team_members', orgname=ORG,
|
TestSpec(url_for('signin_api'), 200, 200, 200, 200).set_method('POST').set_data_from_obj(SIGNIN_DETAILS),
|
||||||
teamname=ORG_READERS), open_kwargs()), 401),
|
|
||||||
|
TestSpec(url_for('send_recovery'), 201, 201, 201, 201).set_method('POST').set_data_from_obj(SEND_RECOVERY_DETAILS),
|
||||||
((url_for('update_organization_team_member', orgname=ORG,
|
|
||||||
teamname=ORG_OWNERS, membername=ORG_OWNER),
|
TestSpec(url_for('get_matching_users', prefix='dev'), 401, 200, 200, 200),
|
||||||
open_kwargs('PUT')), 401),
|
|
||||||
((url_for('update_organization_team_member', orgname=ORG,
|
TestSpec(url_for('get_matching_entities', prefix='dev'), 401, 200, 200, 200),
|
||||||
teamname=ORG_READERS, membername=ORG_OWNER),
|
|
||||||
open_kwargs('PUT')), 401),
|
TestSpec(url_for('get_organization', orgname=ORG), 401, 403, 200, 200),
|
||||||
|
|
||||||
((url_for('delete_organization_team_member', orgname=ORG,
|
TestSpec(url_for('get_organization_private_allowed', orgname=ORG)),
|
||||||
teamname=ORG_OWNERS, membername=ORG_OWNER),
|
|
||||||
open_kwargs('DELETE')), 401),
|
TestSpec(url_for('update_organization_team', orgname=ORG, teamname=ORG_OWNERS)).set_method('PUT'),
|
||||||
((url_for('delete_organization_team_member', orgname=ORG,
|
TestSpec(url_for('update_organization_team', orgname=ORG, teamname=ORG_READERS)).set_method('PUT'),
|
||||||
teamname=ORG_READERS, membername=ORG_OWNER),
|
|
||||||
open_kwargs('DELETE')), 401),
|
TestSpec(url_for('delete_organization_team', orgname=ORG, teamname=ORG_OWNERS), admin_code=400).set_method('DELETE'),
|
||||||
|
TestSpec(url_for('delete_organization_team', orgname=ORG, teamname=ORG_READERS), admin_code=204).set_method('DELETE'),
|
||||||
((url_for('create_repo_api'), open_kwargs('POST', NEW_ORG_REPO_DETAILS)),
|
|
||||||
401),
|
TestSpec(url_for('get_organization_team_members', orgname=ORG, teamname=ORG_OWNERS)),
|
||||||
|
TestSpec(url_for('get_organization_team_members', orgname=ORG, teamname=ORG_READERS), read_code=200),
|
||||||
((url_for('match_repos_api'), open_kwargs()), 200),
|
|
||||||
|
TestSpec(url_for('update_organization_team_member', orgname=ORG, teamname=ORG_OWNERS, membername=ORG_OWNER), admin_code=400).set_method('PUT'),
|
||||||
((url_for('list_repos_api'), open_kwargs()), 200),
|
TestSpec(url_for('update_organization_team_member', orgname=ORG, teamname=ORG_READERS, membername=ORG_OWNER)).set_method('PUT'),
|
||||||
|
|
||||||
((url_for('update_repo_api', repository=PUBLIC_REPO), open_kwargs('PUT')),
|
TestSpec(url_for('delete_organization_team_member', orgname=ORG, teamname=ORG_OWNERS, membername=ORG_OWNER), admin_code=400).set_method('DELETE'),
|
||||||
401),
|
TestSpec(url_for('delete_organization_team_member', orgname=ORG, teamname=ORG_READERS, membername=ORG_OWNER), admin_code=400).set_method('DELETE'),
|
||||||
((url_for('update_repo_api', repository=ORG_REPO), open_kwargs('PUT')),
|
|
||||||
401),
|
TestSpec(url_for('create_repo_api')).set_method('POST').set_data_from_obj(NEW_ORG_REPO_DETAILS),
|
||||||
((url_for('update_repo_api', repository=PRIVATE_REPO),
|
|
||||||
open_kwargs('PUT')), 401),
|
TestSpec(url_for('match_repos_api'), 200, 200, 200, 200),
|
||||||
|
|
||||||
((url_for('change_repo_visibility_api', repository=PUBLIC_REPO),
|
TestSpec(url_for('list_repos_api'), 200, 200, 200, 200),
|
||||||
open_kwargs('POST')), 401),
|
|
||||||
((url_for('change_repo_visibility_api', repository=ORG_REPO),
|
TestSpec(url_for('update_repo_api', repository=PUBLIC_REPO), admin_code=403).set_method('PUT'),
|
||||||
open_kwargs('POST')), 401),
|
TestSpec(url_for('update_repo_api', repository=ORG_REPO)).set_method('PUT').set_data_from_obj(UPDATE_REPO_DETAILS),
|
||||||
((url_for('change_repo_visibility_api', repository=PRIVATE_REPO),
|
TestSpec(url_for('update_repo_api', repository=PRIVATE_REPO)).set_method('PUT').set_data_from_obj(UPDATE_REPO_DETAILS),
|
||||||
open_kwargs('POST')), 401),
|
|
||||||
|
TestSpec(url_for('change_repo_visibility_api', repository=PUBLIC_REPO), admin_code=403).set_method('POST').set_data_from_obj(CHANGE_VISIBILITY_DETAILS),
|
||||||
((url_for('delete_repository', repository=PUBLIC_REPO),
|
TestSpec(url_for('change_repo_visibility_api', repository=ORG_REPO)).set_method('POST').set_data_from_obj(CHANGE_VISIBILITY_DETAILS),
|
||||||
open_kwargs('DELETE')), 401),
|
TestSpec(url_for('change_repo_visibility_api', repository=PRIVATE_REPO)).set_method('POST').set_data_from_obj(CHANGE_VISIBILITY_DETAILS),
|
||||||
((url_for('delete_repository', repository=ORG_REPO),
|
|
||||||
open_kwargs('DELETE')), 401),
|
TestSpec(url_for('delete_repository', repository=PUBLIC_REPO), admin_code=403).set_method('DELETE'),
|
||||||
((url_for('delete_repository', repository=PRIVATE_REPO),
|
TestSpec(url_for('delete_repository', repository=ORG_REPO), admin_code=204).set_method('DELETE'),
|
||||||
open_kwargs('DELETE')), 401),
|
TestSpec(url_for('delete_repository', repository=PRIVATE_REPO), admin_code=204).set_method('DELETE'),
|
||||||
|
|
||||||
((url_for('get_repo_api', repository=PUBLIC_REPO), open_kwargs()), 200),
|
TestSpec(url_for('get_repo_api', repository=PUBLIC_REPO), 200, 200, 200, 200),
|
||||||
((url_for('get_repo_api', repository=ORG_REPO), open_kwargs()), 403),
|
TestSpec(url_for('get_repo_api', repository=ORG_REPO), 403, 403, 200, 200),
|
||||||
((url_for('get_repo_api', repository=PRIVATE_REPO), open_kwargs()), 403),
|
TestSpec(url_for('get_repo_api', repository=PRIVATE_REPO), 403, 403, 200, 200),
|
||||||
|
|
||||||
((url_for('get_repo_builds', repository=PUBLIC_REPO), open_kwargs()),
|
TestSpec(url_for('get_repo_builds', repository=PUBLIC_REPO), admin_code=403),
|
||||||
401),
|
TestSpec(url_for('get_repo_builds', repository=ORG_REPO)),
|
||||||
((url_for('get_repo_builds', repository=ORG_REPO), open_kwargs()), 401),
|
TestSpec(url_for('get_repo_builds', repository=PRIVATE_REPO)),
|
||||||
((url_for('get_repo_builds', repository=PRIVATE_REPO), open_kwargs()),
|
|
||||||
401),
|
TestSpec(url_for('get_filedrop_url'), 401, 200, 200, 200).set_method('POST').set_data_from_obj(FILE_DROP_DETAILS),
|
||||||
|
|
||||||
((url_for('get_filedrop_url'), open_kwargs('POST')), 401),
|
TestSpec(url_for('request_repo_build', repository=PUBLIC_REPO), admin_code=403).set_method('POST').set_data_from_obj(CREATE_BUILD_DETAILS),
|
||||||
|
TestSpec(url_for('request_repo_build', repository=ORG_REPO), admin_code=201).set_method('POST').set_data_from_obj(CREATE_BUILD_DETAILS),
|
||||||
((url_for('request_repo_build', repository=PUBLIC_REPO),
|
TestSpec(url_for('request_repo_build', repository=PRIVATE_REPO), admin_code=201).set_method('POST').set_data_from_obj(CREATE_BUILD_DETAILS),
|
||||||
open_kwargs('POST')), 401),
|
|
||||||
((url_for('request_repo_build', repository=ORG_REPO),
|
TestSpec(url_for('list_repository_images', repository=PUBLIC_REPO), 200, 200, 200, 200),
|
||||||
open_kwargs('POST')), 401),
|
TestSpec(url_for('list_repository_images', repository=ORG_REPO), 403, 403, 200, 200),
|
||||||
((url_for('request_repo_build', repository=PRIVATE_REPO),
|
TestSpec(url_for('list_repository_images', repository=PRIVATE_REPO), 403, 403, 200, 200),
|
||||||
open_kwargs('POST')), 401),
|
|
||||||
|
TestSpec(url_for('get_image', repository=PUBLIC_REPO, image_id=FAKE_IMAGE_ID), 404, 404, 404, 404),
|
||||||
((url_for('list_repository_images', repository=PUBLIC_REPO),
|
TestSpec(url_for('get_image', repository=ORG_REPO, image_id=FAKE_IMAGE_ID), 403, 403, 404, 404),
|
||||||
open_kwargs()), 200),
|
TestSpec(url_for('get_image', repository=PRIVATE_REPO, image_id=FAKE_IMAGE_ID), 403, 403, 404, 404),
|
||||||
((url_for('list_repository_images', repository=ORG_REPO),
|
|
||||||
open_kwargs()), 403),
|
TestSpec(url_for('get_image_changes', repository=PUBLIC_REPO, image_id=FAKE_IMAGE_ID), 404, 404, 404, 404),
|
||||||
((url_for('list_repository_images', repository=PRIVATE_REPO),
|
TestSpec(url_for('get_image_changes', repository=ORG_REPO, image_id=FAKE_IMAGE_ID), 403, 403, 404, 404),
|
||||||
open_kwargs()), 403),
|
TestSpec(url_for('get_image_changes', repository=PRIVATE_REPO, image_id=FAKE_IMAGE_ID), 403, 403, 404, 404),
|
||||||
|
|
||||||
((url_for('get_image', repository=PUBLIC_REPO, image_id=FAKE_IMAGE_ID),
|
TestSpec(url_for('list_tag_images', repository=PUBLIC_REPO, tag=FAKE_TAG_NAME), 404, 404, 404, 404),
|
||||||
open_kwargs()), 404),
|
TestSpec(url_for('list_tag_images', repository=ORG_REPO, tag=FAKE_TAG_NAME), 403, 403, 404, 404),
|
||||||
((url_for('get_image', repository=ORG_REPO, image_id=FAKE_IMAGE_ID),
|
TestSpec(url_for('list_tag_images', repository=PRIVATE_REPO, tag=FAKE_TAG_NAME), 403, 403, 404, 404),
|
||||||
open_kwargs()), 403),
|
|
||||||
((url_for('get_image', repository=PRIVATE_REPO, image_id=FAKE_IMAGE_ID),
|
TestSpec(url_for('list_repo_team_permissions', repository=PUBLIC_REPO), admin_code=403),
|
||||||
open_kwargs()), 403),
|
TestSpec(url_for('list_repo_team_permissions', repository=ORG_REPO)),
|
||||||
|
TestSpec(url_for('list_repo_team_permissions', repository=PRIVATE_REPO)),
|
||||||
((url_for('get_image_changes', repository=PUBLIC_REPO,
|
|
||||||
image_id=FAKE_IMAGE_ID), open_kwargs()), 404),
|
TestSpec(url_for('list_repo_user_permissions', repository=PUBLIC_REPO), admin_code=403),
|
||||||
((url_for('get_image_changes', repository=ORG_REPO,
|
TestSpec(url_for('list_repo_user_permissions', repository=ORG_REPO)),
|
||||||
image_id=FAKE_IMAGE_ID), open_kwargs()), 403),
|
TestSpec(url_for('list_repo_user_permissions', repository=PRIVATE_REPO)),
|
||||||
((url_for('get_image_changes', repository=PRIVATE_REPO,
|
|
||||||
image_id=FAKE_IMAGE_ID), open_kwargs()), 403),
|
TestSpec(url_for('get_user_permissions', repository=PUBLIC_REPO, username=FAKE_USERNAME), admin_code=403),
|
||||||
|
TestSpec(url_for('get_user_permissions', repository=ORG_REPO, username=FAKE_USERNAME), admin_code=400),
|
||||||
((url_for('list_tag_images', repository=PUBLIC_REPO, tag=FAKE_TAG_NAME),
|
TestSpec(url_for('get_user_permissions', repository=PRIVATE_REPO, username=FAKE_USERNAME), admin_code=400),
|
||||||
open_kwargs()), 404),
|
|
||||||
((url_for('list_tag_images', repository=ORG_REPO, tag=FAKE_TAG_NAME),
|
TestSpec(url_for('get_team_permissions', repository=PUBLIC_REPO, teamname=ORG_OWNERS), admin_code=403),
|
||||||
open_kwargs()), 403),
|
TestSpec(url_for('get_team_permissions', repository=PUBLIC_REPO, teamname=ORG_READERS), admin_code=403),
|
||||||
((url_for('list_tag_images', repository=PRIVATE_REPO, tag=FAKE_TAG_NAME),
|
TestSpec(url_for('get_team_permissions', repository=ORG_REPO, teamname=ORG_OWNERS), admin_code=400),
|
||||||
open_kwargs()), 403),
|
TestSpec(url_for('get_team_permissions', repository=ORG_REPO, teamname=ORG_READERS)),
|
||||||
|
TestSpec(url_for('get_team_permissions', repository=PRIVATE_REPO, teamname=ORG_OWNERS), admin_code=400),
|
||||||
((url_for('list_repo_team_permissions', repository=PUBLIC_REPO),
|
TestSpec(url_for('get_team_permissions', repository=PRIVATE_REPO, teamname=ORG_READERS), admin_code=400),
|
||||||
open_kwargs()), 401),
|
|
||||||
((url_for('list_repo_team_permissions', repository=ORG_REPO),
|
TestSpec(url_for('change_user_permissions', repository=PUBLIC_REPO, username=FAKE_USERNAME), admin_code=403).set_method('PUT'),
|
||||||
open_kwargs()), 401),
|
TestSpec(url_for('change_user_permissions', repository=ORG_REPO, username=FAKE_USERNAME), admin_code=400).set_method('PUT'),
|
||||||
((url_for('list_repo_team_permissions', repository=PRIVATE_REPO),
|
TestSpec(url_for('change_user_permissions', repository=PRIVATE_REPO, username=FAKE_USERNAME), admin_code=400).set_method('PUT'),
|
||||||
open_kwargs()), 401),
|
|
||||||
|
TestSpec(url_for('change_team_permissions', repository=PUBLIC_REPO, teamname=ORG_OWNERS), admin_code=403).set_method('PUT').set_data_from_obj(CHANGE_PERMISSION_DETAILS),
|
||||||
((url_for('list_repo_user_permissions', repository=PUBLIC_REPO),
|
TestSpec(url_for('change_team_permissions', repository=PUBLIC_REPO, teamname=ORG_READERS), admin_code=403).set_method('PUT').set_data_from_obj(CHANGE_PERMISSION_DETAILS),
|
||||||
open_kwargs()), 401),
|
TestSpec(url_for('change_team_permissions', repository=ORG_REPO, teamname=ORG_OWNERS)).set_method('PUT').set_data_from_obj(CHANGE_PERMISSION_DETAILS),
|
||||||
((url_for('list_repo_user_permissions', repository=ORG_REPO),
|
TestSpec(url_for('change_team_permissions', repository=ORG_REPO, teamname=ORG_READERS)).set_method('PUT').set_data_from_obj(CHANGE_PERMISSION_DETAILS),
|
||||||
open_kwargs()), 401),
|
TestSpec(url_for('change_team_permissions', repository=PRIVATE_REPO, teamname=ORG_OWNERS), admin_code=400).set_method('PUT').set_data_from_obj(CHANGE_PERMISSION_DETAILS),
|
||||||
((url_for('list_repo_user_permissions', repository=PRIVATE_REPO),
|
TestSpec(url_for('change_team_permissions', repository=PRIVATE_REPO, teamname=ORG_READERS), admin_code=400).set_method('PUT').set_data_from_obj(CHANGE_PERMISSION_DETAILS),
|
||||||
open_kwargs()), 401),
|
|
||||||
|
TestSpec(url_for('delete_user_permissions', repository=PUBLIC_REPO, username=FAKE_USERNAME), admin_code=403).set_method('DELETE'),
|
||||||
((url_for('get_user_permissions', repository=PUBLIC_REPO,
|
TestSpec(url_for('delete_user_permissions', repository=ORG_REPO, username=FAKE_USERNAME), admin_code=400).set_method('DELETE'),
|
||||||
username=FAKE_USERNAME), open_kwargs()), 401),
|
TestSpec(url_for('delete_user_permissions', repository=PRIVATE_REPO, username=FAKE_USERNAME), admin_code=400).set_method('DELETE'),
|
||||||
((url_for('get_user_permissions', repository=ORG_REPO,
|
|
||||||
username=FAKE_USERNAME), open_kwargs()), 401),
|
TestSpec(url_for('delete_team_permissions', repository=PUBLIC_REPO, teamname=ORG_OWNERS), admin_code=403).set_method('DELETE'),
|
||||||
((url_for('get_user_permissions', repository=PRIVATE_REPO,
|
TestSpec(url_for('delete_team_permissions', repository=PUBLIC_REPO, teamname=ORG_READERS), admin_code=403).set_method('DELETE'),
|
||||||
username=FAKE_USERNAME), open_kwargs()), 401),
|
TestSpec(url_for('delete_team_permissions', repository=ORG_REPO, teamname=ORG_OWNERS), admin_code=400).set_method('DELETE'),
|
||||||
|
TestSpec(url_for('delete_team_permissions', repository=ORG_REPO, teamname=ORG_READERS), admin_code=204).set_method('DELETE'),
|
||||||
((url_for('get_team_permissions', repository=PUBLIC_REPO,
|
TestSpec(url_for('delete_team_permissions', repository=PRIVATE_REPO, teamname=ORG_OWNERS), admin_code=400).set_method('DELETE'),
|
||||||
teamname=ORG_OWNERS), open_kwargs()), 401),
|
TestSpec(url_for('delete_team_permissions', repository=PRIVATE_REPO, teamname=ORG_READERS), admin_code=400).set_method('DELETE'),
|
||||||
((url_for('get_team_permissions', repository=PUBLIC_REPO,
|
|
||||||
teamname=ORG_READERS), open_kwargs()), 401),
|
TestSpec(url_for('list_repo_tokens', repository=PUBLIC_REPO), admin_code=403),
|
||||||
((url_for('get_team_permissions', repository=ORG_REPO,
|
TestSpec(url_for('list_repo_tokens', repository=ORG_REPO)),
|
||||||
teamname=ORG_OWNERS), open_kwargs()), 401),
|
TestSpec(url_for('list_repo_tokens', repository=PRIVATE_REPO)),
|
||||||
((url_for('get_team_permissions', repository=ORG_REPO,
|
|
||||||
teamname=ORG_READERS), open_kwargs()), 401),
|
TestSpec(url_for('get_tokens', repository=PUBLIC_REPO, code=FAKE_TOKEN), admin_code=403),
|
||||||
((url_for('get_team_permissions', repository=PRIVATE_REPO,
|
TestSpec(url_for('get_tokens', repository=ORG_REPO, code=FAKE_TOKEN), admin_code=400),
|
||||||
teamname=ORG_OWNERS), open_kwargs()), 401),
|
TestSpec(url_for('get_tokens', repository=PRIVATE_REPO, code=FAKE_TOKEN), admin_code=400),
|
||||||
((url_for('get_team_permissions', repository=PRIVATE_REPO,
|
|
||||||
teamname=ORG_READERS), open_kwargs()), 401),
|
TestSpec(url_for('create_token', repository=PUBLIC_REPO), admin_code=403).set_method('POST'),
|
||||||
|
TestSpec(url_for('create_token', repository=ORG_REPO), admin_code=201).set_method('POST').set_data_from_obj(CREATE_TOKEN_DETAILS),
|
||||||
((url_for('change_user_permissions', repository=PUBLIC_REPO,
|
TestSpec(url_for('create_token', repository=PRIVATE_REPO), admin_code=201).set_method('POST').set_data_from_obj(CREATE_TOKEN_DETAILS),
|
||||||
username=FAKE_USERNAME), open_kwargs('PUT')), 401),
|
|
||||||
((url_for('change_user_permissions', repository=ORG_REPO,
|
TestSpec(url_for('change_token', repository=PUBLIC_REPO, code=FAKE_TOKEN), admin_code=403).set_method('PUT'),
|
||||||
username=FAKE_USERNAME), open_kwargs('PUT')), 401),
|
TestSpec(url_for('change_token', repository=ORG_REPO, code=FAKE_TOKEN), admin_code=400).set_method('PUT'),
|
||||||
((url_for('change_user_permissions', repository=PRIVATE_REPO,
|
TestSpec(url_for('change_token', repository=PRIVATE_REPO, code=FAKE_TOKEN), admin_code=400).set_method('PUT'),
|
||||||
username=FAKE_USERNAME), open_kwargs('PUT')), 401),
|
|
||||||
|
TestSpec(url_for('delete_token', repository=PUBLIC_REPO, code=FAKE_TOKEN), admin_code=403).set_method('DELETE'),
|
||||||
((url_for('change_team_permissions', repository=PUBLIC_REPO,
|
TestSpec(url_for('delete_token', repository=ORG_REPO, code=FAKE_TOKEN), admin_code=400).set_method('DELETE'),
|
||||||
teamname=ORG_OWNERS), open_kwargs('PUT')), 401),
|
TestSpec(url_for('delete_token', repository=PRIVATE_REPO, code=FAKE_TOKEN), admin_code=400).set_method('DELETE'),
|
||||||
((url_for('change_team_permissions', repository=PUBLIC_REPO,
|
|
||||||
teamname=ORG_READERS), open_kwargs('PUT')), 401),
|
TestSpec(url_for('subscribe_api'), 401, 400, 400, 400).set_method('PUT'),
|
||||||
((url_for('change_team_permissions', repository=ORG_REPO,
|
|
||||||
teamname=ORG_OWNERS), open_kwargs('PUT')), 401),
|
TestSpec(url_for('subscribe_org_api', orgname=ORG), 401, 403, 403, 400).set_method('PUT'),
|
||||||
((url_for('change_team_permissions', repository=ORG_REPO,
|
|
||||||
teamname=ORG_READERS), open_kwargs('PUT')), 401),
|
TestSpec(url_for('get_subscription'), 401, 200, 200, 200),
|
||||||
((url_for('change_team_permissions', repository=PRIVATE_REPO,
|
|
||||||
teamname=ORG_OWNERS), open_kwargs('PUT')), 401),
|
TestSpec(url_for('get_org_subscription', orgname=ORG)),
|
||||||
((url_for('change_team_permissions', repository=PRIVATE_REPO,
|
]
|
||||||
teamname=ORG_READERS), open_kwargs('PUT')), 401),
|
|
||||||
|
|
||||||
((url_for('delete_user_permissions', repository=PUBLIC_REPO,
|
|
||||||
username=FAKE_USERNAME), open_kwargs('DELETE')), 401),
|
|
||||||
((url_for('delete_user_permissions', repository=ORG_REPO,
|
|
||||||
username=FAKE_USERNAME), open_kwargs('DELETE')), 401),
|
|
||||||
((url_for('delete_user_permissions', repository=PRIVATE_REPO,
|
|
||||||
username=FAKE_USERNAME), open_kwargs('DELETE')), 401),
|
|
||||||
|
|
||||||
((url_for('delete_team_permissions', repository=PUBLIC_REPO,
|
|
||||||
teamname=ORG_OWNERS), open_kwargs('DELETE')), 401),
|
|
||||||
((url_for('delete_team_permissions', repository=PUBLIC_REPO,
|
|
||||||
teamname=ORG_READERS), open_kwargs('DELETE')), 401),
|
|
||||||
((url_for('delete_team_permissions', repository=ORG_REPO,
|
|
||||||
teamname=ORG_OWNERS), open_kwargs('DELETE')), 401),
|
|
||||||
((url_for('delete_team_permissions', repository=ORG_REPO,
|
|
||||||
teamname=ORG_READERS), open_kwargs('DELETE')), 401),
|
|
||||||
((url_for('delete_team_permissions', repository=PRIVATE_REPO,
|
|
||||||
teamname=ORG_OWNERS), open_kwargs('DELETE')), 401),
|
|
||||||
((url_for('delete_team_permissions', repository=PRIVATE_REPO,
|
|
||||||
teamname=ORG_READERS), open_kwargs('DELETE')), 401),
|
|
||||||
|
|
||||||
((url_for('list_repo_tokens', repository=PUBLIC_REPO), open_kwargs()),
|
|
||||||
401),
|
|
||||||
((url_for('list_repo_tokens', repository=ORG_REPO), open_kwargs()), 401),
|
|
||||||
((url_for('list_repo_tokens', repository=PRIVATE_REPO), open_kwargs()),
|
|
||||||
401),
|
|
||||||
|
|
||||||
((url_for('get_tokens', repository=PUBLIC_REPO, code=FAKE_TOKEN),
|
|
||||||
open_kwargs()), 401),
|
|
||||||
((url_for('get_tokens', repository=ORG_REPO, code=FAKE_TOKEN),
|
|
||||||
open_kwargs()), 401),
|
|
||||||
((url_for('get_tokens', repository=PRIVATE_REPO, code=FAKE_TOKEN),
|
|
||||||
open_kwargs()), 401),
|
|
||||||
|
|
||||||
((url_for('create_token', repository=PUBLIC_REPO), open_kwargs('POST')),
|
|
||||||
401),
|
|
||||||
((url_for('create_token', repository=ORG_REPO), open_kwargs('POST')),
|
|
||||||
401),
|
|
||||||
((url_for('create_token', repository=PRIVATE_REPO), open_kwargs('POST')),
|
|
||||||
401),
|
|
||||||
|
|
||||||
((url_for('change_token', repository=PUBLIC_REPO, code=FAKE_TOKEN),
|
|
||||||
open_kwargs('PUT')), 401),
|
|
||||||
((url_for('change_token', repository=ORG_REPO, code=FAKE_TOKEN),
|
|
||||||
open_kwargs('PUT')), 401),
|
|
||||||
((url_for('change_token', repository=PRIVATE_REPO, code=FAKE_TOKEN),
|
|
||||||
open_kwargs('PUT')), 401),
|
|
||||||
|
|
||||||
((url_for('delete_token', repository=PUBLIC_REPO, code=FAKE_TOKEN),
|
|
||||||
open_kwargs('DELETE')), 401),
|
|
||||||
((url_for('delete_token', repository=ORG_REPO, code=FAKE_TOKEN),
|
|
||||||
open_kwargs('DELETE')), 401),
|
|
||||||
((url_for('delete_token', repository=PRIVATE_REPO, code=FAKE_TOKEN),
|
|
||||||
open_kwargs('DELETE')), 401),
|
|
||||||
|
|
||||||
((url_for('subscribe_api'), open_kwargs('PUT')), 401),
|
|
||||||
|
|
||||||
((url_for('subscribe_org_api', orgname=ORG), open_kwargs('PUT')), 401),
|
|
||||||
|
|
||||||
((url_for('get_subscription'), open_kwargs()), 401),
|
|
||||||
|
|
||||||
((url_for('get_org_subscription', orgname=ORG), open_kwargs()), 401),
|
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
def build_no_access_spec():
|
|
||||||
changes = OrderedDict([
|
|
||||||
((url_for('change_user_details'), open_kwargs('PUT')), 200),
|
|
||||||
|
|
||||||
((url_for('get_matching_users', prefix='dev'), open_kwargs()), 200),
|
|
||||||
|
|
||||||
((url_for('get_matching_entities', prefix='dev'), open_kwargs()), 200),
|
|
||||||
|
|
||||||
((url_for('get_organization', orgname=ORG), open_kwargs()), 403),
|
|
||||||
|
|
||||||
((url_for('get_organization_private_allowed', orgname=ORG),
|
|
||||||
open_kwargs()), 403),
|
|
||||||
|
|
||||||
((url_for('update_organization_team', orgname=ORG, teamname=ORG_OWNERS),
|
|
||||||
open_kwargs('PUT')), 403),
|
|
||||||
((url_for('update_organization_team', orgname=ORG, teamname=ORG_READERS),
|
|
||||||
open_kwargs('PUT')), 403),
|
|
||||||
|
|
||||||
((url_for('delete_organization_team', orgname=ORG, teamname=ORG_OWNERS),
|
|
||||||
open_kwargs('DELETE')), 403),
|
|
||||||
((url_for('delete_organization_team', orgname=ORG, teamname=ORG_READERS),
|
|
||||||
open_kwargs('DELETE')), 403),
|
|
||||||
|
|
||||||
((url_for('get_organization_team_members', orgname=ORG,
|
|
||||||
teamname=ORG_OWNERS), open_kwargs()), 403),
|
|
||||||
((url_for('get_organization_team_members', orgname=ORG,
|
|
||||||
teamname=ORG_READERS), open_kwargs()), 403),
|
|
||||||
|
|
||||||
((url_for('update_organization_team_member', orgname=ORG,
|
|
||||||
teamname=ORG_OWNERS, membername=ORG_OWNER),
|
|
||||||
open_kwargs('PUT')), 403),
|
|
||||||
((url_for('update_organization_team_member', orgname=ORG,
|
|
||||||
teamname=ORG_READERS, membername=ORG_OWNER),
|
|
||||||
open_kwargs('PUT')), 403),
|
|
||||||
|
|
||||||
((url_for('delete_organization_team_member', orgname=ORG,
|
|
||||||
teamname=ORG_OWNERS, membername=ORG_OWNER),
|
|
||||||
open_kwargs('DELETE')), 403),
|
|
||||||
((url_for('delete_organization_team_member', orgname=ORG,
|
|
||||||
teamname=ORG_READERS, membername=ORG_OWNER),
|
|
||||||
open_kwargs('DELETE')), 403),
|
|
||||||
|
|
||||||
((url_for('create_repo_api'), open_kwargs('POST', NEW_ORG_REPO_DETAILS)),
|
|
||||||
403),
|
|
||||||
|
|
||||||
((url_for('update_repo_api', repository=PUBLIC_REPO), open_kwargs('PUT')),
|
|
||||||
403),
|
|
||||||
((url_for('update_repo_api', repository=ORG_REPO), open_kwargs('PUT')),
|
|
||||||
403),
|
|
||||||
((url_for('update_repo_api', repository=PRIVATE_REPO),
|
|
||||||
open_kwargs('PUT')), 403),
|
|
||||||
|
|
||||||
((url_for('change_repo_visibility_api', repository=PUBLIC_REPO),
|
|
||||||
open_kwargs('POST')), 403),
|
|
||||||
((url_for('change_repo_visibility_api', repository=ORG_REPO),
|
|
||||||
open_kwargs('POST')), 403),
|
|
||||||
((url_for('change_repo_visibility_api', repository=PRIVATE_REPO),
|
|
||||||
open_kwargs('POST')), 403),
|
|
||||||
|
|
||||||
((url_for('delete_repository', repository=PUBLIC_REPO),
|
|
||||||
open_kwargs('DELETE')), 403),
|
|
||||||
((url_for('delete_repository', repository=ORG_REPO),
|
|
||||||
open_kwargs('DELETE')), 403),
|
|
||||||
((url_for('delete_repository', repository=PRIVATE_REPO),
|
|
||||||
open_kwargs('DELETE')), 403),
|
|
||||||
|
|
||||||
((url_for('get_repo_builds', repository=PUBLIC_REPO), open_kwargs()),
|
|
||||||
403),
|
|
||||||
((url_for('get_repo_builds', repository=ORG_REPO), open_kwargs()), 403),
|
|
||||||
((url_for('get_repo_builds', repository=PRIVATE_REPO), open_kwargs()),
|
|
||||||
403),
|
|
||||||
|
|
||||||
((url_for('get_filedrop_url'), open_kwargs('POST')), 400),
|
|
||||||
|
|
||||||
((url_for('request_repo_build', repository=PUBLIC_REPO),
|
|
||||||
open_kwargs('POST')), 403),
|
|
||||||
((url_for('request_repo_build', repository=ORG_REPO),
|
|
||||||
open_kwargs('POST')), 403),
|
|
||||||
((url_for('request_repo_build', repository=PRIVATE_REPO),
|
|
||||||
open_kwargs('POST')), 403),
|
|
||||||
|
|
||||||
((url_for('list_repo_team_permissions', repository=PUBLIC_REPO),
|
|
||||||
open_kwargs()), 403),
|
|
||||||
((url_for('list_repo_team_permissions', repository=ORG_REPO),
|
|
||||||
open_kwargs()), 403),
|
|
||||||
((url_for('list_repo_team_permissions', repository=PRIVATE_REPO),
|
|
||||||
open_kwargs()), 403),
|
|
||||||
|
|
||||||
((url_for('list_repo_user_permissions', repository=PUBLIC_REPO),
|
|
||||||
open_kwargs()), 403),
|
|
||||||
((url_for('list_repo_user_permissions', repository=ORG_REPO),
|
|
||||||
open_kwargs()), 403),
|
|
||||||
((url_for('list_repo_user_permissions', repository=PRIVATE_REPO),
|
|
||||||
open_kwargs()), 403),
|
|
||||||
|
|
||||||
((url_for('get_user_permissions', repository=PUBLIC_REPO,
|
|
||||||
username=FAKE_USERNAME), open_kwargs()), 403),
|
|
||||||
((url_for('get_user_permissions', repository=ORG_REPO,
|
|
||||||
username=FAKE_USERNAME), open_kwargs()), 403),
|
|
||||||
((url_for('get_user_permissions', repository=PRIVATE_REPO,
|
|
||||||
username=FAKE_USERNAME), open_kwargs()), 403),
|
|
||||||
|
|
||||||
((url_for('get_team_permissions', repository=PUBLIC_REPO,
|
|
||||||
teamname=ORG_OWNERS), open_kwargs()), 403),
|
|
||||||
((url_for('get_team_permissions', repository=PUBLIC_REPO,
|
|
||||||
teamname=ORG_READERS), open_kwargs()), 403),
|
|
||||||
((url_for('get_team_permissions', repository=ORG_REPO,
|
|
||||||
teamname=ORG_OWNERS), open_kwargs()), 403),
|
|
||||||
((url_for('get_team_permissions', repository=ORG_REPO,
|
|
||||||
teamname=ORG_READERS), open_kwargs()), 403),
|
|
||||||
((url_for('get_team_permissions', repository=PRIVATE_REPO,
|
|
||||||
teamname=ORG_OWNERS), open_kwargs()), 403),
|
|
||||||
((url_for('get_team_permissions', repository=PRIVATE_REPO,
|
|
||||||
teamname=ORG_READERS), open_kwargs()), 403),
|
|
||||||
|
|
||||||
((url_for('change_user_permissions', repository=PUBLIC_REPO,
|
|
||||||
username=FAKE_USERNAME), open_kwargs('PUT')), 403),
|
|
||||||
((url_for('change_user_permissions', repository=ORG_REPO,
|
|
||||||
username=FAKE_USERNAME), open_kwargs('PUT')), 403),
|
|
||||||
((url_for('change_user_permissions', repository=PRIVATE_REPO,
|
|
||||||
username=FAKE_USERNAME), open_kwargs('PUT')), 403),
|
|
||||||
|
|
||||||
((url_for('change_team_permissions', repository=PUBLIC_REPO,
|
|
||||||
teamname=ORG_OWNERS), open_kwargs('PUT')), 403),
|
|
||||||
((url_for('change_team_permissions', repository=PUBLIC_REPO,
|
|
||||||
teamname=ORG_READERS), open_kwargs('PUT')), 403),
|
|
||||||
((url_for('change_team_permissions', repository=ORG_REPO,
|
|
||||||
teamname=ORG_OWNERS), open_kwargs('PUT')), 403),
|
|
||||||
((url_for('change_team_permissions', repository=ORG_REPO,
|
|
||||||
teamname=ORG_READERS), open_kwargs('PUT')), 403),
|
|
||||||
((url_for('change_team_permissions', repository=PRIVATE_REPO,
|
|
||||||
teamname=ORG_OWNERS), open_kwargs('PUT')), 403),
|
|
||||||
((url_for('change_team_permissions', repository=PRIVATE_REPO,
|
|
||||||
teamname=ORG_READERS), open_kwargs('PUT')), 403),
|
|
||||||
|
|
||||||
((url_for('delete_user_permissions', repository=PUBLIC_REPO,
|
|
||||||
username=FAKE_USERNAME), open_kwargs('DELETE')), 403),
|
|
||||||
((url_for('delete_user_permissions', repository=ORG_REPO,
|
|
||||||
username=FAKE_USERNAME), open_kwargs('DELETE')), 403),
|
|
||||||
((url_for('delete_user_permissions', repository=PRIVATE_REPO,
|
|
||||||
username=FAKE_USERNAME), open_kwargs('DELETE')), 403),
|
|
||||||
|
|
||||||
((url_for('delete_team_permissions', repository=PUBLIC_REPO,
|
|
||||||
teamname=ORG_OWNERS), open_kwargs('DELETE')), 403),
|
|
||||||
((url_for('delete_team_permissions', repository=PUBLIC_REPO,
|
|
||||||
teamname=ORG_READERS), open_kwargs('DELETE')), 403),
|
|
||||||
((url_for('delete_team_permissions', repository=ORG_REPO,
|
|
||||||
teamname=ORG_OWNERS), open_kwargs('DELETE')), 403),
|
|
||||||
((url_for('delete_team_permissions', repository=ORG_REPO,
|
|
||||||
teamname=ORG_READERS), open_kwargs('DELETE')), 403),
|
|
||||||
((url_for('delete_team_permissions', repository=PRIVATE_REPO,
|
|
||||||
teamname=ORG_OWNERS), open_kwargs('DELETE')), 403),
|
|
||||||
((url_for('delete_team_permissions', repository=PRIVATE_REPO,
|
|
||||||
teamname=ORG_READERS), open_kwargs('DELETE')), 403),
|
|
||||||
|
|
||||||
((url_for('list_repo_tokens', repository=PUBLIC_REPO), open_kwargs()),
|
|
||||||
403),
|
|
||||||
((url_for('list_repo_tokens', repository=ORG_REPO), open_kwargs()), 403),
|
|
||||||
((url_for('list_repo_tokens', repository=PRIVATE_REPO), open_kwargs()),
|
|
||||||
403),
|
|
||||||
|
|
||||||
((url_for('get_tokens', repository=PUBLIC_REPO, code=FAKE_TOKEN),
|
|
||||||
open_kwargs()), 403),
|
|
||||||
((url_for('get_tokens', repository=ORG_REPO, code=FAKE_TOKEN),
|
|
||||||
open_kwargs()), 403),
|
|
||||||
((url_for('get_tokens', repository=PRIVATE_REPO, code=FAKE_TOKEN),
|
|
||||||
open_kwargs()), 403),
|
|
||||||
|
|
||||||
((url_for('create_token', repository=PUBLIC_REPO), open_kwargs('POST')),
|
|
||||||
403),
|
|
||||||
((url_for('create_token', repository=ORG_REPO), open_kwargs('POST')),
|
|
||||||
403),
|
|
||||||
((url_for('create_token', repository=PRIVATE_REPO), open_kwargs('POST')),
|
|
||||||
403),
|
|
||||||
|
|
||||||
((url_for('change_token', repository=PUBLIC_REPO, code=FAKE_TOKEN),
|
|
||||||
open_kwargs('PUT')), 403),
|
|
||||||
((url_for('change_token', repository=ORG_REPO, code=FAKE_TOKEN),
|
|
||||||
open_kwargs('PUT')), 403),
|
|
||||||
((url_for('change_token', repository=PRIVATE_REPO, code=FAKE_TOKEN),
|
|
||||||
open_kwargs('PUT')), 403),
|
|
||||||
|
|
||||||
((url_for('delete_token', repository=PUBLIC_REPO, code=FAKE_TOKEN),
|
|
||||||
open_kwargs('DELETE')), 403),
|
|
||||||
((url_for('delete_token', repository=ORG_REPO, code=FAKE_TOKEN),
|
|
||||||
open_kwargs('DELETE')), 403),
|
|
||||||
((url_for('delete_token', repository=PRIVATE_REPO, code=FAKE_TOKEN),
|
|
||||||
open_kwargs('DELETE')), 403),
|
|
||||||
|
|
||||||
((url_for('subscribe_api'), open_kwargs('PUT')), 400),
|
|
||||||
|
|
||||||
((url_for('subscribe_org_api', orgname=ORG), open_kwargs('PUT')), 403),
|
|
||||||
|
|
||||||
((url_for('get_subscription'), open_kwargs()), 200),
|
|
||||||
|
|
||||||
((url_for('get_org_subscription', orgname=ORG), open_kwargs()), 403),
|
|
||||||
])
|
|
||||||
|
|
||||||
to_update = build_anon_spec()
|
|
||||||
to_update.update(changes)
|
|
||||||
return to_update
|
|
||||||
|
|
||||||
|
|
||||||
def build_read_access_spec():
|
|
||||||
changes = OrderedDict([
|
|
||||||
((url_for('get_organization', orgname=ORG), open_kwargs()), 200),
|
|
||||||
|
|
||||||
((url_for('get_organization_team_members', orgname=ORG,
|
|
||||||
teamname=ORG_READERS), open_kwargs()), 200),
|
|
||||||
|
|
||||||
((url_for('create_repo_api'), open_kwargs('POST', NEW_ORG_REPO_DETAILS)),
|
|
||||||
403),
|
|
||||||
|
|
||||||
((url_for('get_repo_api', repository=ORG_REPO), open_kwargs()), 200),
|
|
||||||
((url_for('get_repo_api', repository=PRIVATE_REPO), open_kwargs()), 200),
|
|
||||||
|
|
||||||
((url_for('list_repository_images', repository=ORG_REPO),
|
|
||||||
open_kwargs()), 200),
|
|
||||||
((url_for('list_repository_images', repository=PRIVATE_REPO),
|
|
||||||
open_kwargs()), 200),
|
|
||||||
|
|
||||||
((url_for('get_image', repository=ORG_REPO, image_id=FAKE_IMAGE_ID),
|
|
||||||
open_kwargs()), 404),
|
|
||||||
((url_for('get_image', repository=PRIVATE_REPO, image_id=FAKE_IMAGE_ID),
|
|
||||||
open_kwargs()), 404),
|
|
||||||
|
|
||||||
((url_for('get_image_changes', repository=ORG_REPO,
|
|
||||||
image_id=FAKE_IMAGE_ID), open_kwargs()), 404),
|
|
||||||
((url_for('get_image_changes', repository=PRIVATE_REPO,
|
|
||||||
image_id=FAKE_IMAGE_ID), open_kwargs()), 404),
|
|
||||||
|
|
||||||
((url_for('list_tag_images', repository=ORG_REPO, tag=FAKE_TAG_NAME),
|
|
||||||
open_kwargs()), 404),
|
|
||||||
((url_for('list_tag_images', repository=PRIVATE_REPO, tag=FAKE_TAG_NAME),
|
|
||||||
open_kwargs()), 404),
|
|
||||||
])
|
|
||||||
|
|
||||||
to_update = build_no_access_spec()
|
|
||||||
to_update.update(changes)
|
|
||||||
return to_update
|
|
||||||
|
|
|
@ -6,12 +6,12 @@ import endpoints.api
|
||||||
from app import app
|
from app import app
|
||||||
from data import model
|
from data import model
|
||||||
from initdb import wipe_database, initialize_database, populate_database
|
from initdb import wipe_database, initialize_database, populate_database
|
||||||
from specs import (build_anon_spec, build_no_access_spec,
|
from specs import build_specs
|
||||||
build_read_access_spec)
|
|
||||||
|
|
||||||
|
|
||||||
NO_ACCESS_USER = 'freshuser'
|
NO_ACCESS_USER = 'freshuser'
|
||||||
READ_ACCESS_USER = 'reader'
|
READ_ACCESS_USER = 'reader'
|
||||||
|
ADMIN_ACCESS_USER = 'devtable'
|
||||||
|
|
||||||
|
|
||||||
class ApiTestCase(unittest.TestCase):
|
class ApiTestCase(unittest.TestCase):
|
||||||
|
@ -42,14 +42,18 @@ class SpecTestBuilder(type):
|
||||||
rv = c.open(url, **open_kwargs)
|
rv = c.open(url, **open_kwargs)
|
||||||
msg = '%s %s: %s expected: %s' % (open_kwargs['method'], url,
|
msg = '%s %s: %s expected: %s' % (open_kwargs['method'], url,
|
||||||
rv.status_code, expected_status)
|
rv.status_code, expected_status)
|
||||||
|
if rv.status_code != expected_status:
|
||||||
|
print msg
|
||||||
self.assertEqual(rv.status_code, expected_status, msg)
|
self.assertEqual(rv.status_code, expected_status, msg)
|
||||||
return test
|
return test
|
||||||
|
|
||||||
|
|
||||||
def __new__(cls, name, bases, attrs):
|
def __new__(cls, name, bases, attrs):
|
||||||
with app.test_request_context() as ctx:
|
with app.test_request_context() as ctx:
|
||||||
spec = attrs['spec_func']()
|
specs = attrs['spec_func']()
|
||||||
for (url, open_kwargs), expected_status in spec.items():
|
for test_spec in specs:
|
||||||
|
url, open_kwargs = test_spec.get_client_args()
|
||||||
|
expected_status = getattr(test_spec, attrs['result_attr'])
|
||||||
test = SpecTestBuilder._test_generator(url, expected_status,
|
test = SpecTestBuilder._test_generator(url, expected_status,
|
||||||
open_kwargs,
|
open_kwargs,
|
||||||
attrs['auth_username'])
|
attrs['auth_username'])
|
||||||
|
@ -64,21 +68,31 @@ class SpecTestBuilder(type):
|
||||||
|
|
||||||
class TestAnonymousAccess(ApiTestCase):
|
class TestAnonymousAccess(ApiTestCase):
|
||||||
__metaclass__ = SpecTestBuilder
|
__metaclass__ = SpecTestBuilder
|
||||||
spec_func = build_anon_spec
|
spec_func = build_specs
|
||||||
|
result_attr = 'anon_code'
|
||||||
auth_username = None
|
auth_username = None
|
||||||
|
|
||||||
|
|
||||||
class TestNoAccess(ApiTestCase):
|
class TestNoAccess(ApiTestCase):
|
||||||
__metaclass__ = SpecTestBuilder
|
__metaclass__ = SpecTestBuilder
|
||||||
spec_func = build_no_access_spec
|
spec_func = build_specs
|
||||||
|
result_attr = 'no_access_code'
|
||||||
auth_username = NO_ACCESS_USER
|
auth_username = NO_ACCESS_USER
|
||||||
|
|
||||||
|
|
||||||
class TestReadAccess(ApiTestCase):
|
class TestReadAccess(ApiTestCase):
|
||||||
__metaclass__ = SpecTestBuilder
|
__metaclass__ = SpecTestBuilder
|
||||||
spec_func = build_read_access_spec
|
spec_func = build_specs
|
||||||
|
result_attr = 'read_code'
|
||||||
auth_username = READ_ACCESS_USER
|
auth_username = READ_ACCESS_USER
|
||||||
|
|
||||||
|
|
||||||
|
class TestAdminAccess(ApiTestCase):
|
||||||
|
__metaclass__ = SpecTestBuilder
|
||||||
|
spec_func = build_specs
|
||||||
|
result_attr = 'admin_code'
|
||||||
|
auth_username = ADMIN_ACCESS_USER
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -19,6 +19,9 @@ class FakeStorage(Storage):
|
||||||
def stream_write(self, path, fp):
|
def stream_write(self, path, fp):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def remove(self, path):
|
||||||
|
pass
|
||||||
|
|
||||||
def exists(self, path):
|
def exists(self, path):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
Reference in a new issue