Continue on API unit tests: Now 60% (or so) coverage
This commit is contained in:
parent
36d37e839b
commit
e3eee958a4
1 changed files with 138 additions and 0 deletions
|
@ -570,5 +570,143 @@ class TestDeleteOrganizationTeamMember(ApiTestCase):
|
||||||
assert not READ_ACCESS_USER in json['members']
|
assert not READ_ACCESS_USER in json['members']
|
||||||
|
|
||||||
|
|
||||||
|
class TestCreateRepo(ApiTestCase):
|
||||||
|
def test_duplicaterepo(self):
|
||||||
|
self.login(ADMIN_ACCESS_USER)
|
||||||
|
|
||||||
|
json = self.postJsonResponse('api.create_repo',
|
||||||
|
data=dict(repository='simple', visibility='public'),
|
||||||
|
expected_code=400)
|
||||||
|
|
||||||
|
self.assertEquals('Repository already exists', json['message'])
|
||||||
|
|
||||||
|
|
||||||
|
def test_createrepo(self):
|
||||||
|
self.login(ADMIN_ACCESS_USER)
|
||||||
|
|
||||||
|
json = self.postJsonResponse('api.create_repo',
|
||||||
|
data=dict(repository='newrepo', visibility='public', description=''))
|
||||||
|
|
||||||
|
|
||||||
|
self.assertEquals(ADMIN_ACCESS_USER, json['namespace'])
|
||||||
|
self.assertEquals('newrepo', json['name'])
|
||||||
|
|
||||||
|
|
||||||
|
def test_createrepo_underorg(self):
|
||||||
|
self.login(ADMIN_ACCESS_USER)
|
||||||
|
|
||||||
|
json = self.postJsonResponse('api.create_repo',
|
||||||
|
data=dict(namespace=ORGANIZATION,
|
||||||
|
repository='newrepo',
|
||||||
|
visibility='private',
|
||||||
|
description=''))
|
||||||
|
|
||||||
|
self.assertEquals(ORGANIZATION, json['namespace'])
|
||||||
|
self.assertEquals('newrepo', json['name'])
|
||||||
|
|
||||||
|
|
||||||
|
class TestFindRepos(ApiTestCase):
|
||||||
|
def test_findrepos_asguest(self):
|
||||||
|
json = self.getJsonResponse('api.find_repos', params=dict(query='p'))
|
||||||
|
assert len(json['repositories']) == 1
|
||||||
|
|
||||||
|
self.assertEquals(json['repositories'][0]['namespace'], 'public')
|
||||||
|
self.assertEquals(json['repositories'][0]['name'], 'publicrepo')
|
||||||
|
|
||||||
|
def test_findrepos_asuser(self):
|
||||||
|
self.login(NO_ACCESS_USER)
|
||||||
|
|
||||||
|
json = self.getJsonResponse('api.find_repos', params=dict(query='p'))
|
||||||
|
assert len(json['repositories']) == 1
|
||||||
|
|
||||||
|
self.assertEquals(json['repositories'][0]['namespace'], 'public')
|
||||||
|
self.assertEquals(json['repositories'][0]['name'], 'publicrepo')
|
||||||
|
|
||||||
|
def test_findrepos_orgmember(self):
|
||||||
|
self.login(READ_ACCESS_USER)
|
||||||
|
|
||||||
|
json = self.getJsonResponse('api.find_repos', params=dict(query='p'))
|
||||||
|
assert len(json['repositories']) > 1
|
||||||
|
|
||||||
|
|
||||||
|
class TestListRepos(ApiTestCase):
|
||||||
|
def test_listrepos_asguest(self):
|
||||||
|
json = self.getJsonResponse('api.list_repos', params=dict(public=True))
|
||||||
|
assert len(json['repositories']) == 0
|
||||||
|
|
||||||
|
def test_listrepos_orgmember(self):
|
||||||
|
self.login(READ_ACCESS_USER)
|
||||||
|
json = self.getJsonResponse('api.list_repos', params=dict(public=True))
|
||||||
|
assert len(json['repositories']) > 1
|
||||||
|
|
||||||
|
def test_listrepos_filter(self):
|
||||||
|
self.login(READ_ACCESS_USER)
|
||||||
|
json = self.getJsonResponse('api.list_repos', params=dict(namespace=ORGANIZATION, public=False))
|
||||||
|
|
||||||
|
for repo in json['repositories']:
|
||||||
|
self.assertEquals(ORGANIZATION, repo['namespace'])
|
||||||
|
|
||||||
|
def test_listrepos_limit(self):
|
||||||
|
self.login(READ_ACCESS_USER)
|
||||||
|
json = self.getJsonResponse('api.list_repos', params=dict(limit=2))
|
||||||
|
|
||||||
|
assert len(json['repositories']) == 2
|
||||||
|
|
||||||
|
|
||||||
|
class TestUpdateRepo(ApiTestCase):
|
||||||
|
def test_updatedescription(self):
|
||||||
|
self.login(ADMIN_ACCESS_USER)
|
||||||
|
|
||||||
|
self.putJsonResponse('api.update_repo',
|
||||||
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'),
|
||||||
|
data=dict(description='Some cool repo'))
|
||||||
|
|
||||||
|
# Verify the repo description was updated.
|
||||||
|
json = self.getJsonResponse('api.get_repo',
|
||||||
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'))
|
||||||
|
|
||||||
|
self.assertEquals('Some cool repo', json['description'])
|
||||||
|
|
||||||
|
|
||||||
|
class TestChangeRepoVisibility(ApiTestCase):
|
||||||
|
def test_changevisibility(self):
|
||||||
|
self.login(ADMIN_ACCESS_USER)
|
||||||
|
|
||||||
|
# Make public.
|
||||||
|
self.postJsonResponse('api.change_repo_visibility',
|
||||||
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'),
|
||||||
|
data=dict(visibility='public'))
|
||||||
|
|
||||||
|
# Verify the visibility.
|
||||||
|
json = self.getJsonResponse('api.get_repo',
|
||||||
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'))
|
||||||
|
|
||||||
|
self.assertEquals(True, json['is_public'])
|
||||||
|
|
||||||
|
# Make private.
|
||||||
|
self.postJsonResponse('api.change_repo_visibility',
|
||||||
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'),
|
||||||
|
data=dict(visibility='private'))
|
||||||
|
|
||||||
|
# Verify the visibility.
|
||||||
|
json = self.getJsonResponse('api.get_repo',
|
||||||
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'))
|
||||||
|
|
||||||
|
self.assertEquals(False, json['is_public'])
|
||||||
|
|
||||||
|
|
||||||
|
class TestDeleteRepository(ApiTestCase):
|
||||||
|
def test_deleterepo(self):
|
||||||
|
self.login(ADMIN_ACCESS_USER)
|
||||||
|
|
||||||
|
self.deleteResponse('api.delete_repository',
|
||||||
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'))
|
||||||
|
|
||||||
|
# Verify the repo was deleted.
|
||||||
|
self.getResponse('api.get_repo',
|
||||||
|
params=dict(repository=ADMIN_ACCESS_USER + '/simple'),
|
||||||
|
expected_code=404)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Reference in a new issue