Increase CLI test cases

This commit is contained in:
Jana Cupova 2022-03-02 21:46:40 +01:00 committed by Tomas Kopecek
parent ba407086fb
commit a8f11fbf9c
39 changed files with 2899 additions and 1869 deletions

View file

@ -4,7 +4,6 @@ from __future__ import absolute_import
import unittest
import mock
import six
import koji
from koji_cli.commands import handle_edit_channel
@ -25,6 +24,12 @@ class TestEditChannel(utils.CliTestCase):
'description': self.description,
}
self.maxDiff = None
self.activate_session_mock = mock.patch('koji_cli.commands.activate_session').start()
self.error_format = """Usage: %s edit-channel [options] <old-name>
(Specify the --help global option for a list of other help options)
%s: error: {message}
""" % (self.progname, self.progname)
def tearDown(self):
mock.patch.stopall()
@ -43,82 +48,90 @@ Options:
--comment=COMMENT Comment of channel
""" % self.progname)
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
def test_handle_edit_channel_without_args(self, activate_session_mock, stderr):
with self.assertRaises(SystemExit) as ex:
handle_edit_channel(self.options, self.session, [])
self.assertExitCode(ex, 2)
actual = stderr.getvalue()
expected_stderr = """Usage: %s edit-channel [options] <old-name>
(Specify the --help global option for a list of other help options)
def test_handle_edit_channel_without_args(self):
expected = self.format_error_message("Incorrect number of arguments")
self.assert_system_exit(
handle_edit_channel,
self.options,
self.session,
[],
stderr=expected,
activate_session=None,
exit_code=2
)
self.activate_session_mock.assert_not_called()
self.session.getChannel.assert_not_called()
self.session.editChannel.assert_not_called()
self.session.getKojiVersion.assert_not_called()
%s: error: Incorrect number of arguments
""" % (self.progname, self.progname)
self.assertMultiLineEqual(actual, expected_stderr)
activate_session_mock.assert_not_called()
@mock.patch('koji_cli.commands.activate_session')
def test_handle_edit_channel(self, activate_session_mock):
def test_handle_edit_channel(self):
handle_edit_channel(self.options, self.session,
[self.channel_old, '--name', self.channel_new,
'--description', self.description])
activate_session_mock.assert_called_once_with(self.session, self.options)
self.activate_session_mock.assert_called_once_with(self.session, self.options)
self.session.editChannel.assert_called_once_with(self.channel_old, name=self.channel_new,
description=self.description)
self.session.getChannel.assert_called_once_with(self.channel_old)
self.session.getKojiVersion.assert_not_called()
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
def test_handle_edit_channel_older_hub(self, activate_session_mock, stderr):
def test_handle_edit_channel_older_hub(self):
expected_api = 'Invalid method: editChannel'
expected = 'editChannel is available on hub from Koji 1.26 version, your version ' \
'is 1.25.1\n'
self.session.getKojiVersion.return_value = '1.25.1'
self.session.editChannel.side_effect = koji.GenericError(expected_api)
with self.assertRaises(SystemExit) as ex:
handle_edit_channel(self.options, self.session,
[self.channel_old, '--name', self.channel_new,
'--description', self.description])
self.assertExitCode(ex, 1)
actual = stderr.getvalue()
self.assertMultiLineEqual(actual, expected)
activate_session_mock.assert_called_once_with(self.session, self.options)
self.assert_system_exit(
handle_edit_channel,
self.options,
self.session,
[self.channel_old, '--name', self.channel_new, '--description', self.description],
stderr=expected,
activate_session=None,
exit_code=1
)
self.activate_session_mock.assert_called_once_with(self.session, self.options)
self.session.editChannel.assert_called_once_with(self.channel_old, name=self.channel_new,
description=self.description)
self.session.getChannel.assert_called_once_with(self.channel_old)
self.session.getKojiVersion.assert_called_once_with()
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
def test_handle_edit_channel_non_exist_channel(self, activate_session_mock, stderr):
def test_handle_edit_channel_non_exist_channel(self):
expected = 'No such channel: %s\n' % self.channel_old
channel_info = None
self.session.getChannel.return_value = channel_info
with self.assertRaises(SystemExit) as ex:
handle_edit_channel(self.options, self.session,
[self.channel_old, '--name', self.channel_new,
'--description', self.description])
self.assertExitCode(ex, 1)
actual = stderr.getvalue()
self.assertMultiLineEqual(actual, expected)
activate_session_mock.assert_called_once_with(self.session, self.options)
self.assert_system_exit(
handle_edit_channel,
self.options,
self.session,
[self.channel_old, '--name', self.channel_new, '--description', self.description],
stderr=expected,
activate_session=None,
exit_code=1
)
self.activate_session_mock.assert_called_once_with(self.session, self.options)
self.session.editChannel.assert_not_called()
self.session.getChannel.assert_called_once_with(self.channel_old)
self.session.getKojiVersion.assert_not_called()
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
def test_handle_edit_channel_non_result(self, activate_session_mock, stderr):
def test_handle_edit_channel_non_result(self):
expected = 'No changes made, please correct the command line\n'
self.session.getChannel.return_value = self.channel_info
self.session.editChannel.return_value = None
with self.assertRaises(SystemExit) as ex:
handle_edit_channel(self.options, self.session,
[self.channel_old, '--name', self.channel_new,
'--description', self.description])
self.assertExitCode(ex, 1)
actual = stderr.getvalue()
self.assertMultiLineEqual(actual, expected)
activate_session_mock.assert_called_once_with(self.session, self.options)
self.assert_system_exit(
handle_edit_channel,
self.options,
self.session,
[self.channel_old, '--name', self.channel_new, '--description', self.description],
stderr=expected,
activate_session=None,
exit_code=1
)
self.activate_session_mock.assert_called_once_with(self.session, self.options)
self.session.editChannel.assert_called_once_with(self.channel_old, name=self.channel_new,
description=self.description)
self.session.getChannel.assert_called_once_with(self.channel_old)
self.session.getKojiVersion.assert_not_called()
if __name__ == '__main__':