Unify error messages

Unify error messages for CLI

Unify error messages for hub

Fixes: https://pagure.io/koji/issue/2720
This commit is contained in:
Jana Cupova 2021-03-02 09:51:11 +01:00 committed by Tomas Kopecek
parent bbe5b4c703
commit e784373000
77 changed files with 2170 additions and 348 deletions

View file

@ -17,30 +17,34 @@ class TestRemoveGroup(utils.CliTestCase):
%s: error: {message}
""" % (self.progname, self.progname)
self.options = mock.MagicMock()
self.options.debug = False
self.session = mock.MagicMock()
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
def test_handle_remove_group_nonexistent_tag(self, activate_session_mock, stdout, stderr):
def test_handle_remove_group_nonexistent_tag(self, activate_session_mock, stderr, stdout):
tag = 'nonexistent-tag'
group = 'group'
arguments = [tag, group]
options = mock.MagicMock()
# Mock out the xmlrpc server
session = mock.MagicMock()
session.hasPerm.return_value = True
session.getTag.return_value = None
self.session.hasPerm.return_value = True
self.session.getTag.return_value = None
with self.assertRaises(SystemExit):
handle_remove_group(options, session, arguments)
expected = 'No such tag: %s\n' % tag
with self.assertRaises(SystemExit) as ex:
handle_remove_group(self.options, self.session, arguments)
self.assertExitCode(ex, 1)
self.assert_console_message(stderr, expected)
# assert that things were called as we expected.
activate_session_mock.assert_called_once_with(session, options)
session.hasPerm.assert_called_once_with('admin')
session.getTag.assert_called_once_with(tag)
session.getTagGroups.assert_not_called()
session.groupListRemove.assert_not_called()
activate_session_mock.assert_called_once_with(self.session, self.options)
self.session.hasPerm.assert_called_once_with('admin')
self.session.getTag.assert_called_once_with(tag)
self.session.getTagGroups.assert_not_called()
self.session.groupListRemove.assert_not_called()
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('sys.stderr', new_callable=six.StringIO)
@ -49,23 +53,21 @@ class TestRemoveGroup(utils.CliTestCase):
tag = 'tag'
group = 'group'
arguments = [tag, group]
options = mock.MagicMock()
# Mock out the xmlrpc server
session = mock.MagicMock()
session.hasPerm.return_value = True
session.getTag.return_value = tag
session.getTagGroups.return_value = []
self.session.hasPerm.return_value = True
self.session.getTag.return_value = tag
self.session.getTagGroups.return_value = []
with self.assertRaises(SystemExit):
handle_remove_group(options, session, arguments)
handle_remove_group(self.options, self.session, arguments)
# assert that things were called as we expected.
activate_session_mock.assert_called_once_with(session, options)
session.hasPerm.assert_called_once_with('admin')
session.getTag.assert_called_once_with(tag)
session.getTagGroups.assert_called_once_with(tag, inherit=False)
session.groupListRemove.assert_not_called()
activate_session_mock.assert_called_once_with(self.session, self.options)
self.session.hasPerm.assert_called_once_with('admin')
self.session.getTag.assert_called_once_with(tag)
self.session.getTagGroups.assert_called_once_with(tag, inherit=False)
self.session.groupListRemove.assert_not_called()
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('sys.stderr', new_callable=six.StringIO)
@ -74,45 +76,40 @@ class TestRemoveGroup(utils.CliTestCase):
tag = 'tag'
group = 'group'
arguments = [tag, group]
options = mock.MagicMock()
# Mock out the xmlrpc server
session = mock.MagicMock()
session.hasPerm.return_value = True
session.getTag.return_value = tag
session.getTagGroups.return_value = [
self.session.hasPerm.return_value = True
self.session.getTag.return_value = tag
self.session.getTagGroups.return_value = [
{'name': 'group', 'group_id': 'groupId'}]
rv = handle_remove_group(options, session, arguments)
rv = handle_remove_group(self.options, self.session, arguments)
# assert that things were called as we expected.
activate_session_mock.assert_called_once_with(session, options)
session.hasPerm.assert_called_once_with('admin')
session.getTag.assert_called_once_with(tag)
session.getTagGroups.assert_called_once_with(tag, inherit=False)
session.groupListRemove.assert_called_once_with(tag, group)
activate_session_mock.assert_called_once_with(self.session, self.options)
self.session.hasPerm.assert_called_once_with('admin')
self.session.getTag.assert_called_once_with(tag)
self.session.getTagGroups.assert_called_once_with(tag, inherit=False)
self.session.groupListRemove.assert_called_once_with(tag, group)
self.assertEqual(rv, None)
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
def test_handle_remove_group_error_handling(self, activate_session_mock, stdout, stderr):
session = mock.MagicMock()
options = mock.MagicMock()
expected = self.format_error_message(
"Please specify a tag name and a group name")
for args in [[], ['tag'], ['tag', 'grp', 'etc']]:
self.assert_system_exit(
handle_remove_group,
options,
session,
self.options,
self.session,
args,
stderr=expected,
activate_session=None)
# if we don't have 'tag' permission
session.hasPerm.return_value = False
self.session.hasPerm.return_value = False
with self.assertRaises(SystemExit):
handle_remove_group(options, session, ['tag', 'grp'])
activate_session_mock.assert_called_with(session, options)
handle_remove_group(self.options, self.session, ['tag', 'grp'])
activate_session_mock.assert_called_with(self.session, self.options)