Increase CLI test cases
This commit is contained in:
parent
ba407086fb
commit
a8f11fbf9c
39 changed files with 2899 additions and 1869 deletions
|
|
@ -1,61 +1,58 @@
|
|||
from __future__ import absolute_import
|
||||
import mock
|
||||
import six
|
||||
import unittest
|
||||
import koji
|
||||
|
||||
from koji_cli.commands import handle_enable_user
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestEnableUser(utils.CliTestCase):
|
||||
|
||||
# Show long diffs in error output...
|
||||
maxDiff = None
|
||||
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
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 enable-user <username>
|
||||
(Specify the --help global option for a list of other help options)
|
||||
|
||||
%s: error: {message}
|
||||
""" % (self.progname, self.progname)
|
||||
self.username = 'user'
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||
@mock.patch('koji_cli.commands.activate_session')
|
||||
def test_handle_enable_user(
|
||||
self,
|
||||
activate_session_mock,
|
||||
stdout):
|
||||
def test_handle_enable_user_no_argument(self):
|
||||
"""Test handle_enable_user function"""
|
||||
session = mock.MagicMock()
|
||||
options = mock.MagicMock()
|
||||
username = 'user'
|
||||
|
||||
# Case 1. no argument error
|
||||
expected = self.format_error_message(
|
||||
"You must specify the username of the user to enable")
|
||||
expected = self.format_error_message("You must specify the username of the user to enable")
|
||||
self.assert_system_exit(
|
||||
handle_enable_user,
|
||||
options,
|
||||
session,
|
||||
self.options,
|
||||
self.session,
|
||||
[],
|
||||
stderr=expected,
|
||||
activate_session=None)
|
||||
self.activate_session_mock.assert_not_called()
|
||||
self.session.enableUser.assert_not_called()
|
||||
|
||||
# Case 2. Too many argument error
|
||||
expected = self.format_error_message(
|
||||
"This command only accepts one argument (username)")
|
||||
def test_handle_enable_user_to_many_arguments(self):
|
||||
"""Test handle_enable_user function"""
|
||||
expected = self.format_error_message("This command only accepts one argument (username)")
|
||||
self.assert_system_exit(
|
||||
handle_enable_user,
|
||||
options,
|
||||
session,
|
||||
self.options,
|
||||
self.session,
|
||||
['user-1', 'user-2', 'user-3'],
|
||||
stderr=expected,
|
||||
activate_session=None)
|
||||
self.activate_session_mock.assert_not_called()
|
||||
self.session.enableUser.assert_not_called()
|
||||
|
||||
# Case 3. Enable user test
|
||||
handle_enable_user(options, session, [username])
|
||||
session.enableUser.assert_called_with(username)
|
||||
activate_session_mock.assert_called_with(session, options)
|
||||
def test_handle_enable_user_valid(self):
|
||||
"""Test handle_enable_user function"""
|
||||
handle_enable_user(self.options, self.session, [self.username])
|
||||
self.session.enableUser.assert_called_with(self.username)
|
||||
self.activate_session_mock.assert_called_with(self.session, self.options)
|
||||
self.session.enableUser.assert_called_with(self.username)
|
||||
|
||||
def test_handle_enable_user_help(self):
|
||||
self.assert_help(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue