def test_api_get_repo( self, apikey_attr, expect_secrets, cache_param, backend, user_util): repo = backend.create_repo() usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) group = user_util.create_user_group(members=[usr]) user_util.grant_user_group_permission_to_repo( repo=repo, user_group=group, permission_name='repository.read') Session().commit() kwargs = { 'repoid': repo.repo_name, } if cache_param is not None: kwargs['cache'] = cache_param apikey = getattr(self, apikey_attr) id_, params = build_data(apikey, 'get_repo', **kwargs) response = api_call(self.app, params) ret = repo.get_api_data() permissions = expected_permissions(repo) followers = [] for user in repo.followers: followers.append(user.user.get_api_data( include_secrets=expect_secrets)) ret['members'] = permissions ret['permissions'] = permissions ret['followers'] = followers expected = ret assert_ok(id_, expected, given=response.body)
def test_api_get_repo_by_non_admin(self, grant_perm, backend): # TODO: Depending on which tests are running before this one, we # start with a different number of permissions in the database. repo = RepoModel().get_by_repo_name(backend.repo_name) permission_count = len(repo.repo_to_perm) RepoModel().grant_user_permission(repo=backend.repo_name, user=self.TEST_USER_LOGIN, perm=grant_perm) Session().commit() id_, params = build_data( self.apikey_regular, 'get_repo', repoid=backend.repo_name) response = api_call(self.app, params) repo = RepoModel().get_by_repo_name(backend.repo_name) ret = repo.get_api_data() assert permission_count + 1, len(repo.repo_to_perm) permissions = expected_permissions(repo) followers = [] for user in repo.followers: followers.append(user.user.get_api_data()) ret['members'] = permissions ret['permissions'] = permissions ret['followers'] = followers expected = ret try: assert_ok(id_, expected, given=response.body) finally: RepoModel().revoke_user_permission( backend.repo_name, self.TEST_USER_LOGIN)
def test_api_get_user_group_regular_user(self, user_util): user, group = user_util.create_user_with_group() id_, params = build_data(self.apikey_regular, 'get_user_group', usergroupid=group.users_group_name) response = api_call(self.app, params) ret = group.get_api_data() ret['users'] = [user.get_api_data()] permissions = expected_permissions(group) ret['members'] = permissions expected = ret assert_ok(id_, expected, given=response.body)
def test_api_get_repo_group(self, user_util): repo_group = user_util.create_repo_group() repo_group_name = repo_group.group_name id_, params = build_data(self.apikey, 'get_repo_group', repogroupid=repo_group_name) response = api_call(self.app, params) repo_group = RepoGroupModel()._get_repo_group(repo_group_name) ret = repo_group.get_api_data() permissions = expected_permissions(repo_group) ret['members'] = permissions expected = ret assert_ok(id_, expected, given=response.body)