##// END OF EJS Templates
get-perms-api-helper: show nicer message when prefix is specified to help in API usage.
marcink -
r4194:22366957 stable
parent child Browse files
Show More
@@ -66,7 +66,7 b' class TestGrantUserGroupPermission(objec'
66 perm=perm)
66 perm=perm)
67 response = api_call(self.app, params)
67 response = api_call(self.app, params)
68
68
69 expected = 'permission `%s` does not exist' % (perm,)
69 expected = 'permission `%s` does not exist.' % (perm,)
70 assert_error(id_, expected, given=response.body)
70 assert_error(id_, expected, given=response.body)
71
71
72 @mock.patch.object(RepoModel, 'grant_user_group_permission', crash)
72 @mock.patch.object(RepoModel, 'grant_user_group_permission', crash)
@@ -132,8 +132,7 b' class TestGrantUserGroupPermissionFromRe'
132 RepoGroupModel().revoke_user_group_permission(
132 RepoGroupModel().revoke_user_group_permission(
133 repo_group.group_id, user_group.users_group_id)
133 repo_group.group_id, user_group.users_group_id)
134 else:
134 else:
135 expected = 'repository group `%s` does not exist' % (
135 expected = 'repository group `%s` does not exist' % (repo_group.name,)
136 repo_group.name,)
137 assert_error(id_, expected, given=response.body)
136 assert_error(id_, expected, given=response.body)
138
137
139 def test_api_grant_user_group_permission_to_repo_group_wrong_permission(
138 def test_api_grant_user_group_permission_to_repo_group_wrong_permission(
@@ -149,7 +148,7 b' class TestGrantUserGroupPermissionFromRe'
149 perm=perm)
148 perm=perm)
150 response = api_call(self.app, params)
149 response = api_call(self.app, params)
151
150
152 expected = 'permission `%s` does not exist' % (perm,)
151 expected = 'permission `%s` does not exist. Permission should start with prefix: `group.`' % (perm,)
153 assert_error(id_, expected, given=response.body)
152 assert_error(id_, expected, given=response.body)
154
153
155 @mock.patch.object(RepoGroupModel, 'grant_user_group_permission', crash)
154 @mock.patch.object(RepoGroupModel, 'grant_user_group_permission', crash)
@@ -65,7 +65,7 b' class TestGrantUserPermission(object):'
65 perm=perm)
65 perm=perm)
66 response = api_call(self.app, params)
66 response = api_call(self.app, params)
67
67
68 expected = 'permission `%s` does not exist' % (perm,)
68 expected = 'permission `%s` does not exist.' % (perm,)
69 assert_error(id_, expected, given=response.body)
69 assert_error(id_, expected, given=response.body)
70
70
71 @mock.patch.object(RepoModel, 'grant_user_permission', crash)
71 @mock.patch.object(RepoModel, 'grant_user_permission', crash)
@@ -132,7 +132,7 b' class TestGrantUserPermissionFromRepoGro'
132 perm=perm)
132 perm=perm)
133 response = api_call(self.app, params)
133 response = api_call(self.app, params)
134
134
135 expected = 'permission `%s` does not exist' % (perm,)
135 expected = 'permission `%s` does not exist. Permission should start with prefix: `group.`' % (perm,)
136 assert_error(id_, expected, given=response.body)
136 assert_error(id_, expected, given=response.body)
137
137
138 @mock.patch.object(RepoGroupModel, 'grant_user_permission', crash)
138 @mock.patch.object(RepoGroupModel, 'grant_user_permission', crash)
@@ -130,7 +130,7 b' class TestGrantUserPermissionFromUserGro'
130 perm=perm)
130 perm=perm)
131 response = api_call(self.app, params)
131 response = api_call(self.app, params)
132
132
133 expected = 'permission `%s` does not exist' % perm
133 expected = 'permission `%s` does not exist. Permission should start with prefix: `usergroup.`' % perm
134 assert_error(id_, expected, given=response.body)
134 assert_error(id_, expected, given=response.body)
135
135
136 def test_api_grant_user_permission_to_user_group_exception_when_adding(
136 def test_api_grant_user_permission_to_user_group_exception_when_adding(
@@ -308,7 +308,11 b' def get_perm_or_error(permid, prefix=Non'
308
308
309 perm = PermissionModel.cls.get_by_key(permid)
309 perm = PermissionModel.cls.get_by_key(permid)
310 if perm is None:
310 if perm is None:
311 raise JSONRPCError('permission `%s` does not exist' % (permid,))
311 msg = 'permission `{}` does not exist.'.format(permid)
312 if prefix:
313 msg += ' Permission should start with prefix: `{}`'.format(prefix)
314 raise JSONRPCError(msg)
315
312 if prefix:
316 if prefix:
313 if not perm.permission_name.startswith(prefix):
317 if not perm.permission_name.startswith(prefix):
314 raise JSONRPCError('permission `%s` is invalid, '
318 raise JSONRPCError('permission `%s` is invalid, '
General Comments 0
You need to be logged in to leave comments. Login now