update cli tests
This commit is contained in:
parent
ac3f76a4de
commit
c02eb739aa
30 changed files with 667 additions and 695 deletions
|
|
@ -1,18 +1,14 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
|
||||
import mock
|
||||
import os
|
||||
import six
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
|
||||
import os
|
||||
|
||||
import sys
|
||||
|
||||
import mock
|
||||
import six
|
||||
|
||||
from . import loadcli
|
||||
|
||||
cli = loadcli.cli
|
||||
|
||||
from koji_cli.commands import handle_add_group
|
||||
|
||||
class TestAddGroup(unittest.TestCase):
|
||||
|
||||
|
|
@ -20,7 +16,7 @@ class TestAddGroup(unittest.TestCase):
|
|||
maxDiff = None
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||
@mock.patch('koji_cli.activate_session')
|
||||
@mock.patch('koji_cli.commands.activate_session')
|
||||
def test_handle_add_group(self, activate_session_mock, stdout):
|
||||
tag = 'tag'
|
||||
group = 'group'
|
||||
|
|
@ -35,13 +31,13 @@ class TestAddGroup(unittest.TestCase):
|
|||
{'name': 'otherGroup', 'group_id': 'otherGroupId'}]
|
||||
|
||||
# Run it and check immediate output
|
||||
rv = cli.handle_add_group(options, session, arguments)
|
||||
rv = handle_add_group(options, session, arguments)
|
||||
actual = stdout.getvalue()
|
||||
expected = ''
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
|
||||
# Finally, assert that things were called as we expected.
|
||||
activate_session_mock.assert_called_once_with(session)
|
||||
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)
|
||||
|
|
@ -49,7 +45,7 @@ class TestAddGroup(unittest.TestCase):
|
|||
self.assertNotEqual(rv, 1)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||
@mock.patch('koji_cli.activate_session')
|
||||
@mock.patch('koji_cli.commands.activate_session')
|
||||
def test_handle_add_group_dupl(self, activate_session_mock, stdout):
|
||||
tag = 'tag'
|
||||
group = 'group'
|
||||
|
|
@ -64,13 +60,13 @@ class TestAddGroup(unittest.TestCase):
|
|||
{'name': 'group', 'group_id': 'groupId'}]
|
||||
|
||||
# Run it and check immediate output
|
||||
rv = cli.handle_add_group(options, session, arguments)
|
||||
rv = handle_add_group(options, session, arguments)
|
||||
actual = stdout.getvalue()
|
||||
expected = 'Group group already exists for tag tag\n'
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
|
||||
# Finally, assert that things were called as we expected.
|
||||
activate_session_mock.assert_called_once_with(session)
|
||||
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)
|
||||
|
|
@ -79,7 +75,7 @@ class TestAddGroup(unittest.TestCase):
|
|||
|
||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||
@mock.patch('sys.stderr', new_callable=six.StringIO)
|
||||
@mock.patch('koji_cli.activate_session')
|
||||
@mock.patch('koji_cli.commands.activate_session')
|
||||
def test_handle_add_group_help(
|
||||
self,
|
||||
activate_session_mock,
|
||||
|
|
@ -93,7 +89,7 @@ class TestAddGroup(unittest.TestCase):
|
|||
|
||||
# Run it and check immediate output
|
||||
with self.assertRaises(SystemExit) as cm:
|
||||
rv = cli.handle_add_group(options, session, arguments)
|
||||
rv = handle_add_group(options, session, arguments)
|
||||
actual_stdout = stdout.getvalue()
|
||||
actual_stderr = stderr.getvalue()
|
||||
expected_stdout = ''
|
||||
|
|
@ -115,7 +111,7 @@ class TestAddGroup(unittest.TestCase):
|
|||
self.assertEqual(cm.exception.code, 2)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||
@mock.patch('koji_cli.activate_session')
|
||||
@mock.patch('koji_cli.commands.activate_session')
|
||||
def test_handle_add_group_no_perm(self, activate_session_mock, stdout):
|
||||
tag = 'tag'
|
||||
group = 'group'
|
||||
|
|
@ -127,13 +123,13 @@ class TestAddGroup(unittest.TestCase):
|
|||
session.hasPerm.return_value = False
|
||||
|
||||
# Run it and check immediate output
|
||||
rv = cli.handle_add_group(options, session, arguments)
|
||||
rv = handle_add_group(options, session, arguments)
|
||||
actual = stdout.getvalue()
|
||||
expected = 'This action requires admin privileges\n'
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
|
||||
# Finally, assert that things were called as we expected.
|
||||
activate_session_mock.assert_called_once_with(session)
|
||||
activate_session_mock.assert_called_once_with(session, options)
|
||||
session.hasPerm.assert_called_once_with('admin')
|
||||
session.getTag.assert_not_called()
|
||||
session.getTagGroups.assert_not_called()
|
||||
|
|
@ -141,7 +137,7 @@ class TestAddGroup(unittest.TestCase):
|
|||
self.assertEqual(rv, 1)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||
@mock.patch('koji_cli.activate_session')
|
||||
@mock.patch('koji_cli.commands.activate_session')
|
||||
def test_handle_add_group_no_tag(self, activate_session_mock, stdout):
|
||||
tag = 'tag'
|
||||
group = 'group'
|
||||
|
|
@ -154,13 +150,13 @@ class TestAddGroup(unittest.TestCase):
|
|||
session.getTag.return_value = None
|
||||
|
||||
# Run it and check immediate output
|
||||
rv = cli.handle_add_group(options, session, arguments)
|
||||
rv = handle_add_group(options, session, arguments)
|
||||
actual = stdout.getvalue()
|
||||
expected = 'Unknown tag: tag\n'
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
|
||||
# Finally, assert that things were called as we expected.
|
||||
activate_session_mock.assert_called_once_with(session)
|
||||
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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue