Increase CLI test cases
This commit is contained in:
parent
ba407086fb
commit
a8f11fbf9c
39 changed files with 2899 additions and 1869 deletions
|
|
@ -1,8 +1,6 @@
|
|||
from __future__ import absolute_import
|
||||
import koji
|
||||
import mock
|
||||
import unittest
|
||||
from six.moves import StringIO
|
||||
|
||||
from koji_cli.commands import handle_edit_notification
|
||||
from . import utils
|
||||
|
|
@ -14,108 +12,150 @@ class TestEditNotification(utils.CliTestCase):
|
|||
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-notification [options] <notification_id>
|
||||
(Specify the --help global option for a list of other help options)
|
||||
|
||||
%s: error: {message}
|
||||
""" % (self.progname, self.progname)
|
||||
|
||||
@mock.patch('koji_cli.commands.activate_session')
|
||||
def test_handle_edit_notification(self, activate_session_mock):
|
||||
def test_handle_edit_notification(self):
|
||||
self.session.getPackageID.return_value = 1234
|
||||
self.session.getTagID.return_value = 4321
|
||||
self.session.getBuildNotification.return_value = {'id': 2345}
|
||||
|
||||
handle_edit_notification(self.options, self.session,
|
||||
['--package', 'pkg_a', '--tag', 'tag_a', '--success-only', '2345'])
|
||||
['--package', 'pkg_a', '--tag', 'tag_a',
|
||||
'--success-only', '2345'])
|
||||
|
||||
self.session.getBuildNotification.assert_called_once_with(2345)
|
||||
self.session.getPackageID.assert_called_once_with('pkg_a')
|
||||
self.session.getTagID.assert_called_once_with('tag_a', strict=True)
|
||||
self.session.updateNotification.assert_called_once_with(2345, 1234, 4321, True)
|
||||
self.activate_session_mock.assert_called_once_with(self.session, self.options)
|
||||
|
||||
|
||||
@mock.patch('koji_cli.commands.activate_session')
|
||||
def test_handle_edit_notification_no_pkg(self, activate_session_mock):
|
||||
def test_handle_edit_notification_no_pkg(self):
|
||||
self.session.getBuildNotification.return_value = \
|
||||
{'id': 2345, 'package_id': 135, 'success_only': False}
|
||||
|
||||
handle_edit_notification(self.options, self.session,
|
||||
['--tag', '*', '2345'])
|
||||
handle_edit_notification(self.options, self.session, ['--tag', '*', '2345'])
|
||||
|
||||
self.session.getPackageID.assert_not_called()
|
||||
self.session.getTagID.assert_not_called()
|
||||
self.session.updateNotification.assert_called_once_with(2345, 135, None, False)
|
||||
self.session.getBuildNotification.assert_called_once_with(2345)
|
||||
self.activate_session_mock.assert_called_once_with(self.session, self.options)
|
||||
|
||||
|
||||
@mock.patch('koji_cli.commands.activate_session')
|
||||
def test_handle_edit_notification_no_tag(self, activate_session_mock):
|
||||
def test_handle_edit_notification_no_tag(self):
|
||||
self.session.getBuildNotification.return_value = \
|
||||
{'id': 2345, 'tag_id': 135, 'success_only': True}
|
||||
|
||||
handle_edit_notification(self.options, self.session,
|
||||
['--package', '*', '--no-success-only', '2345'])
|
||||
['--package', '*', '--no-success-only', '2345'])
|
||||
|
||||
self.session.getPackageID.assert_not_called()
|
||||
self.session.getTagID.assert_not_called()
|
||||
self.session.updateNotification.assert_called_once_with(2345, None, 135, False)
|
||||
self.session.getBuildNotification.assert_called_once_with(2345)
|
||||
self.activate_session_mock.assert_called_once_with(self.session, self.options)
|
||||
|
||||
def test_handle_edit_notification_bogus(self):
|
||||
expected = self.format_error_message("Notification ID has to be numeric")
|
||||
self.assert_system_exit(
|
||||
handle_edit_notification,
|
||||
self.options,
|
||||
self.session,
|
||||
['bogus'],
|
||||
stdout='',
|
||||
stderr=expected,
|
||||
activate_session=None,
|
||||
exit_code=2
|
||||
)
|
||||
self.session.updateNotification.assert_not_called()
|
||||
self.session.getPackageID.assert_not_called()
|
||||
self.session.getTagID.assert_not_called()
|
||||
self.session.getBuildNotification.assert_not_called()
|
||||
self.activate_session_mock.assert_not_called()
|
||||
|
||||
@mock.patch('sys.exit')
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_handle_edit_notification_bogus(self, sys_stderr, sys_exit):
|
||||
sys_exit.side_effect = SystemExit()
|
||||
|
||||
with self.assertRaises(SystemExit):
|
||||
handle_edit_notification(self.options, self.session, ['bogus'])
|
||||
def test_handle_edit_notification_no_id(self):
|
||||
expected = self.format_error_message("Only argument is notification ID")
|
||||
self.assert_system_exit(
|
||||
handle_edit_notification,
|
||||
self.options,
|
||||
self.session,
|
||||
[],
|
||||
stdout='',
|
||||
stderr=expected,
|
||||
activate_session=None,
|
||||
exit_code=2
|
||||
)
|
||||
|
||||
self.session.updateNotification.assert_not_called()
|
||||
self.session.getPackageID.assert_not_called()
|
||||
self.session.getTagID.assert_not_called()
|
||||
self.session.getBuildNotification.assert_not_called()
|
||||
self.activate_session_mock.assert_not_called()
|
||||
|
||||
|
||||
@mock.patch('sys.exit')
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_handle_edit_notification_no_id(self, sys_stderr, sys_exit):
|
||||
sys_exit.side_effect = SystemExit()
|
||||
|
||||
with self.assertRaises(SystemExit):
|
||||
handle_edit_notification(self.options, self.session, [])
|
||||
def test_handle_edit_notification_no_opts(self):
|
||||
expected = self.format_error_message("Command need at least one option")
|
||||
self.assert_system_exit(
|
||||
handle_edit_notification,
|
||||
self.options,
|
||||
self.session,
|
||||
['123'],
|
||||
stdout='',
|
||||
stderr=expected,
|
||||
activate_session=None,
|
||||
exit_code=2
|
||||
)
|
||||
|
||||
self.session.updateNotification.assert_not_called()
|
||||
self.session.getPackageID.assert_not_called()
|
||||
self.session.getTagID.assert_not_called()
|
||||
self.session.getBuildNotification.assert_not_called()
|
||||
self.activate_session_mock.assert_not_called()
|
||||
|
||||
|
||||
@mock.patch('sys.exit')
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_handle_edit_notification_no_opts(self, sys_stderr, sys_exit):
|
||||
sys_exit.side_effect = SystemExit()
|
||||
|
||||
with self.assertRaises(SystemExit):
|
||||
handle_edit_notification(self.options, self.session, ['123'])
|
||||
|
||||
self.session.updateNotification.assert_not_called()
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_handle_edit_notification_non_exist_tag(self, stderr):
|
||||
def test_handle_edit_notification_non_exist_tag(self):
|
||||
tag = 'test-tag'
|
||||
expected = "Usage: %s edit-notification [options] <notification_id>\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: No such tag: %s\n" % (self.progname, self.progname, tag)
|
||||
expected = self.format_error_message("No such tag: %s" % tag)
|
||||
|
||||
self.session.getBuildNotification.return_value = \
|
||||
{'id': 2345, 'package_id': 135, 'success_only': False}
|
||||
self.session.getTagID.side_effect = koji.GenericError
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_edit_notification(self.options, self.session, ['--tag', tag, '2345'])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
self.assert_system_exit(
|
||||
handle_edit_notification,
|
||||
self.options,
|
||||
self.session,
|
||||
['--tag', tag, '2345'],
|
||||
stdout='',
|
||||
stderr=expected,
|
||||
activate_session=None,
|
||||
exit_code=2
|
||||
)
|
||||
self.session.getPackageID.assert_not_called()
|
||||
self.session.getTagID.assert_called_once_with(tag, strict=True)
|
||||
self.session.getBuildNotification.assert_called_once_with(2345)
|
||||
self.session.updateNotification.assert_not_called()
|
||||
self.activate_session_mock.assert_called_once_with(self.session, self.options)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_handle_edit_notification_non_exist_pkg(self, stderr):
|
||||
def test_handle_edit_notification_non_exist_pkg(self):
|
||||
pkg = 'test-pkg'
|
||||
expected = "Usage: %s edit-notification [options] <notification_id>\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: No such package: %s\n" % (self.progname, self.progname, pkg)
|
||||
expected = self.format_error_message("No such package: %s" % pkg)
|
||||
self.session.getBuildNotification.return_value = \
|
||||
{'id': 2345, 'package_id': 135, 'success_only': False}
|
||||
self.session.getPackageID.return_value = None
|
||||
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_edit_notification(self.options, self.session, ['--package', pkg, '2345'])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
self.assert_system_exit(
|
||||
handle_edit_notification,
|
||||
self.options,
|
||||
self.session,
|
||||
['--package', pkg, '2345'],
|
||||
stdout='',
|
||||
stderr=expected,
|
||||
activate_session=None,
|
||||
exit_code=2
|
||||
)
|
||||
self.session.getPackageID.assert_called_once_with(pkg)
|
||||
self.session.getTagID.assert_not_called()
|
||||
self.session.getBuildNotification.assert_called_once_with(2345)
|
||||
self.session.updateNotification.assert_not_called()
|
||||
self.activate_session_mock.assert_called_once_with(self.session, self.options)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue