get-perms-api-helper: show nicer message when prefix is specified to help in API usage.
This commit is contained in:
parent
2c14a575a7
commit
abcf0ed683
6 changed files with 11 additions and 8 deletions
|
|
@ -66,7 +66,7 @@ class TestGrantUserGroupPermission(object):
|
|||
perm=perm)
|
||||
response = api_call(self.app, params)
|
||||
|
||||
expected = 'permission `%s` does not exist' % (perm,)
|
||||
expected = 'permission `%s` does not exist.' % (perm,)
|
||||
assert_error(id_, expected, given=response.body)
|
||||
|
||||
@mock.patch.object(RepoModel, 'grant_user_group_permission', crash)
|
||||
|
|
|
|||
|
|
@ -132,8 +132,7 @@ class TestGrantUserGroupPermissionFromRepoGroup(object):
|
|||
RepoGroupModel().revoke_user_group_permission(
|
||||
repo_group.group_id, user_group.users_group_id)
|
||||
else:
|
||||
expected = 'repository group `%s` does not exist' % (
|
||||
repo_group.name,)
|
||||
expected = 'repository group `%s` does not exist' % (repo_group.name,)
|
||||
assert_error(id_, expected, given=response.body)
|
||||
|
||||
def test_api_grant_user_group_permission_to_repo_group_wrong_permission(
|
||||
|
|
@ -149,7 +148,7 @@ class TestGrantUserGroupPermissionFromRepoGroup(object):
|
|||
perm=perm)
|
||||
response = api_call(self.app, params)
|
||||
|
||||
expected = 'permission `%s` does not exist' % (perm,)
|
||||
expected = 'permission `%s` does not exist. Permission should start with prefix: `group.`' % (perm,)
|
||||
assert_error(id_, expected, given=response.body)
|
||||
|
||||
@mock.patch.object(RepoGroupModel, 'grant_user_group_permission', crash)
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ class TestGrantUserPermission(object):
|
|||
perm=perm)
|
||||
response = api_call(self.app, params)
|
||||
|
||||
expected = 'permission `%s` does not exist' % (perm,)
|
||||
expected = 'permission `%s` does not exist.' % (perm,)
|
||||
assert_error(id_, expected, given=response.body)
|
||||
|
||||
@mock.patch.object(RepoModel, 'grant_user_permission', crash)
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ class TestGrantUserPermissionFromRepoGroup(object):
|
|||
perm=perm)
|
||||
response = api_call(self.app, params)
|
||||
|
||||
expected = 'permission `%s` does not exist' % (perm,)
|
||||
expected = 'permission `%s` does not exist. Permission should start with prefix: `group.`' % (perm,)
|
||||
assert_error(id_, expected, given=response.body)
|
||||
|
||||
@mock.patch.object(RepoGroupModel, 'grant_user_permission', crash)
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ class TestGrantUserPermissionFromUserGroup(object):
|
|||
perm=perm)
|
||||
response = api_call(self.app, params)
|
||||
|
||||
expected = 'permission `%s` does not exist' % perm
|
||||
expected = 'permission `%s` does not exist. Permission should start with prefix: `usergroup.`' % perm
|
||||
assert_error(id_, expected, given=response.body)
|
||||
|
||||
def test_api_grant_user_permission_to_user_group_exception_when_adding(
|
||||
|
|
|
|||
|
|
@ -308,7 +308,11 @@ def get_perm_or_error(permid, prefix=None):
|
|||
|
||||
perm = PermissionModel.cls.get_by_key(permid)
|
||||
if perm is None:
|
||||
raise JSONRPCError('permission `%s` does not exist' % (permid,))
|
||||
msg = 'permission `{}` does not exist.'.format(permid)
|
||||
if prefix:
|
||||
msg += ' Permission should start with prefix: `{}`'.format(prefix)
|
||||
raise JSONRPCError(msg)
|
||||
|
||||
if prefix:
|
||||
if not perm.permission_name.startswith(prefix):
|
||||
raise JSONRPCError('permission `%s` is invalid, '
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue