Add description for permissions
Fixes: https://pagure.io/koji/issue/335
This commit is contained in:
parent
e292fd8f2b
commit
1252129136
11 changed files with 371 additions and 68 deletions
|
|
@ -26,6 +26,7 @@ admin commands:
|
|||
edit-channel Edit a channel
|
||||
edit-external-repo Edit data for an external repo
|
||||
edit-host Edit a host
|
||||
edit-permission Edit a permission description
|
||||
edit-tag Alter tag information
|
||||
edit-tag-inheritance Edit tag inheritance
|
||||
edit-target Set the name, build_tag, and/or dest_tag of an existing build target to new values
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ admin commands:
|
|||
edit-channel Edit a channel
|
||||
edit-external-repo Edit data for an external repo
|
||||
edit-host Edit a host
|
||||
edit-permission Edit a permission description
|
||||
edit-tag Alter tag information
|
||||
edit-tag-inheritance Edit tag inheritance
|
||||
edit-target Set the name, build_tag, and/or dest_tag of an existing build target to new values
|
||||
|
|
|
|||
45
tests/test_cli/test_edit_permission.py
Normal file
45
tests/test_cli/test_edit_permission.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
from __future__ import absolute_import
|
||||
import mock
|
||||
import koji
|
||||
|
||||
from koji_cli.commands import handle_edit_permission
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestEditPermission(utils.CliTestCase):
|
||||
|
||||
def setUp(self):
|
||||
# Show long diffs in error output...
|
||||
self.maxDiff = None
|
||||
self.options = mock.MagicMock()
|
||||
self.options.quiet = True
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
self.activate_session_mock = mock.patch('koji_cli.commands.activate_session').start()
|
||||
self.error_format = """Usage: %s edit-permission <permission> <description>
|
||||
(Specify the --help global option for a list of other help options)
|
||||
|
||||
%s: error: {message}
|
||||
""" % (self.progname, self.progname)
|
||||
self.perm = 'test-perm'
|
||||
self.description = 'test-description'
|
||||
|
||||
def test_handle_edit_permission_argument_error(self):
|
||||
expected = self.format_error_message(
|
||||
"Please specify a permission and a description")
|
||||
for args in [[], [self.perm]]:
|
||||
self.assert_system_exit(
|
||||
handle_edit_permission,
|
||||
self.options,
|
||||
self.session,
|
||||
args,
|
||||
stderr=expected,
|
||||
activate_session=None)
|
||||
self.activate_session_mock.assert_not_called()
|
||||
self.session.grantPermission.assert_not_called()
|
||||
|
||||
def test_handle_edit_permission_with_new_and_description(self):
|
||||
handle_edit_permission(self.options, self.session, [self.perm, self.description])
|
||||
self.session.editPermission.assert_called_once_with(self.perm, self.description)
|
||||
self.activate_session_mock.assert_called_once_with(self.session, self.options)
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import absolute_import
|
||||
import mock
|
||||
import six
|
||||
import unittest
|
||||
import koji
|
||||
|
||||
from koji_cli.commands import handle_grant_permission
|
||||
from . import utils
|
||||
|
|
@ -9,72 +9,94 @@ from . import utils
|
|||
|
||||
class TestGrantPermission(utils.CliTestCase):
|
||||
|
||||
# Show long diffs in error output...
|
||||
maxDiff = None
|
||||
|
||||
def setUp(self):
|
||||
self.error_format = """Usage: %s grant-permission [--new] <permission> <user> [<user> ...]
|
||||
# Show long diffs in error output...
|
||||
self.maxDiff = None
|
||||
self.options = mock.MagicMock()
|
||||
self.options.quiet = True
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
self.activate_session_mock = mock.patch('koji_cli.commands.activate_session').start()
|
||||
self.error_format = """Usage: %s grant-permission [options] <permission> <user> [<user> ...]
|
||||
(Specify the --help global option for a list of other help options)
|
||||
|
||||
%s: error: {message}
|
||||
""" % (self.progname, self.progname)
|
||||
self.perm = 'createuser'
|
||||
self.user = 'user'
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||
@mock.patch('koji_cli.commands.activate_session')
|
||||
def test_handle_grant_permission(
|
||||
self,
|
||||
activate_session_mock,
|
||||
stdout):
|
||||
"""Test handle_grant_permission function"""
|
||||
session = mock.MagicMock()
|
||||
options = mock.MagicMock()
|
||||
perm = 'createrepo'
|
||||
users = 'user'
|
||||
|
||||
# Case 1. argument error
|
||||
def test_handle_grant_permission_argument_error(self):
|
||||
expected = self.format_error_message(
|
||||
"Please specify a permission and at least one user")
|
||||
for args in [[], [perm]]:
|
||||
for args in [[], [self.perm]]:
|
||||
self.assert_system_exit(
|
||||
handle_grant_permission,
|
||||
options,
|
||||
session,
|
||||
self.options,
|
||||
self.session,
|
||||
args,
|
||||
stderr=expected,
|
||||
activate_session=None)
|
||||
self.activate_session_mock.assert_not_called()
|
||||
self.session.grantPermission.assert_not_called()
|
||||
|
||||
# Case 2. user not exists
|
||||
expected = self.format_error_message(
|
||||
"No such user: %s" % users)
|
||||
session.getUser.return_value = None
|
||||
def test_handle_grant_permission_non_exist_user(self):
|
||||
expected = self.format_error_message("No such user: %s" % self.user)
|
||||
self.session.getUser.return_value = None
|
||||
self.assert_system_exit(
|
||||
handle_grant_permission,
|
||||
options,
|
||||
session,
|
||||
[perm, users],
|
||||
self.options,
|
||||
self.session,
|
||||
[self.perm, self.user],
|
||||
stderr=expected)
|
||||
self.session.grantPermission.assert_not_called()
|
||||
|
||||
# Case 3. grant permission with --new
|
||||
def test_handle_grant_permission_with_new(self):
|
||||
users = ['user1', 'user2', 'user3']
|
||||
perm = 'build_iso'
|
||||
session.getUser.side_effect = [
|
||||
self.session.getUser.side_effect = [
|
||||
{'id': 101, 'name': users[0]},
|
||||
{'id': 111, 'name': users[1]},
|
||||
{'id': 121, 'name': users[2]},
|
||||
]
|
||||
handle_grant_permission(options, session, [perm, '--new'] + users)
|
||||
handle_grant_permission(self.options, self.session, [perm, '--new'] + users)
|
||||
calls = [mock.call(p, perm, create=True) for p in users]
|
||||
session.grantPermission.assert_has_calls(calls)
|
||||
self.session.grantPermission.assert_has_calls(calls)
|
||||
self.activate_session_mock.assert_called_once_with(self.session, self.options)
|
||||
|
||||
def test_handle_grant_permission_description_without_new(self):
|
||||
expected = self.format_error_message(
|
||||
"Option new must be specified with option description.")
|
||||
self.session.getUser.return_value = {'id': 101, 'name': self.user}
|
||||
self.assert_system_exit(
|
||||
handle_grant_permission,
|
||||
self.options,
|
||||
self.session,
|
||||
[self.perm, self.user, '--description', 'test-description'],
|
||||
stderr=expected)
|
||||
self.session.grantPermission.assert_not_called()
|
||||
|
||||
def test_handle_grant_permission_with_new_and_description(self):
|
||||
description = 'test-description'
|
||||
self.session.getUser.return_value = {'id': 101, 'name': self.user}
|
||||
handle_grant_permission(self.options, self.session,
|
||||
['--new', '--description', description, self.perm, self.user])
|
||||
self.session.grantPermission.assert_called_once_with(
|
||||
self.user, self.perm, create=True, description=description)
|
||||
self.activate_session_mock.assert_called_once_with(self.session, self.options)
|
||||
|
||||
def test_handle_grant_permission_help(self):
|
||||
self.assert_help(
|
||||
handle_grant_permission,
|
||||
"""Usage: %s grant-permission [--new] <permission> <user> [<user> ...]
|
||||
"""Usage: %s grant-permission [options] <permission> <user> [<user> ...]
|
||||
(Specify the --help global option for a list of other help options)
|
||||
|
||||
Options:
|
||||
-h, --help show this help message and exit
|
||||
--new Create this permission if the permission does not exist
|
||||
-h, --help show this help message and exit
|
||||
--new Create this permission if the permission does not
|
||||
exist
|
||||
--description=DESCRIPTION
|
||||
Add description about new permission
|
||||
""" % self.progname)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,12 +32,12 @@ class TestListPermissions(utils.CliTestCase):
|
|||
options = mock.MagicMock()
|
||||
user = 'tester'
|
||||
all_perms = [
|
||||
{'id': 0, 'name': 'admin'},
|
||||
{'id': 1, 'name': 'build'},
|
||||
{'id': 2, 'name': 'repo'},
|
||||
{'id': 3, 'name': 'image'},
|
||||
{'id': 4, 'name': 'livecd'},
|
||||
{'id': 5, 'name': 'appliance'}
|
||||
{'id': 0, 'name': 'admin', 'description': 'admin-description'},
|
||||
{'id': 1, 'name': 'build', 'description': 'build-description'},
|
||||
{'id': 2, 'name': 'repo', 'description': 'repo-description'},
|
||||
{'id': 3, 'name': 'image', 'description': 'image-description'},
|
||||
{'id': 4, 'name': 'livecd', 'description': 'livecd-description'},
|
||||
{'id': 5, 'name': 'appliance', 'description': 'appliance-description'}
|
||||
]
|
||||
|
||||
# case 1. argument error (no argument is required)
|
||||
|
|
@ -62,7 +62,13 @@ class TestListPermissions(utils.CliTestCase):
|
|||
perms = [p['name'] for p in all_perms[::1]]
|
||||
session.getUserPerms.return_value = perms
|
||||
session.getUser.return_value = {'id': 101, 'name': user}
|
||||
expected = "\n".join([p for p in perms]) + "\n"
|
||||
expected = """admin
|
||||
build
|
||||
repo
|
||||
image
|
||||
livecd
|
||||
appliance
|
||||
"""
|
||||
handle_list_permissions(options, session, ['--user', user])
|
||||
self.assert_console_message(stdout, expected)
|
||||
|
||||
|
|
@ -71,7 +77,9 @@ class TestListPermissions(utils.CliTestCase):
|
|||
# case 4. List my permission
|
||||
perms = [p['name'] for p in all_perms[1:3]]
|
||||
session.getPerms.return_value = perms
|
||||
expected = "\n".join([p for p in perms]) + "\n"
|
||||
expected = """build
|
||||
repo
|
||||
"""
|
||||
handle_list_permissions(options, session, ['--mine'])
|
||||
self.assert_console_message(stdout, expected)
|
||||
session.getUserPerms.assert_not_called()
|
||||
|
|
@ -80,7 +88,13 @@ class TestListPermissions(utils.CliTestCase):
|
|||
|
||||
# case 5. List all permission
|
||||
session.getAllPerms.return_value = all_perms
|
||||
expected = "\n".join([p['name'] for p in all_perms]) + "\n"
|
||||
expected = """admin admin-description
|
||||
build build-description
|
||||
repo repo-description
|
||||
image image-description
|
||||
livecd livecd-description
|
||||
appliance appliance-description
|
||||
"""
|
||||
handle_list_permissions(options, session, [])
|
||||
self.assert_console_message(stdout, expected)
|
||||
session.getUserPerms.assert_not_called()
|
||||
|
|
@ -97,6 +111,7 @@ Options:
|
|||
-h, --help show this help message and exit
|
||||
--user=USER List permissions for the given user
|
||||
--mine List your permissions
|
||||
--quiet Do not print the header information
|
||||
""" % self.progname)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue