change handle_remove_pkg to multicall
This commit is contained in:
parent
f5d070384f
commit
aede0d752f
2 changed files with 237 additions and 1 deletions
6
cli/koji
6
cli/koji
|
|
@ -850,6 +850,9 @@ def handle_remove_pkg(options, session, args):
|
|||
opts['force'] = options.force
|
||||
# check if list of packages exists for that tag already
|
||||
dsttag=session.getTag(tag)
|
||||
if dsttag is None:
|
||||
print "No such tag: %s" % tag
|
||||
return 1
|
||||
pkglist = dict([(p['package_name'], p['package_id']) for p in session.listPackages(tagID=dsttag['id'])])
|
||||
ret = 0
|
||||
for package in args[1:]:
|
||||
|
|
@ -859,9 +862,10 @@ def handle_remove_pkg(options, session, args):
|
|||
ret = 1
|
||||
if ret:
|
||||
return ret
|
||||
session.multicall = True
|
||||
for package in args[1:]:
|
||||
#really should implement multicall...
|
||||
session.packageListRemove(tag, package, **opts)
|
||||
session.multiCall(strict=True)
|
||||
|
||||
def _unique_path(prefix):
|
||||
"""Create a unique path fragment by appending a path component
|
||||
|
|
|
|||
232
tests/test_cli/test_remove_pkg.py
Normal file
232
tests/test_cli/test_remove_pkg.py
Normal file
|
|
@ -0,0 +1,232 @@
|
|||
import unittest
|
||||
|
||||
|
||||
import StringIO as stringio
|
||||
|
||||
import os
|
||||
|
||||
import sys
|
||||
|
||||
import mock
|
||||
|
||||
from mock import call
|
||||
|
||||
import loadcli
|
||||
|
||||
cli = loadcli.cli
|
||||
|
||||
|
||||
class TestRemovePkg(unittest.TestCase):
|
||||
|
||||
# Show long diffs in error output...
|
||||
maxDiff = None
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=stringio.StringIO)
|
||||
@mock.patch('koji_cli.activate_session')
|
||||
def test_handle_remove_pkg(self, activate_session_mock, stdout):
|
||||
tag = 'tag'
|
||||
dsttag = {'name': tag, 'id': 1}
|
||||
package = 'package'
|
||||
args = [tag, package]
|
||||
kwargs = {'force': None}
|
||||
options = mock.MagicMock()
|
||||
|
||||
# Mock out the xmlrpc server
|
||||
session = mock.MagicMock()
|
||||
|
||||
session.getTag.return_value = dsttag
|
||||
session.listPackages.return_value = [
|
||||
{'package_name': package, 'package_id': 1}]
|
||||
# Run it and check immediate output
|
||||
# args: tag, package
|
||||
# expected: success
|
||||
rv = cli.handle_remove_pkg(options, session, args)
|
||||
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)
|
||||
session.getTag.assert_called_once_with(tag)
|
||||
session.listPackages.assert_called_once_with(
|
||||
tagID=dsttag['id'])
|
||||
session.packageListRemove.assert_called_once_with(
|
||||
tag, package, **kwargs)
|
||||
session.multiCall.assert_called_once_with(strict=True)
|
||||
self.assertNotEqual(rv, 1)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=stringio.StringIO)
|
||||
@mock.patch('koji_cli.activate_session')
|
||||
def test_handle_remove_pkg_multi_pkg(self, activate_session_mock, stdout):
|
||||
tag = 'tag'
|
||||
dsttag = {'name': tag, 'id': 1}
|
||||
packages = ['package1', 'package2', 'package3']
|
||||
args = [tag] + packages
|
||||
kwargs = {'force': None}
|
||||
options = mock.MagicMock()
|
||||
|
||||
# Mock out the xmlrpc server
|
||||
session = mock.MagicMock()
|
||||
|
||||
session.getTag.return_value = dsttag
|
||||
session.listPackages.return_value = [
|
||||
{'package_name': 'package1', 'package_id': 1},
|
||||
{'package_name': 'package2', 'package_id': 2},
|
||||
{'package_name': 'package3', 'package_id': 3},
|
||||
{'package_name': 'other_package', 'package_id': 4}
|
||||
]
|
||||
# Run it and check immediate output
|
||||
# args: tag, package1, package2, package3
|
||||
# expected: success
|
||||
rv = cli.handle_remove_pkg(options, session, args)
|
||||
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)
|
||||
self.assertEqual(
|
||||
session.mock_calls, [
|
||||
call.getTag(tag), call.listPackages(
|
||||
tagID=dsttag['id']), call.packageListRemove(
|
||||
tag, packages[0], **kwargs), call.packageListRemove(
|
||||
tag, packages[1], **kwargs), call.packageListRemove(
|
||||
tag, packages[2], **kwargs), call.multiCall(
|
||||
strict=True)])
|
||||
self.assertNotEqual(rv, 1)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=stringio.StringIO)
|
||||
@mock.patch('koji_cli.activate_session')
|
||||
def test_handle_remove_pkg_force(self, activate_session_mock, stdout):
|
||||
tag = 'tag'
|
||||
dsttag = {'name': tag, 'id': 1}
|
||||
packages = ['package1', 'package2', 'package3']
|
||||
args = ['--force', tag] + packages
|
||||
kwargs = {'force': True}
|
||||
options = mock.MagicMock()
|
||||
|
||||
# Mock out the xmlrpc server
|
||||
session = mock.MagicMock()
|
||||
|
||||
session.getTag.return_value = dsttag
|
||||
session.listPackages.return_value = [
|
||||
{'package_name': 'package1', 'package_id': 1},
|
||||
{'package_name': 'package2', 'package_id': 2},
|
||||
{'package_name': 'package3', 'package_id': 3},
|
||||
{'package_name': 'other_package', 'package_id': 4}
|
||||
]
|
||||
# Run it and check immediate output
|
||||
# args: --force, tag, package1, package2, package3
|
||||
# expected: success
|
||||
rv = cli.handle_remove_pkg(options, session, args)
|
||||
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)
|
||||
self.assertEqual(
|
||||
session.mock_calls, [
|
||||
call.getTag(tag), call.listPackages(
|
||||
tagID=dsttag['id']), call.packageListRemove(
|
||||
tag, packages[0], **kwargs), call.packageListRemove(
|
||||
tag, packages[1], **kwargs), call.packageListRemove(
|
||||
tag, packages[2], **kwargs), call.multiCall(
|
||||
strict=True)])
|
||||
self.assertNotEqual(rv, 1)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=stringio.StringIO)
|
||||
@mock.patch('koji_cli.activate_session')
|
||||
def test_handle_remove_pkg_no_package(self, activate_session_mock, stdout):
|
||||
tag = 'tag'
|
||||
dsttag = {'name': tag, 'id': 1}
|
||||
packages = ['package1', 'package2', 'package3']
|
||||
args = [tag] + packages
|
||||
options = mock.MagicMock()
|
||||
|
||||
# Mock out the xmlrpc server
|
||||
session = mock.MagicMock()
|
||||
|
||||
session.getTag.return_value = dsttag
|
||||
session.listPackages.return_value = [
|
||||
{'package_name': 'package1', 'package_id': 1},
|
||||
{'package_name': 'package3', 'package_id': 3},
|
||||
{'package_name': 'other_package', 'package_id': 4}]
|
||||
# Run it and check immediate output
|
||||
# args: tag, package1, package2, package3
|
||||
# expected: failed: can not find package2 under tag
|
||||
rv = cli.handle_remove_pkg(options, session, args)
|
||||
actual = stdout.getvalue()
|
||||
expected = 'Package package2 is not in tag tag\n'
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
# Finally, assert that things were called as we expected.
|
||||
activate_session_mock.assert_called_once_with(session)
|
||||
session.getTag.assert_called_once_with(tag)
|
||||
session.listPackages.assert_called_once_with(
|
||||
tagID=dsttag['id'])
|
||||
session.packageListRemove.assert_not_called()
|
||||
session.multiCall.assert_not_called()
|
||||
self.assertEqual(rv, 1)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=stringio.StringIO)
|
||||
@mock.patch('koji_cli.activate_session')
|
||||
def test_handle_remove_pkg_tag_no_exists(
|
||||
self, activate_session_mock, stdout):
|
||||
tag = 'tag'
|
||||
dsttag = None
|
||||
packages = ['package1', 'package2', 'package3']
|
||||
args = [tag] + packages
|
||||
options = mock.MagicMock()
|
||||
|
||||
# Mock out the xmlrpc server
|
||||
session = mock.MagicMock()
|
||||
|
||||
session.getTag.return_value = dsttag
|
||||
# Run it and check immediate output
|
||||
# args: tag, package1, package2, package3
|
||||
# expected: failed: tag does not exist
|
||||
rv = cli.handle_remove_pkg(options, session, args)
|
||||
actual = stdout.getvalue()
|
||||
expected = 'No such tag: tag\n'
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
# Finally, assert that things were called as we expected.
|
||||
activate_session_mock.assert_called_once_with(session)
|
||||
session.getTag.assert_called_once_with(tag)
|
||||
session.listPackages.assert_not_called()
|
||||
session.packageListRemove.assert_not_called()
|
||||
self.assertEqual(rv, 1)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=stringio.StringIO)
|
||||
@mock.patch('sys.stderr', new_callable=stringio.StringIO)
|
||||
@mock.patch('koji_cli.activate_session')
|
||||
def test_handle_remove_pkg_help(
|
||||
self, activate_session_mock, stderr, stdout):
|
||||
args = []
|
||||
options = mock.MagicMock()
|
||||
|
||||
progname = os.path.basename(sys.argv[0]) or 'koji'
|
||||
|
||||
# Mock out the xmlrpc server
|
||||
session = mock.MagicMock()
|
||||
|
||||
# Run it and check immediate output
|
||||
with self.assertRaises(SystemExit) as cm:
|
||||
cli.handle_remove_pkg(options, session, args)
|
||||
actual_stdout = stdout.getvalue()
|
||||
actual_stderr = stderr.getvalue()
|
||||
expected_stdout = ''
|
||||
expected_stderr = """Usage: %s remove-pkg [options] tag package [package2 ...]
|
||||
(Specify the --help global option for a list of other help options)
|
||||
|
||||
%s: error: Please specify a tag and at least one package
|
||||
""" % (progname, progname)
|
||||
self.assertMultiLineEqual(actual_stdout, expected_stdout)
|
||||
self.assertMultiLineEqual(actual_stderr, expected_stderr)
|
||||
|
||||
# Finally, assert that things were called as we expected.
|
||||
activate_session_mock.assert_not_called()
|
||||
session.getTag.assert_not_called()
|
||||
session.listPackages.assert_not_called()
|
||||
session.packageListRemove.assert_not_called()
|
||||
self.assertEqual(cm.exception.code, 2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue