This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/test/specs.py
2013-11-07 12:54:44 -05:00

258 lines
13 KiB
Python

import json
from flask import url_for
from collections import OrderedDict
from uuid import uuid4
PUBLIC_REPO = 'public/publicrepo'
PRIVATE_REPO = 'devtable/shared'
ORG = 'devtableorg'
ORG_REPO = ORG + '/orgrepo'
ORG_READERS = 'readers'
ORG_OWNER = 'devtable'
ORG_OWNERS = 'owners'
ORG_READERS = 'readers'
FAKE_IMAGE_ID = str(uuid4())
FAKE_TAG_NAME = str(uuid4())
FAKE_USERNAME = str(uuid4())
FAKE_TOKEN = str(uuid4())
NEW_ORG_REPO_DETAILS = {
'repository': str(uuid4()),
'visibility': 'private',
'description': '',
'namespace': ORG,
}
NEW_USER_DETAILS = {
'username': 'bob',
'password': 'password',
'email': 'jake@devtable.com',
}
SEND_RECOVERY_DETAILS = {
'email': 'jacob.moshenko@gmail.com',
}
SIGNIN_DETAILS = {
'username': 'devtable',
'password': 'password',
}
FILE_DROP_DETAILS = {
'mimeType': 'application/zip',
}
CHANGE_PERMISSION_DETAILS = {
'role': 'admin',
}
CREATE_BUILD_DETAILS = {
'file_id': str(uuid4()),
}
CHANGE_VISIBILITY_DETAILS = {
'visibility': 'public',
}
CREATE_TOKEN_DETAILS = {
'friendlyName': 'A new token',
}
UPDATE_REPO_DETAILS = {
'description': 'A new description',
}
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'
self.anon_code = anon_code
self.no_access_code = no_access_code
self.read_code = read_code
self.admin_code = admin_code
def set_data_from_obj(self, json_serializable):
self._data = json.dumps(json_serializable)
return self
def set_method(self, method):
self._method = method
return self
def get_client_args(self):
kwargs = {
'method': self._method
}
if self._data or self._method == 'POST' or self._method == 'PUT':
kwargs['data'] = self._data if self._data else '{}'
kwargs['content_type'] = 'application/json'
return self._url, kwargs
def build_specs():
return [
TestSpec(url_for('welcome'), 200, 200, 200, 200),
TestSpec(url_for('plans_list'), 200, 200, 200, 200),
TestSpec(url_for('get_logged_in_user'), 200, 200, 200, 200),
TestSpec(url_for('change_user_details'), 401, 200, 200, 200).set_method('PUT'),
TestSpec(url_for('create_user_api'), 201, 201, 201, 201).set_method('POST').set_data_from_obj(NEW_USER_DETAILS),
TestSpec(url_for('signin_api'), 200, 200, 200, 200).set_method('POST').set_data_from_obj(SIGNIN_DETAILS),
TestSpec(url_for('send_recovery'), 201, 201, 201, 201).set_method('POST').set_data_from_obj(SEND_RECOVERY_DETAILS),
TestSpec(url_for('get_matching_users', prefix='dev'), 401, 200, 200, 200),
TestSpec(url_for('get_matching_entities', prefix='dev'), 401, 200, 200, 200),
TestSpec(url_for('get_organization', orgname=ORG), 401, 403, 200, 200),
TestSpec(url_for('get_organization_private_allowed', orgname=ORG)),
TestSpec(url_for('update_organization_team', orgname=ORG, teamname=ORG_OWNERS)).set_method('PUT'),
TestSpec(url_for('update_organization_team', orgname=ORG, teamname=ORG_READERS)).set_method('PUT'),
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'),
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),
TestSpec(url_for('update_organization_team_member', orgname=ORG, teamname=ORG_OWNERS, membername=ORG_OWNER), admin_code=400).set_method('PUT'),
TestSpec(url_for('update_organization_team_member', orgname=ORG, teamname=ORG_READERS, membername=ORG_OWNER)).set_method('PUT'),
TestSpec(url_for('delete_organization_team_member', orgname=ORG, teamname=ORG_OWNERS, membername=ORG_OWNER), admin_code=400).set_method('DELETE'),
TestSpec(url_for('delete_organization_team_member', orgname=ORG, teamname=ORG_READERS, membername=ORG_OWNER), admin_code=400).set_method('DELETE'),
TestSpec(url_for('create_repo_api')).set_method('POST').set_data_from_obj(NEW_ORG_REPO_DETAILS),
TestSpec(url_for('match_repos_api'), 200, 200, 200, 200),
TestSpec(url_for('list_repos_api'), 200, 200, 200, 200),
TestSpec(url_for('update_repo_api', repository=PUBLIC_REPO), admin_code=403).set_method('PUT'),
TestSpec(url_for('update_repo_api', repository=ORG_REPO)).set_method('PUT').set_data_from_obj(UPDATE_REPO_DETAILS),
TestSpec(url_for('update_repo_api', repository=PRIVATE_REPO)).set_method('PUT').set_data_from_obj(UPDATE_REPO_DETAILS),
TestSpec(url_for('change_repo_visibility_api', repository=PUBLIC_REPO), admin_code=403).set_method('POST').set_data_from_obj(CHANGE_VISIBILITY_DETAILS),
TestSpec(url_for('change_repo_visibility_api', repository=ORG_REPO)).set_method('POST').set_data_from_obj(CHANGE_VISIBILITY_DETAILS),
TestSpec(url_for('change_repo_visibility_api', repository=PRIVATE_REPO)).set_method('POST').set_data_from_obj(CHANGE_VISIBILITY_DETAILS),
TestSpec(url_for('delete_repository', repository=PUBLIC_REPO), admin_code=403).set_method('DELETE'),
TestSpec(url_for('delete_repository', repository=ORG_REPO), admin_code=204).set_method('DELETE'),
TestSpec(url_for('delete_repository', repository=PRIVATE_REPO), admin_code=204).set_method('DELETE'),
TestSpec(url_for('get_repo_api', repository=PUBLIC_REPO), 200, 200, 200, 200),
TestSpec(url_for('get_repo_api', repository=ORG_REPO), 403, 403, 200, 200),
TestSpec(url_for('get_repo_api', repository=PRIVATE_REPO), 403, 403, 200, 200),
TestSpec(url_for('get_repo_builds', repository=PUBLIC_REPO), admin_code=403),
TestSpec(url_for('get_repo_builds', repository=ORG_REPO)),
TestSpec(url_for('get_repo_builds', repository=PRIVATE_REPO)),
TestSpec(url_for('get_filedrop_url'), 401, 200, 200, 200).set_method('POST').set_data_from_obj(FILE_DROP_DETAILS),
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),
TestSpec(url_for('request_repo_build', repository=PRIVATE_REPO), admin_code=201).set_method('POST').set_data_from_obj(CREATE_BUILD_DETAILS),
TestSpec(url_for('list_repository_images', repository=PUBLIC_REPO), 200, 200, 200, 200),
TestSpec(url_for('list_repository_images', repository=ORG_REPO), 403, 403, 200, 200),
TestSpec(url_for('list_repository_images', repository=PRIVATE_REPO), 403, 403, 200, 200),
TestSpec(url_for('get_image', repository=PUBLIC_REPO, image_id=FAKE_IMAGE_ID), 404, 404, 404, 404),
TestSpec(url_for('get_image', repository=ORG_REPO, image_id=FAKE_IMAGE_ID), 403, 403, 404, 404),
TestSpec(url_for('get_image', repository=PRIVATE_REPO, image_id=FAKE_IMAGE_ID), 403, 403, 404, 404),
TestSpec(url_for('get_image_changes', repository=PUBLIC_REPO, image_id=FAKE_IMAGE_ID), 404, 404, 404, 404),
TestSpec(url_for('get_image_changes', repository=ORG_REPO, image_id=FAKE_IMAGE_ID), 403, 403, 404, 404),
TestSpec(url_for('get_image_changes', repository=PRIVATE_REPO, image_id=FAKE_IMAGE_ID), 403, 403, 404, 404),
TestSpec(url_for('list_tag_images', repository=PUBLIC_REPO, tag=FAKE_TAG_NAME), 404, 404, 404, 404),
TestSpec(url_for('list_tag_images', repository=ORG_REPO, tag=FAKE_TAG_NAME), 403, 403, 404, 404),
TestSpec(url_for('list_tag_images', repository=PRIVATE_REPO, tag=FAKE_TAG_NAME), 403, 403, 404, 404),
TestSpec(url_for('list_repo_team_permissions', repository=PUBLIC_REPO), admin_code=403),
TestSpec(url_for('list_repo_team_permissions', repository=ORG_REPO)),
TestSpec(url_for('list_repo_team_permissions', repository=PRIVATE_REPO)),
TestSpec(url_for('list_repo_user_permissions', repository=PUBLIC_REPO), admin_code=403),
TestSpec(url_for('list_repo_user_permissions', repository=ORG_REPO)),
TestSpec(url_for('list_repo_user_permissions', repository=PRIVATE_REPO)),
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),
TestSpec(url_for('get_user_permissions', repository=PRIVATE_REPO, username=FAKE_USERNAME), admin_code=400),
TestSpec(url_for('get_team_permissions', repository=PUBLIC_REPO, teamname=ORG_OWNERS), admin_code=403),
TestSpec(url_for('get_team_permissions', repository=PUBLIC_REPO, teamname=ORG_READERS), admin_code=403),
TestSpec(url_for('get_team_permissions', repository=ORG_REPO, teamname=ORG_OWNERS), admin_code=400),
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),
TestSpec(url_for('get_team_permissions', repository=PRIVATE_REPO, teamname=ORG_READERS), admin_code=400),
TestSpec(url_for('change_user_permissions', repository=PUBLIC_REPO, username=FAKE_USERNAME), admin_code=403).set_method('PUT'),
TestSpec(url_for('change_user_permissions', repository=ORG_REPO, username=FAKE_USERNAME), admin_code=400).set_method('PUT'),
TestSpec(url_for('change_user_permissions', repository=PRIVATE_REPO, username=FAKE_USERNAME), admin_code=400).set_method('PUT'),
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),
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),
TestSpec(url_for('change_team_permissions', repository=ORG_REPO, teamname=ORG_OWNERS)).set_method('PUT').set_data_from_obj(CHANGE_PERMISSION_DETAILS),
TestSpec(url_for('change_team_permissions', repository=ORG_REPO, teamname=ORG_READERS)).set_method('PUT').set_data_from_obj(CHANGE_PERMISSION_DETAILS),
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),
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),
TestSpec(url_for('delete_user_permissions', repository=PUBLIC_REPO, username=FAKE_USERNAME), admin_code=403).set_method('DELETE'),
TestSpec(url_for('delete_user_permissions', repository=ORG_REPO, username=FAKE_USERNAME), admin_code=400).set_method('DELETE'),
TestSpec(url_for('delete_user_permissions', repository=PRIVATE_REPO, username=FAKE_USERNAME), admin_code=400).set_method('DELETE'),
TestSpec(url_for('delete_team_permissions', repository=PUBLIC_REPO, teamname=ORG_OWNERS), admin_code=403).set_method('DELETE'),
TestSpec(url_for('delete_team_permissions', repository=PUBLIC_REPO, teamname=ORG_READERS), admin_code=403).set_method('DELETE'),
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'),
TestSpec(url_for('delete_team_permissions', repository=PRIVATE_REPO, teamname=ORG_OWNERS), admin_code=400).set_method('DELETE'),
TestSpec(url_for('delete_team_permissions', repository=PRIVATE_REPO, teamname=ORG_READERS), admin_code=400).set_method('DELETE'),
TestSpec(url_for('list_repo_tokens', repository=PUBLIC_REPO), admin_code=403),
TestSpec(url_for('list_repo_tokens', repository=ORG_REPO)),
TestSpec(url_for('list_repo_tokens', repository=PRIVATE_REPO)),
TestSpec(url_for('get_tokens', repository=PUBLIC_REPO, code=FAKE_TOKEN), admin_code=403),
TestSpec(url_for('get_tokens', repository=ORG_REPO, code=FAKE_TOKEN), admin_code=400),
TestSpec(url_for('get_tokens', repository=PRIVATE_REPO, code=FAKE_TOKEN), admin_code=400),
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),
TestSpec(url_for('create_token', repository=PRIVATE_REPO), admin_code=201).set_method('POST').set_data_from_obj(CREATE_TOKEN_DETAILS),
TestSpec(url_for('change_token', repository=PUBLIC_REPO, code=FAKE_TOKEN), admin_code=403).set_method('PUT'),
TestSpec(url_for('change_token', repository=ORG_REPO, code=FAKE_TOKEN), admin_code=400).set_method('PUT'),
TestSpec(url_for('change_token', repository=PRIVATE_REPO, code=FAKE_TOKEN), admin_code=400).set_method('PUT'),
TestSpec(url_for('delete_token', repository=PUBLIC_REPO, code=FAKE_TOKEN), admin_code=403).set_method('DELETE'),
TestSpec(url_for('delete_token', repository=ORG_REPO, code=FAKE_TOKEN), admin_code=400).set_method('DELETE'),
TestSpec(url_for('delete_token', repository=PRIVATE_REPO, code=FAKE_TOKEN), admin_code=400).set_method('DELETE'),
TestSpec(url_for('subscribe_api'), 401, 400, 400, 400).set_method('PUT'),
TestSpec(url_for('subscribe_org_api', orgname=ORG), 401, 403, 403, 400).set_method('PUT'),
TestSpec(url_for('get_subscription'), 401, 200, 200, 200),
TestSpec(url_for('get_org_subscription', orgname=ORG)),
]