Unify error messages
Unify error messages for CLI Unify error messages for hub Fixes: https://pagure.io/koji/issue/2720
This commit is contained in:
parent
bbe5b4c703
commit
e784373000
77 changed files with 2170 additions and 348 deletions
|
|
@ -155,7 +155,7 @@ class TestAddGroup(utils.CliTestCase):
|
|||
handle_add_group(options, session, arguments)
|
||||
self.assertExitCode(ex, 1)
|
||||
actual = stderr.getvalue()
|
||||
expected = 'Unknown tag: tag\n'
|
||||
expected = 'No such tag: tag\n'
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
|
||||
# Finally, assert that things were called as we expected.
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
from __future__ import absolute_import
|
||||
import koji
|
||||
import mock
|
||||
import unittest
|
||||
from six.moves import StringIO
|
||||
|
||||
from koji_cli.commands import handle_add_notification
|
||||
from . import utils
|
||||
|
||||
class TestAddNotification(unittest.TestCase):
|
||||
class TestAddNotification(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.quiet = True
|
||||
|
|
@ -114,3 +114,29 @@ class TestAddNotification(unittest.TestCase):
|
|||
handle_add_notification(self.options, self.session, ['bogus'])
|
||||
|
||||
self.session.createNotification.assert_not_called()
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_handle_add_notification_non_exist_tag(self, stderr):
|
||||
tag = 'tag_a'
|
||||
expected = "Usage: %s add-notification [options]\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)
|
||||
|
||||
self.session.getTagID.side_effect = koji.GenericError
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_add_notification(self.options, self.session, ['--tag', tag])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_handle_add_notification_non_exist_pkg(self, stderr):
|
||||
pkg = 'pkg_a'
|
||||
expected = "Usage: %s add-notification [options]\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)
|
||||
|
||||
self.session.getPackageID.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_add_notification(self.options, self.session, ['--package', pkg])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
import os
|
||||
import six
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
import six
|
||||
from mock import call
|
||||
|
||||
from koji_cli.commands import handle_add_pkg
|
||||
|
|
@ -133,7 +133,7 @@ class TestAddPkg(utils.CliTestCase):
|
|||
handle_add_pkg(options, session, args)
|
||||
self.assertExitCode(ex, 1)
|
||||
actual = stderr.getvalue()
|
||||
expected = 'User owner does not exist\n'
|
||||
expected = 'No such user: %s\n' % owner
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
# Finally, assert that things were called as we expected.
|
||||
activate_session_mock.assert_not_called()
|
||||
|
|
@ -168,7 +168,7 @@ class TestAddPkg(utils.CliTestCase):
|
|||
handle_add_pkg(options, session, args)
|
||||
self.assertExitCode(ex, 1)
|
||||
actual = stdout.getvalue()
|
||||
expected = 'No such tag: tag\n'
|
||||
expected = 'No such tag: %s\n' % tag
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
# Finally, assert that things were called as we expected.
|
||||
activate_session_mock.assert_called_once_with(session, options)
|
||||
|
|
|
|||
64
tests/test_cli/test_add_tag_inheritance.py
Normal file
64
tests/test_cli/test_add_tag_inheritance.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from six.moves import StringIO
|
||||
import mock
|
||||
|
||||
import koji
|
||||
from koji_cli.commands import handle_add_tag_inheritance
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestAddTagInheritance(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_add_tag_inheritance_without_option(self, stderr):
|
||||
expected = "Usage: %s add-tag-inheritance [options] <tag> <parent-tag>\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: This command takes exctly two argument: " \
|
||||
"a tag name or ID and that tag's new parent name " \
|
||||
"or ID\n" % (self.progname, self.progname)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_add_tag_inheritance(self.options, self.session, [])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_add_tag_inheritance_non_exist_tag(self, stderr):
|
||||
tag = 'test-tag'
|
||||
parent_tag = 'parent-test-tag'
|
||||
expected = "Usage: %s add-tag-inheritance [options] <tag> <parent-tag>\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)
|
||||
self.session.getTag.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_add_tag_inheritance(self.options, self.session, [tag, parent_tag])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_add_tag_inheritance_non_exist_parent_tag(self, stderr):
|
||||
side_effect_result = [{'arches': 'x86_64',
|
||||
'extra': {},
|
||||
'id': 1,
|
||||
'locked': False,
|
||||
'maven_include_all': False,
|
||||
'maven_support': False,
|
||||
'name': 'test-tag',
|
||||
'perm': None,
|
||||
'perm_id': None},
|
||||
None]
|
||||
tag = 'test-tag'
|
||||
parent_tag = 'parent-test-tag'
|
||||
expected = "Usage: %s add-tag-inheritance [options] <tag> <parent-tag>\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, parent_tag)
|
||||
self.session.getTag.side_effect = side_effect_result
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_add_tag_inheritance(self.options, self.session, [tag, parent_tag])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
85
tests/test_cli/test_add_target.py
Normal file
85
tests/test_cli/test_add_target.py
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
from koji_cli.commands import handle_add_target
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestAddTarget(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_add_target_without_option(self, stderr):
|
||||
expected = "Usage: %s add-target <name> <build tag> <dest tag>\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: Please specify a target name, a build tag, " \
|
||||
"and destination tag\n" % (self.progname, self.progname)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_add_target(self.options, self.session, [])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_add_target_non_exist_tag(self, stderr):
|
||||
target = 'test-target'
|
||||
tag = 'test-tag'
|
||||
dest_tag = 'test-dest-tag'
|
||||
expected = "No such tag: %s\n" % tag
|
||||
self.session.getTag.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_add_target(self.options, self.session, [target, tag, dest_tag])
|
||||
self.assertExitCode(ex, 1)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_add_target_tag_without_arch(self, stderr):
|
||||
tag_info = {'arches': None,
|
||||
'extra': {},
|
||||
'id': 1,
|
||||
'locked': False,
|
||||
'maven_include_all': False,
|
||||
'maven_support': False,
|
||||
'name': 'test-tag',
|
||||
'perm': None,
|
||||
'perm_id': None}
|
||||
target = 'test-target'
|
||||
tag = 'test-tag'
|
||||
dest_tag = 'test-dest-tag'
|
||||
expected = "Build tag has no arches: %s\n" % tag
|
||||
self.session.getTag.return_value = tag_info
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_add_target(self.options, self.session, [target, tag, dest_tag])
|
||||
self.assertExitCode(ex, 1)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_add_target_non_exist_dest_tag(self, stderr):
|
||||
side_effect_result = [{'arches': 'x86_64',
|
||||
'extra': {},
|
||||
'id': 1,
|
||||
'locked': False,
|
||||
'maven_include_all': False,
|
||||
'maven_support': False,
|
||||
'name': 'test-tag',
|
||||
'perm': None,
|
||||
'perm_id': None
|
||||
},
|
||||
None,
|
||||
]
|
||||
|
||||
target = 'test-target'
|
||||
tag = 'test-tag'
|
||||
dest_tag = 'test-dest-tag'
|
||||
expected = "No such destination tag: %s\n" % dest_tag
|
||||
self.session.getTag.side_effect = side_effect_result
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_add_target(self.options, self.session, [target, tag, dest_tag])
|
||||
self.assertExitCode(ex, 1)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
|
@ -36,7 +36,7 @@ class TestBlockGroup(utils.CliTestCase):
|
|||
handle_block_group(options, session, arguments)
|
||||
self.assertExitCode(ex, 1)
|
||||
actual = stderr.getvalue()
|
||||
expected = 'Unknown tag: %s\n' % tag
|
||||
expected = 'No such tag: %s\n' % tag
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
|
||||
# Finally, assert that things were called as we expected.
|
||||
|
|
|
|||
41
tests/test_cli/test_block_notification.py
Normal file
41
tests/test_cli/test_block_notification.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
from __future__ import absolute_import
|
||||
import koji
|
||||
import mock
|
||||
from six.moves import StringIO
|
||||
|
||||
from koji_cli.commands import handle_block_notification
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestBlockNotification(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_handle_block_notification_non_exist_tag(self, stderr):
|
||||
tag = 'test-tag'
|
||||
expected = "Usage: %s block-notification [options]\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)
|
||||
|
||||
self.session.getTagID.side_effect = koji.GenericError
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_block_notification(self.options, self.session, ['--tag', tag])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_handle_block_notification_non_exist_pkg(self, stderr):
|
||||
pkg = 'test-pkg'
|
||||
expected = "Usage: %s block-notification [options]\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)
|
||||
|
||||
self.session.getPackageID.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_block_notification(self.options, self.session, ['--package', pkg])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
from __future__ import absolute_import
|
||||
import mock
|
||||
|
||||
import os
|
||||
import six
|
||||
import sys
|
||||
|
||||
import mock
|
||||
import six
|
||||
from mock import call
|
||||
|
||||
from koji_cli.commands import handle_block_pkg
|
||||
|
|
@ -140,7 +141,7 @@ class TestBlockPkg(utils.CliTestCase):
|
|||
handle_block_pkg(options, session, args)
|
||||
self.assertExitCode(ex, 1)
|
||||
actual = stderr.getvalue()
|
||||
expected = 'No such tag: tag\n'
|
||||
expected = 'No such tag: %s\n' % tag
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
# Finally, assert that things were called as we expected.
|
||||
activate_session_mock.assert_called_once_with(session, options)
|
||||
|
|
|
|||
|
|
@ -357,7 +357,7 @@ Task info: weburl/taskinfo?taskID=1
|
|||
handle_build(self.options, self.session, args)
|
||||
self.assertExitCode(ex, 2)
|
||||
actual = stderr.getvalue()
|
||||
expected = self.format_error_message( "Unknown build target: target")
|
||||
expected = self.format_error_message( "No such build target: target")
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
# Finally, assert that things were called as we expected.
|
||||
activate_session_mock.assert_called_once_with(self.session, self.options)
|
||||
|
|
@ -401,7 +401,7 @@ Task info: weburl/taskinfo?taskID=1
|
|||
handle_build(self.options, self.session, args)
|
||||
self.assertExitCode(ex, 2)
|
||||
actual = stderr.getvalue()
|
||||
expected = self.format_error_message("Unknown destination tag: dest_tag_name")
|
||||
expected = self.format_error_message("No such destination tag: dest_tag_name")
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
# Finally, assert that things were called as we expected.
|
||||
activate_session_mock.assert_called_once_with(self.session, self.options)
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ Options:
|
|||
expected = """Usage: %s chain-build [options] <target> <URL> [<URL> [:] <URL> [:] <URL> ...]
|
||||
(Specify the --help global option for a list of other help options)
|
||||
|
||||
%s: error: Unknown build target: target
|
||||
%s: error: No such build target: target
|
||||
""" % (progname, progname)
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
# Finally, assert that things were called as we expected.
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ clone-tag will create the destination tag if it does not already exist
|
|||
self.options,
|
||||
self.session,
|
||||
args,
|
||||
stderr=self.format_error_message("Unknown src-tag: src-tag"),
|
||||
stderr=self.format_error_message("No such src-tag: src-tag"),
|
||||
activate_session=None)
|
||||
self.activate_session.assert_called_once()
|
||||
self.activate_session.getTag.has_called([call('src-tag'),
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
|
||||
import unittest
|
||||
import copy
|
||||
|
||||
import mock
|
||||
import six
|
||||
import unittest
|
||||
|
||||
|
||||
from koji_cli.commands import handle_dist_repo
|
||||
from . import utils
|
||||
|
|
@ -26,7 +27,7 @@ class TestDistRepo(utils.CliTestCase):
|
|||
'arches': 'x86_64',
|
||||
'maven_include_all': False,
|
||||
'perm_id': None
|
||||
}
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
self.task_id = 1001
|
||||
|
|
@ -91,10 +92,10 @@ via 'koji edit-tag -x distrepo.cancel_others=True'
|
|||
arguments = [self.tag_name, self.fake_key]
|
||||
self.__run_test_handle_dist_repo(arguments, True)
|
||||
self.watch_tasks.assert_called_with(
|
||||
self.session,
|
||||
[self.task_id],
|
||||
quiet=self.options.quiet,
|
||||
poll_interval=self.options.poll_interval, topurl=self.options.topurl)
|
||||
self.session,
|
||||
[self.task_id],
|
||||
quiet=self.options.quiet,
|
||||
poll_interval=self.options.poll_interval, topurl=self.options.topurl)
|
||||
|
||||
def test_handle_dist_repo_nowait(self):
|
||||
arguments = [self.tag_name, self.fake_key, '--nowait']
|
||||
|
|
@ -120,7 +121,8 @@ via 'koji edit-tag -x distrepo.cancel_others=True'
|
|||
'--allow-missing-signatures',
|
||||
'--skip-missing-signatures'
|
||||
],
|
||||
'err_str': 'allow_missing_signatures and skip_missing_signatures are mutually exclusive'
|
||||
'err_str': 'allow_missing_signatures and skip_missing_signatures are mutually '
|
||||
'exclusive'
|
||||
}
|
||||
]
|
||||
|
||||
|
|
@ -137,7 +139,7 @@ via 'koji edit-tag -x distrepo.cancel_others=True'
|
|||
|
||||
# Case 2. Tag Error
|
||||
self.session.getTag.return_value = {}
|
||||
expected = self.format_error_message('unknown tag %s' % self.tag_name)
|
||||
expected = self.format_error_message('No such tag: %s' % self.tag_name)
|
||||
self.assert_system_exit(
|
||||
handle_dist_repo,
|
||||
self.options,
|
||||
|
|
@ -218,7 +220,7 @@ via 'koji edit-tag -x distrepo.cancel_others=True'
|
|||
stderr=expected)
|
||||
|
||||
# normal case
|
||||
self.session.uploadWrapper = lambda *args, **kwargs: print ('uploadWrapper ...')
|
||||
self.session.uploadWrapper = lambda *args, **kwargs: print('uploadWrapper ...')
|
||||
self.session.getTag.return_value.update({'arches': 'x86_64, i686'})
|
||||
expected = 'uploadWrapper ...\n\n'
|
||||
arguments += ['--arch', 'x86_64', '--arch', 'i686']
|
||||
|
|
@ -234,11 +236,11 @@ via 'koji edit-tag -x distrepo.cancel_others=True'
|
|||
self.session.getRepo.return_value = {}
|
||||
expected = self.format_error_message("Can't find repo for tag: %s" % "test-repo1")
|
||||
self.assert_system_exit(
|
||||
handle_dist_repo,
|
||||
self.options,
|
||||
self.session,
|
||||
arguments,
|
||||
stderr=expected)
|
||||
handle_dist_repo,
|
||||
self.options,
|
||||
self.session,
|
||||
arguments,
|
||||
stderr=expected)
|
||||
|
||||
# Normal case, assume test-repo2 is expired
|
||||
self.session.getRepo.side_effect = [
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
from mock import call
|
||||
import six
|
||||
|
||||
from . import utils
|
||||
from koji_cli.commands import anon_handle_download_logs
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestDownloadLogs(utils.CliTestCase):
|
||||
def mock_builtin_open(self, filepath, *args):
|
||||
|
|
@ -19,7 +20,8 @@ class TestDownloadLogs(utils.CliTestCase):
|
|||
self.options.topurl = 'https://topurl'
|
||||
# Mock out the xmlrpc server
|
||||
self.session = mock.MagicMock()
|
||||
self.list_task_output_all_volumes = mock.patch('koji_cli.commands.list_task_output_all_volumes').start()
|
||||
self.list_task_output_all_volumes = mock.patch(
|
||||
'koji_cli.commands.list_task_output_all_volumes').start()
|
||||
self.ensuredir = mock.patch('koji.ensuredir').start()
|
||||
self.download_file = mock.patch('koji_cli.commands.download_file').start()
|
||||
self.activate_session = mock.patch('koji_cli.commands.activate_session').start()
|
||||
|
|
@ -104,3 +106,12 @@ class TestDownloadLogs(utils.CliTestCase):
|
|||
mock.call(123456, 'file1.log', offset=5, size=102400, volume='volume1'),
|
||||
])
|
||||
|
||||
def test_anon_handle_download_logs_task_not_found(self):
|
||||
task_id = '123333'
|
||||
self.session.getTaskInfo.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_download_logs(self.options, self.session, [task_id])
|
||||
self.assertExitCode(ex, 1)
|
||||
actual = self.stderr.getvalue()
|
||||
expected = 'No such task: %s\n' % task_id
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
from __future__ import absolute_import
|
||||
import mock
|
||||
from mock import call
|
||||
|
||||
import os
|
||||
import six
|
||||
import sys
|
||||
|
||||
import mock
|
||||
import six
|
||||
from mock import call
|
||||
|
||||
from koji_cli.commands import anon_handle_download_task
|
||||
from . import utils
|
||||
|
||||
|
|
@ -34,7 +36,7 @@ class TestDownloadTask(utils.CliTestCase):
|
|||
if target.endswith('.log') and arch is not None:
|
||||
target = "%s.%s.log" % (target.rstrip(".log"), arch)
|
||||
calls.append(call(url, target, quiet=None, noprogress=None,
|
||||
size=total, num=i + 1))
|
||||
size=total, num=i + 1))
|
||||
return calls
|
||||
|
||||
def setUp(self):
|
||||
|
|
@ -44,7 +46,8 @@ class TestDownloadTask(utils.CliTestCase):
|
|||
self.options.topurl = 'https://topurl'
|
||||
# Mock out the xmlrpc server
|
||||
self.session = mock.MagicMock()
|
||||
self.list_task_output_all_volumes = mock.patch('koji_cli.commands.list_task_output_all_volumes').start()
|
||||
self.list_task_output_all_volumes = mock.patch(
|
||||
'koji_cli.commands.list_task_output_all_volumes').start()
|
||||
self.ensuredir = mock.patch('koji.ensuredir').start()
|
||||
self.download_file = mock.patch('koji_cli.commands.download_file').start()
|
||||
self.ensure_connection = mock.patch('koji_cli.commands.ensure_connection').start()
|
||||
|
|
@ -102,7 +105,7 @@ class TestDownloadTask(utils.CliTestCase):
|
|||
expected = ''
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
actual = self.stderr.getvalue()
|
||||
expected = 'No such task: #123333\n'
|
||||
expected = 'No such task: %s\n' % task_id
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
# Finally, assert that things were called as we expected.
|
||||
self.ensure_connection.assert_called_once_with(self.session, self.options)
|
||||
|
|
|
|||
|
|
@ -5,8 +5,10 @@ import unittest
|
|||
from six.moves import StringIO
|
||||
|
||||
from koji_cli.commands import handle_edit_notification
|
||||
from . import utils
|
||||
|
||||
class TestEditNotification(unittest.TestCase):
|
||||
|
||||
class TestEditNotification(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
|
|
@ -87,3 +89,33 @@ class TestEditNotification(unittest.TestCase):
|
|||
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):
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_handle_edit_notification_non_exist_pkg(self, stderr):
|
||||
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)
|
||||
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)
|
||||
|
|
|
|||
67
tests/test_cli/test_edit_tag_inheritance.py
Normal file
67
tests/test_cli/test_edit_tag_inheritance.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
from koji_cli.commands import handle_edit_tag_inheritance
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestEditTagInheritance(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_edit_tag_inheritance_without_option(self, stderr):
|
||||
expected = "Usage: %s edit-tag-inheritance [options] <tag> <parent> <priority>\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: This command takes at least one argument: " \
|
||||
"a tag name or ID\n" % (self.progname, self.progname)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_edit_tag_inheritance(self.options, self.session, [])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_edit_tag_inheritance_non_exist_tag(self, stderr):
|
||||
tag = 'test-tag'
|
||||
parent_tag = 'parent-test-tag'
|
||||
priority = '99'
|
||||
expected = "Usage: %s edit-tag-inheritance [options] <tag> <parent> <priority>\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)
|
||||
self.session.getTag.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_edit_tag_inheritance(self.options, self.session,
|
||||
[tag, parent_tag, priority])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_edit_tag_inheritance_non_exist_parent_tag(self, stderr):
|
||||
side_effect_result = [{'arches': 'x86_64',
|
||||
'extra': {},
|
||||
'id': 1,
|
||||
'locked': False,
|
||||
'maven_include_all': False,
|
||||
'maven_support': False,
|
||||
'name': 'test-tag',
|
||||
'perm': None,
|
||||
'perm_id': None},
|
||||
None]
|
||||
tag = 'test-tag'
|
||||
parent_tag = 'parent-test-tag'
|
||||
priority = '99'
|
||||
expected = "Usage: %s edit-tag-inheritance [options] <tag> <parent> <priority>\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, parent_tag)
|
||||
self.session.getTag.side_effect = side_effect_result
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_edit_tag_inheritance(self.options, self.session,
|
||||
[tag, parent_tag, priority])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
48
tests/test_cli/test_edit_target.py
Normal file
48
tests/test_cli/test_edit_target.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
from koji_cli.commands import handle_edit_target
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestEditTarget(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_edit_target_without_option(self, stderr):
|
||||
expected = "Usage: %s edit-target [options] <name>\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: Please specify a build target\n" % (self.progname, self.progname)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_edit_target(self.options, self.session, [])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
def test_edit_target_non_exist_target(self):
|
||||
target = 'test-target'
|
||||
expected = "No such build target: %s" % target
|
||||
self.session.getBuildTarget.return_value = None
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
handle_edit_target(self.options, self.session, [target])
|
||||
self.assertEqual(expected, str(cm.exception))
|
||||
self.session.getTag.assert_not_called()
|
||||
self.session.editBuildTarget.assert_not_called()
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_edit_target_non_exist_dest_tag(self, stderr):
|
||||
target = 'test-target'
|
||||
dest_tag = 'test-dest-tag'
|
||||
expected = "No such destination tag: %s\n" % dest_tag
|
||||
self.session.getTag.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_edit_target(self.options, self.session, ['--dest-tag', dest_tag, target])
|
||||
self.assertExitCode(ex, 1)
|
||||
self.assert_console_message(stderr, expected)
|
||||
self.session.editBuildTarget.assert_not_called()
|
||||
|
|
@ -192,7 +192,7 @@ class TestBuildImageOz(utils.CliTestCase):
|
|||
_build_image_oz(
|
||||
self.options, self.task_options, self.session, self.args)
|
||||
self.assertEqual(
|
||||
str(cm.exception), 'Unknown build target: %s' % self.args[2])
|
||||
str(cm.exception), 'No such build target: %s' % self.args[2])
|
||||
|
||||
self.session.getBuildTarget.return_value = self.target_info
|
||||
self.session.getTag.return_value = {}
|
||||
|
|
@ -201,7 +201,7 @@ class TestBuildImageOz(utils.CliTestCase):
|
|||
self.options, self.task_options, self.session, self.args)
|
||||
self.assertEqual(
|
||||
str(cm.exception),
|
||||
'Unknown destination tag: %s' % self.target_info['dest_tag_name'])
|
||||
'No such destination tag: %s' % self.target_info['dest_tag_name'])
|
||||
|
||||
self.session.getTag.return_value = self.tag_info
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ class TestBuildImageIndirection(utils.CliTestCase):
|
|||
|
||||
# Case 4. target not found error
|
||||
self.session.getBuildTarget.return_value = {}
|
||||
expected = "Unknown build target: %s" % {}
|
||||
expected = "No such build target: %s" % {}
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
_build_image_indirection(
|
||||
self.options, self.task_opts, self.session, [])
|
||||
|
|
@ -168,7 +168,7 @@ class TestBuildImageIndirection(utils.CliTestCase):
|
|||
# Case 5. tag not found error
|
||||
self.session.getBuildTarget.return_value = self.build_target
|
||||
self.session.getTag.return_value = {}
|
||||
expected = "Unknown destination tag: %s" % self.build_target['dest_tag_name']
|
||||
expected = "No such destination tag: %s" % self.build_target['dest_tag_name']
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
_build_image_indirection(
|
||||
self.options, self.task_opts, self.session, [])
|
||||
|
|
|
|||
41
tests/test_cli/test_import_archive.py
Normal file
41
tests/test_cli/test_import_archive.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
from koji_cli.commands import handle_import_archive
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestImportArchive(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_import_archive_without_option(self, stderr):
|
||||
expected = "Usage: %s import-archive <build-id|n-v-r> <archive_path> [<archive_path2 ...]\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: You must specify a build ID or N-V-R and " \
|
||||
"an archive to import\n" % (self.progname, self.progname)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_import_archive(self.options, self.session, [])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_import_archive_wrong_type(self, stderr):
|
||||
archive_type = 'test-type'
|
||||
archive_path = '/mnt/brew/work/test-archive.type'
|
||||
expected = "Usage: %s import-archive <build-id|n-v-r> <archive_path> [<archive_path2 ...]\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: Unsupported archive type: %s\n" % (self.progname, self.progname,
|
||||
archive_type)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_import_archive(self.options, self.session, ['--type', archive_type, '12',
|
||||
archive_path])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
|
@ -1,10 +1,13 @@
|
|||
from __future__ import absolute_import
|
||||
import json
|
||||
import mock
|
||||
|
||||
import os
|
||||
import six
|
||||
import sys
|
||||
import unittest
|
||||
import json
|
||||
|
||||
import mock
|
||||
import six
|
||||
from nose.plugins.skip import SkipTest
|
||||
|
||||
try:
|
||||
import libcomps
|
||||
|
|
@ -15,13 +18,11 @@ try:
|
|||
except ImportError:
|
||||
yumcomps = None
|
||||
|
||||
from nose.plugins.skip import SkipTest
|
||||
|
||||
import koji_cli.commands
|
||||
from koji_cli.commands import handle_import_comps, _import_comps,\
|
||||
_import_comps_alt
|
||||
from koji_cli.commands import handle_import_comps, _import_comps, _import_comps_alt
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestImportComps(utils.CliTestCase):
|
||||
# Show long diffs in error output...
|
||||
maxDiff = None
|
||||
|
|
@ -172,7 +173,7 @@ class TestImportComps(utils.CliTestCase):
|
|||
handle_import_comps(options, session, args)
|
||||
self.assertExitCode(ex, 1)
|
||||
actual = stderr.getvalue()
|
||||
expected = 'No such tag: tag\n'
|
||||
expected = 'No such tag: %s\n' % tag
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
|
||||
# Finally, assert that things were called as we expected.
|
||||
|
|
|
|||
104
tests/test_cli/test_list_builds.py
Normal file
104
tests/test_cli/test_list_builds.py
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
from koji_cli.commands import anon_handle_list_builds
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestListBuilds(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_list_builds_without_option(self, stderr):
|
||||
expected = "Usage: %s list-builds [options]\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: Filter must be provided for list\n" % (self.progname, self.progname)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_list_builds(self.options, self.session, [])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_list_builds_non_exist_pkg(self, stderr):
|
||||
pkg = 'test-pkg'
|
||||
expected = "Usage: %s list-builds [options]\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)
|
||||
self.session.getPackageID.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_list_builds(self.options, self.session,
|
||||
['--package', pkg])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_list_builds_non_exist_owner(self, stderr):
|
||||
owner = 'test-owner'
|
||||
expected = "Usage: %s list-builds [options]\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: No such user: %s\n" % (self.progname, self.progname, owner)
|
||||
self.session.getUser.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_list_builds(self.options, self.session,
|
||||
['--owner', owner])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_list_builds_non_exist_volume(self, stderr):
|
||||
volume = 'test-volume'
|
||||
expected = "Usage: %s list-builds [options]\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: No such volume: %s\n" % (self.progname, self.progname, volume)
|
||||
self.session.listVolumes.return_value = []
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_list_builds(self.options, self.session,
|
||||
['--volume', volume])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_list_builds_invalid_state(self, stderr):
|
||||
state = '6'
|
||||
expected = "Usage: %s list-builds [options]\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: Invalid state: %s\n" % (self.progname, self.progname, state)
|
||||
self.session.getTag.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_list_builds(self.options, self.session,
|
||||
['--state', state])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_list_builds_invalid_state_string(self, stderr):
|
||||
state = 'test-state'
|
||||
expected = "Usage: %s list-builds [options]\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: Invalid state: %s\n" % (self.progname, self.progname, state)
|
||||
self.session.getTag.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_list_builds(self.options, self.session,
|
||||
['--state', state])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_list_builds_non_exist_build(self, stderr):
|
||||
build = 222
|
||||
expected = "Usage: %s list-builds [options]\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: No such build: '%s'\n" % (self.progname, self.progname, build)
|
||||
self.session.getBuild.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_list_builds(self.options, self.session,
|
||||
['--build', build])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
28
tests/test_cli/test_list_hosts.py
Normal file
28
tests/test_cli/test_list_hosts.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
from koji_cli.commands import anon_handle_list_hosts
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestListHosts(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_list_pkgs_non_exist_channel(self, stderr):
|
||||
channel = 'test-channel'
|
||||
expected = "Usage: %s list-hosts [options]\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: No such channel: %s\n" % (self.progname, self.progname, channel)
|
||||
self.session.getChannel.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_list_hosts(self.options, self.session, ['--channel', channel])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
|
@ -1,12 +1,14 @@
|
|||
from __future__ import absolute_import
|
||||
import mock
|
||||
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
|
||||
from koji_cli.commands import anon_handle_list_notifications
|
||||
|
||||
|
||||
class TestListNotifications(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
|
|
@ -29,7 +31,7 @@ class TestListNotifications(unittest.TestCase):
|
|||
anon_handle_list_notifications(self.options, self.session, ['--mine'])
|
||||
|
||||
actual = stdout.getvalue()
|
||||
expected = '''\
|
||||
expected = '''\
|
||||
Notifications
|
||||
ID Tag Package E-mail Success-only
|
||||
--------------------------------------------------------------------------------------------
|
||||
|
|
@ -40,7 +42,7 @@ Notifications
|
|||
No notification blocks
|
||||
'''
|
||||
|
||||
self.maxDiff=None
|
||||
self.maxDiff = None
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
activate_session_mock.assert_called_once()
|
||||
self.session.getTag.assert_has_calls([mock.call(1), mock.call(1)])
|
||||
|
|
@ -74,7 +76,7 @@ No notification blocks
|
|||
anon_handle_list_notifications(self.options, self.session, ['--user', 'random_name'])
|
||||
|
||||
actual = stdout.getvalue()
|
||||
expected = '''\
|
||||
expected = '''\
|
||||
Notifications
|
||||
ID Tag Package E-mail Success-only
|
||||
--------------------------------------------------------------------------------------------
|
||||
|
|
@ -89,7 +91,7 @@ Notification blocks
|
|||
12 * *
|
||||
'''
|
||||
|
||||
self.maxDiff=None
|
||||
self.maxDiff = None
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||
self.session.getTag.assert_has_calls([mock.call(1), mock.call(1)])
|
||||
|
|
@ -110,7 +112,6 @@ Notification blocks
|
|||
self.session.getTag.assert_not_called()
|
||||
self.session.getPackage.assert_not_called()
|
||||
|
||||
|
||||
@mock.patch('sys.exit')
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_handle_list_notifications_no_args(self, sys_stderr, sys_exit):
|
||||
|
|
@ -120,3 +121,18 @@ Notification blocks
|
|||
anon_handle_list_notifications(self.options, self.session, [])
|
||||
|
||||
self.session.getBuildNotifications.assert_not_called()
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_list_notifications_user_non_exist_user(self, stderr):
|
||||
username = 'random_name'
|
||||
self.session.getUser.return_value = None
|
||||
|
||||
with self.assertRaises(SystemExit):
|
||||
anon_handle_list_notifications(self.options, self.session,
|
||||
['--user', username])
|
||||
actual = stderr.getvalue()
|
||||
expected = 'No such user: %s\n' % username
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
self.session.getBuildNotifications.assert_not_called()
|
||||
self.session.getTag.assert_not_called()
|
||||
self.session.getPackage.assert_not_called()
|
||||
|
|
|
|||
40
tests/test_cli/test_list_pkgs.py
Normal file
40
tests/test_cli/test_list_pkgs.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
from koji_cli.commands import anon_handle_list_pkgs
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestListPkgs(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_list_pkgs_non_exist_tag(self, stderr):
|
||||
tag = 'test-tag'
|
||||
expected = "Usage: %s list-pkgs [options]\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)
|
||||
self.session.getTag.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_list_pkgs(self.options, self.session, ['--tag', tag])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_list_pkgs_non_exist_owner(self, stderr):
|
||||
owner = 'test-owner'
|
||||
expected = "Usage: %s list-pkgs [options]\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: No such user: %s\n" % (self.progname, self.progname, owner)
|
||||
self.session.getUser.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_list_pkgs(self.options, self.session, ['--owner', owner])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
57
tests/test_cli/test_list_tag_inheritance.py
Normal file
57
tests/test_cli/test_list_tag_inheritance.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
from koji_cli.commands import anon_handle_list_tag_inheritance
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestListTagInheritance(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
self.tag = 'test-tag'
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_without_option(self, stderr):
|
||||
expected = "Usage: %s list-tag-inheritance [options] <tag>\n\n" \
|
||||
"Prints tag inheritance with basic information about links.\n" \
|
||||
"Four flags could be seen in the output:\n" \
|
||||
" M - maxdepth - limits inheritance to n-levels\n" \
|
||||
" F - package filter (packages ignored for inheritance)\n" \
|
||||
" I - intransitive link - inheritance immediately stops here\n" \
|
||||
" N - noconfig - if tag is used in buildroot, its configuration values " \
|
||||
"will not be used\n\n" \
|
||||
"Exact values for maxdepth and package filter can be inquired by " \
|
||||
"taginfo command.\n\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: This command takes exactly one argument: " \
|
||||
"a tag name or ID\n" % (self.progname, self.progname)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_list_tag_inheritance(self.options, self.session, [])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_with_non_exist_tag(self, stderr):
|
||||
expected = "Usage: %s list-tag-inheritance [options] <tag>\n\n" \
|
||||
"Prints tag inheritance with basic information about links.\n" \
|
||||
"Four flags could be seen in the output:\n" \
|
||||
" M - maxdepth - limits inheritance to n-levels\n" \
|
||||
" F - package filter (packages ignored for inheritance)\n" \
|
||||
" I - intransitive link - inheritance immediately stops here\n" \
|
||||
" N - noconfig - if tag is used in buildroot, its configuration values " \
|
||||
"will not be used\n\n" \
|
||||
"Exact values for maxdepth and package filter can be inquired by " \
|
||||
"taginfo command.\n\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, self.tag)
|
||||
self.session.getTag.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_list_tag_inheritance(self.options, self.session, [self.tag])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
import sys
|
||||
import os
|
||||
import time
|
||||
|
||||
|
|
@ -177,8 +176,7 @@ class TestCliListTagged(utils.CliTestCase):
|
|||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||
@mock.patch('koji.util.eventFromOpts', return_value=None)
|
||||
@mock.patch('koji_cli.commands.ensure_connection')
|
||||
def test_list_tagged_type_paths(self, ensure_connection_mock,
|
||||
event_from_opts_mock, stdout):
|
||||
def test_list_tagged_type_paths(self, ensure_connection_mock, event_from_opts_mock, stdout):
|
||||
args = ['tag', 'pkg', '--latest-n=3', '--type=maven', '--paths']
|
||||
self.session.listTagged.return_value = [{'id': 1,
|
||||
'name': 'packagename',
|
||||
|
|
|
|||
40
tests/test_cli/test_list_tags.py
Normal file
40
tests/test_cli/test_list_tags.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
from koji_cli.commands import anon_handle_list_tags
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestListTags(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_list_tags_non_exist_package(self, stderr):
|
||||
pkg = 'test-pkg'
|
||||
expected = "Usage: %s list-tags [options] [pattern]\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)
|
||||
self.session.getPackage.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_list_tags(self.options, self.session, ['--package', pkg])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_list_tags_non_exist_build(self, stderr):
|
||||
build = 'test-build'
|
||||
expected = "Usage: %s list-tags [options] [pattern]\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: No such build: %s\n" % (self.progname, self.progname, build)
|
||||
self.session.getBuild.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_list_tags(self.options, self.session, ['--build', build])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
|
@ -1,16 +1,14 @@
|
|||
import os
|
||||
import re
|
||||
import time
|
||||
import unittest
|
||||
from optparse import Values
|
||||
|
||||
import six
|
||||
import koji
|
||||
import mock
|
||||
|
||||
from . import utils
|
||||
import koji
|
||||
from koji_cli.commands import anon_handle_list_targets
|
||||
|
||||
from . import utils
|
||||
|
||||
_mock_targets = [
|
||||
{
|
||||
|
|
@ -41,7 +39,8 @@ class TestCliListTargets(utils.CliTestCase):
|
|||
@mock.patch('sys.stderr', new_callable=six.StringIO)
|
||||
@mock.patch('koji_cli.commands.activate_session')
|
||||
def test_list_targets_error_args(self, ensure_connection_mock, stderr):
|
||||
session = mock.MagicMock(getAPIVersion=lambda: koji.API_VERSION, getBuildTargets=lambda n: [])
|
||||
session = mock.MagicMock(getAPIVersion=lambda: koji.API_VERSION,
|
||||
getBuildTargets=lambda n: [])
|
||||
options = mock.MagicMock(quiet=False)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_list_targets(options, session, ['aaa'])
|
||||
|
|
@ -50,28 +49,32 @@ class TestCliListTargets(utils.CliTestCase):
|
|||
@mock.patch('sys.stderr', new_callable=six.StringIO)
|
||||
@mock.patch('koji_cli.commands.activate_session')
|
||||
def test_list_targets_error_all_not_found(self, ensure_connection_mock, stderr):
|
||||
session = mock.MagicMock(getAPIVersion=lambda: koji.API_VERSION, getBuildTargets=lambda n: [])
|
||||
session = mock.MagicMock(getAPIVersion=lambda: koji.API_VERSION,
|
||||
getBuildTargets=lambda n: [])
|
||||
options = mock.MagicMock(quiet=False)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_list_targets(options, session, [])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assertTrue('No Targets were found' in stderr.getvalue())
|
||||
self.assertTrue('No targets were found' in stderr.getvalue())
|
||||
|
||||
@mock.patch('optparse.OptionParser.parse_args', return_value=(Values({'quiet': False, 'name': 'f50'}), []))
|
||||
@mock.patch('optparse.OptionParser.parse_args',
|
||||
return_value=(Values({'quiet': False, 'name': 'f50'}), []))
|
||||
@mock.patch('sys.stderr', new_callable=six.StringIO)
|
||||
@mock.patch('koji_cli.commands.activate_session')
|
||||
def test_list_targets_error_name_not_found(self, ensure_connection_mock, stderr, opt):
|
||||
session = mock.MagicMock(getAPIVersion=lambda: koji.API_VERSION, getBuildTargets=lambda n: [])
|
||||
session = mock.MagicMock(getAPIVersion=lambda: koji.API_VERSION,
|
||||
getBuildTargets=lambda n: [])
|
||||
options = mock.MagicMock(quiet=False)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_list_targets(options, session, [])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assertTrue('Target "f50" does not exist' in stderr.getvalue())
|
||||
self.assertTrue('No such build target:' in stderr.getvalue())
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||
@mock.patch('koji_cli.commands.activate_session')
|
||||
def test_list_targets_all(self, ensure_connection_mock, stdout):
|
||||
session = mock.MagicMock(getAPIVersion=lambda: koji.API_VERSION, getBuildTargets=lambda n: _mock_targets)
|
||||
session = mock.MagicMock(getAPIVersion=lambda: koji.API_VERSION,
|
||||
getBuildTargets=lambda n: _mock_targets)
|
||||
options = mock.MagicMock(quiet=False)
|
||||
anon_handle_list_targets(options, session, [])
|
||||
expected = [
|
||||
|
|
@ -82,11 +85,13 @@ class TestCliListTargets(utils.CliTestCase):
|
|||
]
|
||||
self.assertEqual(expected, [re.sub(' +', '|', l) for l in stdout.getvalue().split('\n')])
|
||||
|
||||
@mock.patch('optparse.OptionParser.parse_args', return_value=(Values({'quiet': False, 'name': 'f50'}), []))
|
||||
@mock.patch('optparse.OptionParser.parse_args',
|
||||
return_value=(Values({'quiet': False, 'name': 'f50'}), []))
|
||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||
@mock.patch('koji_cli.commands.activate_session')
|
||||
def test_list_targets_one(self, ensure_connection_mock, stdout, opt):
|
||||
session = mock.MagicMock(getAPIVersion=lambda: koji.API_VERSION, getBuildTargets=lambda n: _mock_targets)
|
||||
session = mock.MagicMock(getAPIVersion=lambda: koji.API_VERSION,
|
||||
getBuildTargets=lambda n: _mock_targets)
|
||||
options = mock.MagicMock(quiet=False)
|
||||
anon_handle_list_targets(options, session, [])
|
||||
expected = [
|
||||
|
|
|
|||
|
|
@ -262,7 +262,7 @@ Options:
|
|||
%s maven-build --ini=CONFIG... [options] <target>
|
||||
(Specify the --help global option for a list of other help options)
|
||||
|
||||
%s: error: Unknown build target: target
|
||||
%s: error: No such build target: target
|
||||
""" % (progname, progname, progname)
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
# Finally, assert that things were called as we expected.
|
||||
|
|
@ -307,7 +307,7 @@ Options:
|
|||
%s maven-build --ini=CONFIG... [options] <target>
|
||||
(Specify the --help global option for a list of other help options)
|
||||
|
||||
%s: error: Unknown destination tag: dest_tag
|
||||
%s: error: No such destination tag: dest_tag
|
||||
""" % (progname, progname, progname)
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
# Finally, assert that things were called as we expected.
|
||||
|
|
@ -536,7 +536,7 @@ Task info: weburl/taskinfo?taskID=1
|
|||
%s maven-build --ini=CONFIG... [options] <target>
|
||||
(Specify the --help global option for a list of other help options)
|
||||
|
||||
%s: error: Invalid SCM URL: badscm
|
||||
%s: error: No such SCM URL: badscm
|
||||
""" % (progname, progname, progname)
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
# Finally, assert that things were called as we expected.
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class TestMavenChain(utils.CliTestCase):
|
|||
|
||||
# Unknonw target test
|
||||
expected = self.format_error_message(
|
||||
"Unknown build target: %s" % self.target)
|
||||
"No such build target: %s" % self.target)
|
||||
self.assert_system_exit(
|
||||
handle_maven_chain,
|
||||
options,
|
||||
|
|
@ -71,7 +71,7 @@ class TestMavenChain(utils.CliTestCase):
|
|||
# Unknow destination tag test
|
||||
session.getBuildTarget.return_value = target_info
|
||||
expected = self.format_error_message(
|
||||
"Unknown destination tag: %s" % target_info['dest_tag_name'])
|
||||
"No such destination tag: %s" % target_info['dest_tag_name'])
|
||||
self.assert_system_exit(
|
||||
handle_maven_chain,
|
||||
options,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
import six
|
||||
import unittest
|
||||
|
||||
from koji_cli.commands import anon_handle_mock_config
|
||||
from . import utils
|
||||
|
|
@ -210,7 +212,7 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
|
|||
self.assert_console_message(stderr, expected)
|
||||
|
||||
arguments = ['--tag', tag['name'], '--arch', tag['arch']]
|
||||
expected = self.format_error_message("Invalid tag: %s" % tag['name'])
|
||||
expected = self.format_error_message("No such tag: %s" % tag['name'])
|
||||
self.assert_system_exit(
|
||||
anon_handle_mock_config,
|
||||
options,
|
||||
|
|
@ -303,8 +305,7 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
|
|||
|
||||
arguments = ['--target', target['name'],
|
||||
'--arch', arch]
|
||||
expected = self.format_error_message(
|
||||
"Invalid target: %s" % target['name'])
|
||||
expected = self.format_error_message("No such build target: %s" % target['name'])
|
||||
self.assert_system_exit(
|
||||
anon_handle_mock_config,
|
||||
options,
|
||||
|
|
@ -361,7 +362,7 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
|
|||
# Run it and check immediate output
|
||||
# argument is empty
|
||||
expected = self.format_error_message(
|
||||
"Please specify one of: --tag, --target, --task, --buildroot")
|
||||
"Please specify one of: --tag, --target, --task, --buildroot")
|
||||
self.assert_system_exit(
|
||||
anon_handle_mock_config,
|
||||
options,
|
||||
|
|
@ -372,8 +373,7 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
|
|||
|
||||
# name is specified twice case
|
||||
arguments = [self.progname, '--name', 'name']
|
||||
expected = self.format_error_message(
|
||||
"Name already specified via option")
|
||||
expected = self.format_error_message("Name already specified via option")
|
||||
self.assert_system_exit(
|
||||
anon_handle_mock_config,
|
||||
options,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
import six
|
||||
import unittest
|
||||
|
||||
from koji_cli.commands import handle_move_build
|
||||
from . import utils
|
||||
|
|
@ -48,7 +50,7 @@ class TestMoveBuild(utils.CliTestCase):
|
|||
]
|
||||
self.session.moveBuild.side_effect = tasks
|
||||
|
||||
expected = 'Invalid build %s, skipping.' % 'pkg_c-2.2-2fc26' + "\n"
|
||||
expected = 'No such build: %s, skipping.' % 'pkg_c-2.2-2fc26' + "\n"
|
||||
for i, t in enumerate(tasks):
|
||||
expected += "Created task %d, moving %s" % (t, pkgs[i]) + "\n"
|
||||
|
||||
|
|
@ -103,7 +105,7 @@ class TestMoveBuild(utils.CliTestCase):
|
|||
[500, 501, 502], [601, 602, 603]
|
||||
]
|
||||
|
||||
expected = 'Invalid package name %s, skipping.' % 'pkg_c-2.2-2fc26' + "\n"
|
||||
expected = 'No such package: %s, skipping.' % 'pkg_c-2.2-2fc26' + "\n"
|
||||
with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:
|
||||
rv = handle_move_build(self.options, self.session, arguments)
|
||||
|
||||
|
|
@ -118,7 +120,8 @@ class TestMoveBuild(utils.CliTestCase):
|
|||
|
||||
# Case 1. without --all option
|
||||
expected = self.format_error_message(
|
||||
"This command takes at least three arguments: two tags and one or more package n-v-r's")
|
||||
"This command takes at least three arguments: "
|
||||
"two tags and one or more package n-v-r's")
|
||||
for arg in [[], ['tag1'], ['tag1', 'tag2']]:
|
||||
self.assert_system_exit(
|
||||
handle_move_build,
|
||||
|
|
@ -130,7 +133,8 @@ class TestMoveBuild(utils.CliTestCase):
|
|||
|
||||
# Case 2. with --all option
|
||||
expected = self.format_error_message(
|
||||
"This command, with --all, takes at least three arguments: two tags and one or more package names")
|
||||
"This command, with --all, takes at least three arguments: "
|
||||
"two tags and one or more package names")
|
||||
for arg in [['--all', 'tag1'], ['--all', 'tag1', 'tag2']]:
|
||||
self.assert_system_exit(
|
||||
handle_move_build,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
|
||||
import unittest
|
||||
import copy
|
||||
|
||||
import mock
|
||||
import six
|
||||
import unittest
|
||||
|
||||
from koji_cli.commands import handle_regen_repo
|
||||
from . import utils
|
||||
|
|
@ -25,7 +27,7 @@ class TestRegenRepo(utils.CliTestCase):
|
|||
'arches': 'x86_64',
|
||||
'maven_include_all': False,
|
||||
'perm_id': None
|
||||
}
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
self.task_id = 1001
|
||||
|
|
@ -85,7 +87,7 @@ class TestRegenRepo(utils.CliTestCase):
|
|||
|
||||
# show error if tag is not exist
|
||||
self.session.getTag.return_value = {}
|
||||
expected = self.format_error_message("No matching tag: " + self.tag_name)
|
||||
expected = self.format_error_message("No such tag: %s" % self.tag_name)
|
||||
self.assert_system_exit(
|
||||
handle_regen_repo,
|
||||
self.options,
|
||||
|
|
@ -115,7 +117,7 @@ class TestRegenRepo(utils.CliTestCase):
|
|||
|
||||
# show error if target is not matched
|
||||
self.session.getBuildTarget.return_value = {}
|
||||
expected = self.format_error_message("No matching build target: " + self.tag_name)
|
||||
expected = self.format_error_message("No such build target: " + self.tag_name)
|
||||
self.assert_system_exit(
|
||||
handle_regen_repo,
|
||||
self.options,
|
||||
|
|
@ -143,8 +145,10 @@ class TestRegenRepo(utils.CliTestCase):
|
|||
tests = [
|
||||
# [ arguments, error_string ]
|
||||
[[], self.format_error_message("A tag name must be specified")],
|
||||
[['tag1', 'tag2'], self.format_error_message("Only a single tag name may be specified")],
|
||||
[['tag1', 'tag2', '--target'], self.format_error_message("Only a single target may be specified")],
|
||||
[['tag1', 'tag2'],
|
||||
self.format_error_message("Only a single tag name may be specified")],
|
||||
[['tag1', 'tag2', '--target'],
|
||||
self.format_error_message("Only a single target may be specified")],
|
||||
]
|
||||
|
||||
for test in tests:
|
||||
|
|
|
|||
|
|
@ -17,30 +17,34 @@ class TestRemoveGroup(utils.CliTestCase):
|
|||
|
||||
%s: error: {message}
|
||||
""" % (self.progname, self.progname)
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||
@mock.patch('sys.stderr', new_callable=six.StringIO)
|
||||
@mock.patch('koji_cli.commands.activate_session')
|
||||
def test_handle_remove_group_nonexistent_tag(self, activate_session_mock, stdout, stderr):
|
||||
def test_handle_remove_group_nonexistent_tag(self, activate_session_mock, stderr, stdout):
|
||||
tag = 'nonexistent-tag'
|
||||
group = 'group'
|
||||
arguments = [tag, group]
|
||||
options = mock.MagicMock()
|
||||
|
||||
# Mock out the xmlrpc server
|
||||
session = mock.MagicMock()
|
||||
session.hasPerm.return_value = True
|
||||
session.getTag.return_value = None
|
||||
self.session.hasPerm.return_value = True
|
||||
self.session.getTag.return_value = None
|
||||
|
||||
with self.assertRaises(SystemExit):
|
||||
handle_remove_group(options, session, arguments)
|
||||
expected = 'No such tag: %s\n' % tag
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_remove_group(self.options, self.session, arguments)
|
||||
self.assertExitCode(ex, 1)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
# assert that things were called as we expected.
|
||||
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()
|
||||
session.groupListRemove.assert_not_called()
|
||||
activate_session_mock.assert_called_once_with(self.session, self.options)
|
||||
self.session.hasPerm.assert_called_once_with('admin')
|
||||
self.session.getTag.assert_called_once_with(tag)
|
||||
self.session.getTagGroups.assert_not_called()
|
||||
self.session.groupListRemove.assert_not_called()
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||
@mock.patch('sys.stderr', new_callable=six.StringIO)
|
||||
|
|
@ -49,23 +53,21 @@ class TestRemoveGroup(utils.CliTestCase):
|
|||
tag = 'tag'
|
||||
group = 'group'
|
||||
arguments = [tag, group]
|
||||
options = mock.MagicMock()
|
||||
|
||||
# Mock out the xmlrpc server
|
||||
session = mock.MagicMock()
|
||||
session.hasPerm.return_value = True
|
||||
session.getTag.return_value = tag
|
||||
session.getTagGroups.return_value = []
|
||||
self.session.hasPerm.return_value = True
|
||||
self.session.getTag.return_value = tag
|
||||
self.session.getTagGroups.return_value = []
|
||||
|
||||
with self.assertRaises(SystemExit):
|
||||
handle_remove_group(options, session, arguments)
|
||||
handle_remove_group(self.options, self.session, arguments)
|
||||
|
||||
# assert that things were called as we expected.
|
||||
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)
|
||||
session.groupListRemove.assert_not_called()
|
||||
activate_session_mock.assert_called_once_with(self.session, self.options)
|
||||
self.session.hasPerm.assert_called_once_with('admin')
|
||||
self.session.getTag.assert_called_once_with(tag)
|
||||
self.session.getTagGroups.assert_called_once_with(tag, inherit=False)
|
||||
self.session.groupListRemove.assert_not_called()
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||
@mock.patch('sys.stderr', new_callable=six.StringIO)
|
||||
|
|
@ -74,45 +76,40 @@ class TestRemoveGroup(utils.CliTestCase):
|
|||
tag = 'tag'
|
||||
group = 'group'
|
||||
arguments = [tag, group]
|
||||
options = mock.MagicMock()
|
||||
|
||||
# Mock out the xmlrpc server
|
||||
session = mock.MagicMock()
|
||||
session.hasPerm.return_value = True
|
||||
session.getTag.return_value = tag
|
||||
session.getTagGroups.return_value = [
|
||||
self.session.hasPerm.return_value = True
|
||||
self.session.getTag.return_value = tag
|
||||
self.session.getTagGroups.return_value = [
|
||||
{'name': 'group', 'group_id': 'groupId'}]
|
||||
|
||||
rv = handle_remove_group(options, session, arguments)
|
||||
rv = handle_remove_group(self.options, self.session, arguments)
|
||||
|
||||
# assert that things were called as we expected.
|
||||
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)
|
||||
session.groupListRemove.assert_called_once_with(tag, group)
|
||||
activate_session_mock.assert_called_once_with(self.session, self.options)
|
||||
self.session.hasPerm.assert_called_once_with('admin')
|
||||
self.session.getTag.assert_called_once_with(tag)
|
||||
self.session.getTagGroups.assert_called_once_with(tag, inherit=False)
|
||||
self.session.groupListRemove.assert_called_once_with(tag, group)
|
||||
self.assertEqual(rv, None)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||
@mock.patch('sys.stderr', new_callable=six.StringIO)
|
||||
@mock.patch('koji_cli.commands.activate_session')
|
||||
def test_handle_remove_group_error_handling(self, activate_session_mock, stdout, stderr):
|
||||
session = mock.MagicMock()
|
||||
options = mock.MagicMock()
|
||||
|
||||
expected = self.format_error_message(
|
||||
"Please specify a tag name and a group name")
|
||||
for args in [[], ['tag'], ['tag', 'grp', 'etc']]:
|
||||
self.assert_system_exit(
|
||||
handle_remove_group,
|
||||
options,
|
||||
session,
|
||||
self.options,
|
||||
self.session,
|
||||
args,
|
||||
stderr=expected,
|
||||
activate_session=None)
|
||||
|
||||
# if we don't have 'tag' permission
|
||||
session.hasPerm.return_value = False
|
||||
self.session.hasPerm.return_value = False
|
||||
with self.assertRaises(SystemExit):
|
||||
handle_remove_group(options, session, ['tag', 'grp'])
|
||||
activate_session_mock.assert_called_with(session, options)
|
||||
handle_remove_group(self.options, self.session, ['tag', 'grp'])
|
||||
activate_session_mock.assert_called_with(self.session, self.options)
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
from __future__ import absolute_import
|
||||
import mock
|
||||
|
||||
import os
|
||||
import six
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
import six
|
||||
from mock import call
|
||||
|
||||
from koji_cli.commands import handle_remove_pkg
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestRemovePkg(utils.CliTestCase):
|
||||
|
||||
# Show long diffs in error output...
|
||||
|
|
@ -180,7 +182,7 @@ class TestRemovePkg(utils.CliTestCase):
|
|||
handle_remove_pkg(options, session, args)
|
||||
self.assertExitCode(ex, 1)
|
||||
actual = stderr.getvalue()
|
||||
expected = 'No such tag: tag\n'
|
||||
expected = 'No such tag: %s\n' % tag
|
||||
self.assertMultiLineEqual(actual, expected)
|
||||
# Finally, assert that things were called as we expected.
|
||||
activate_session_mock.assert_called_once_with(session, options)
|
||||
|
|
|
|||
36
tests/test_cli/test_remove_tag.py
Normal file
36
tests/test_cli/test_remove_tag.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
from koji_cli.commands import handle_remove_tag
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestRemoveTag(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_remove_tag_without_option(self, stderr):
|
||||
expected = "Usage: %s remove-tag [options] <name>\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: Please specify a tag to remove\n" % (self.progname, self.progname)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_remove_tag(self.options, self.session, [])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_remove_tag_non_exist_tag(self, stderr):
|
||||
tag = 'test-tag'
|
||||
expected = "No such tag: %s\n" % tag
|
||||
self.session.getTag.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_remove_tag(self.options, self.session, [tag])
|
||||
self.assertExitCode(ex, 1)
|
||||
self.assert_console_message(stderr, expected)
|
||||
65
tests/test_cli/test_remove_tag_inheritance.py
Normal file
65
tests/test_cli/test_remove_tag_inheritance.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
from koji_cli.commands import handle_remove_tag_inheritance
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestRemoveTagInheritance(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_remove_tag_inheritance_without_option(self, stderr):
|
||||
expected = "Usage: %s remove-tag-inheritance <tag> <parent> <priority>\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: This command takes at least one argument: " \
|
||||
"a tag name or ID\n" % (self.progname, self.progname)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_remove_tag_inheritance(self.options, self.session, [])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_remove_tag_inheritance_non_exist_tag(self, stderr):
|
||||
tag = 'test-tag'
|
||||
parent_tag = 'parent-test-tag'
|
||||
priority = '99'
|
||||
expected = "Usage: %s remove-tag-inheritance <tag> <parent> <priority>\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)
|
||||
self.session.getTag.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_remove_tag_inheritance(self.options, self.session, [tag, parent_tag, priority])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_remove_tag_inheritance_non_exist_parent_tag(self, stderr):
|
||||
side_effect_result = [{'arches': 'x86_64',
|
||||
'extra': {},
|
||||
'id': 1,
|
||||
'locked': False,
|
||||
'maven_include_all': False,
|
||||
'maven_support': False,
|
||||
'name': 'test-tag',
|
||||
'perm': None,
|
||||
'perm_id': None},
|
||||
None]
|
||||
tag = 'test-tag'
|
||||
parent_tag = 'parent-test-tag'
|
||||
priority = '99'
|
||||
expected = "Usage: %s remove-tag-inheritance <tag> <parent> <priority>\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, parent_tag)
|
||||
self.session.getTag.side_effect = side_effect_result
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_remove_tag_inheritance(self.options, self.session, [tag, parent_tag, priority])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
37
tests/test_cli/test_remove_target.py
Normal file
37
tests/test_cli/test_remove_target.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
from koji_cli.commands import handle_remove_target
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestRemoveTarget(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_remove_target_without_option(self, stderr):
|
||||
expected = "Usage: %s remove-target [options] <name>\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: Please specify a build target to " \
|
||||
"remove\n" % (self.progname, self.progname)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_remove_target(self.options, self.session, [])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_remove_target_non_exist_target(self, stderr):
|
||||
target = 'test-target'
|
||||
expected = "No such build target: %s\n" % target
|
||||
self.session.getBuildTarget.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_remove_target(self.options, self.session, [target])
|
||||
self.assertExitCode(ex, 1)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
|
@ -61,7 +61,7 @@ Available search types: package, build, tag, target, user, host, rpm, maven, win
|
|||
{'argument': [], 'error': 'Please specify search type'},
|
||||
{'argument': [s_type], 'error': 'Please specify search pattern'},
|
||||
{'argument': [s_type, s_patt],
|
||||
'error': 'Unknown search type: %s' % s_type}
|
||||
'error': 'No such search type: %s' % s_type}
|
||||
]
|
||||
|
||||
for case in cases:
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ class TestBuildImage(utils.CliTestCase):
|
|||
# Case 2. target not found error
|
||||
self.activate_session.reset_mock()
|
||||
self.session.getBuildTarget.return_value = {}
|
||||
expected = "Unknown build target: %s" % self.arguments[2]
|
||||
expected = "No such build target: %s" % self.arguments[2]
|
||||
args[-1] = img_type
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
_build_image(*args)
|
||||
|
|
@ -235,7 +235,7 @@ class TestBuildImage(utils.CliTestCase):
|
|||
self.activate_session.reset_mock()
|
||||
self.session.getBuildTarget.return_value = self.build_target
|
||||
self.session.getTag.return_value = {}
|
||||
expected = "Unknown destination tag: %s" % self.build_target['dest_tag_name']
|
||||
expected = "No such destination tag: %s" % self.build_target['dest_tag_name']
|
||||
args[-1] = img_type
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
_build_image(*args)
|
||||
|
|
|
|||
38
tests/test_cli/test_taginfo.py
Normal file
38
tests/test_cli/test_taginfo.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
from koji_cli.commands import anon_handle_taginfo
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestTaginfo(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_taginfo_without_option(self, stderr):
|
||||
expected = "Usage: %s taginfo [options] <tag> [<tag> ...]\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: Please specify a tag\n" % (self.progname, self.progname)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
anon_handle_taginfo(self.options, self.session, [])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_taginfo_non_exist_tag(self, stderr):
|
||||
tag = 'test-tag'
|
||||
expected = "Usage: %s taginfo [options] <tag> [<tag> ...]\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)
|
||||
self.session.getBuildConfig.return_value = None
|
||||
with self.assertRaises(SystemExit) as cm:
|
||||
anon_handle_taginfo(self.options, self.session, [tag])
|
||||
self.assertExitCode(cm, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
38
tests/test_cli/test_unlock_tag.py
Normal file
38
tests/test_cli/test_unlock_tag.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
from koji_cli.commands import handle_unlock_tag
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestUnlockTag(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_unlock_tag_without_option(self, stderr):
|
||||
expected = "Usage: %s unlock-tag [options] <tag> [<tag> ...]\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: Please specify a tag\n" % (self.progname, self.progname)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_unlock_tag(self.options, self.session, [])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_unlock_tag_non_exist_tag(self, stderr):
|
||||
tag = 'test-tag'
|
||||
expected = "Usage: %s unlock-tag [options] <tag> [<tag> ...]\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)
|
||||
self.session.getTag.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_unlock_tag(self.options, self.session, [tag])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
51
tests/test_cli/test_untag_build.py
Normal file
51
tests/test_cli/test_untag_build.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
from koji_cli.commands import handle_untag_build
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestUntagBuild(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_untag_build_without_option(self, stderr):
|
||||
expected = "Usage: %s untag-build [options] <tag> <pkg> [<pkg> ...]\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: This command takes at least two arguments: " \
|
||||
"a tag name/ID and one or more package " \
|
||||
"n-v-r's\n" % (self.progname, self.progname)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_untag_build(self.options, self.session, [])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_untag_build_without_option_non_latest_force(self, stderr):
|
||||
expected = "Usage: %s untag-build [options] <tag> <pkg> [<pkg> ...]\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: Please specify a tag\n" % (self.progname, self.progname)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_untag_build(self.options, self.session, ['--non-latest', '--force'])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_untag_build_non_exist_tag(self, stderr):
|
||||
tag = 'test-tag'
|
||||
pkg_info = {'id': 9, 'name': 'test-build'}
|
||||
expected = "Usage: %s untag-build [options] <tag> <pkg> [<pkg> ...]\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)
|
||||
self.session.getTag.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_untag_build(self.options, self.session, [tag, pkg_info['name']])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
|
||||
import unittest
|
||||
import copy
|
||||
|
||||
import mock
|
||||
import six
|
||||
import unittest
|
||||
|
||||
from koji_cli.commands import anon_handle_wait_repo
|
||||
from . import utils
|
||||
|
|
@ -25,7 +28,7 @@ class TestWaitRepo(utils.CliTestCase):
|
|||
'arches': 'x86_64',
|
||||
'maven_include_all': False,
|
||||
'perm_id': None
|
||||
}
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
self.task_id = 1001
|
||||
|
|
@ -106,7 +109,8 @@ class TestWaitRepo(utils.CliTestCase):
|
|||
arguments = [self.tag_name, '--target']
|
||||
|
||||
self.options.quiet = False
|
||||
self.session.getBuildTarget.return_value = {'build_tag_name': self.tag_name, 'build_tag': 1}
|
||||
self.session.getBuildTarget.return_value = {'build_tag_name': self.tag_name,
|
||||
'build_tag': 1}
|
||||
self.session.getRepo.side_effect = [{}, {}, {'id': 1, 'name': 'DEFAULT'}]
|
||||
expected = 'Successfully waited 0:03 for a new %s repo' % self.tag_name + '\n'
|
||||
self.__test_wait_repo(arguments, expected)
|
||||
|
|
@ -143,7 +147,8 @@ class TestWaitRepo(utils.CliTestCase):
|
|||
expected = 'Warning: nvr %s is not current in tag %s\n latest build in %s is %s' % \
|
||||
(builds[0], self.tag_name, self.tag_name, new_ver) + "\n"
|
||||
expected += 'Warning: package sed is not in tag %s' % self.tag_name + '\n'
|
||||
expected += 'Successfully waited 0:03 for %s to appear in the %s repo' % (pkgs, self.tag_name) + '\n'
|
||||
expected += 'Successfully waited 0:03 for %s to appear in the ' \
|
||||
'%s repo\n' % (pkgs, self.tag_name)
|
||||
self.__test_wait_repo(arguments, expected)
|
||||
|
||||
def test_anon_handle_wait_repo_with_build_timeout(self):
|
||||
|
|
@ -163,7 +168,8 @@ class TestWaitRepo(utils.CliTestCase):
|
|||
]
|
||||
self.checkForBuilds.return_value = True
|
||||
self.session.getRepo.return_value = {}
|
||||
expected = 'Unsuccessfully waited 1:02 for %s to appear in the %s repo' % (pkgs, self.tag_name) + '\n'
|
||||
expected = 'Unsuccessfully waited 1:02 for %s to appear in the %s ' \
|
||||
'repo\n' % (pkgs, self.tag_name)
|
||||
self.__test_wait_repo_timeout(arguments, expected, ret_code=1)
|
||||
|
||||
def test_anon_handle_wait_repo_errors(self):
|
||||
|
|
@ -172,8 +178,8 @@ class TestWaitRepo(utils.CliTestCase):
|
|||
# [ arguments, error_string ]
|
||||
[[], "Please specify a tag name"],
|
||||
[['tag1', 'tag2'], "Only one tag may be specified"],
|
||||
[[self.tag_name], "Invalid tag: %s" % self.tag_name],
|
||||
[[self.tag_name, '--target'], "Invalid build target: %s" % self.tag_name],
|
||||
[[self.tag_name], "No such tag: %s" % self.tag_name],
|
||||
[[self.tag_name, '--target'], "No such build target: %s" % self.tag_name],
|
||||
]
|
||||
|
||||
self.session.getBuildTarget.return_value = {}
|
||||
|
|
|
|||
78
tests/test_cli/test_win_build.py
Normal file
78
tests/test_cli/test_win_build.py
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
from six.moves import StringIO
|
||||
|
||||
import koji
|
||||
from koji_cli.commands import handle_win_build
|
||||
from . import utils
|
||||
|
||||
|
||||
class TestWinBuild(utils.CliTestCase):
|
||||
def setUp(self):
|
||||
self.options = mock.MagicMock()
|
||||
self.options.debug = False
|
||||
self.session = mock.MagicMock()
|
||||
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||
self.target = 'test-target'
|
||||
self.dest_tag = 'destination-test_tag'
|
||||
self.target_info = {'build_tag': 4,
|
||||
'build_tag_name': 'test_tag',
|
||||
'dest_tag': 5,
|
||||
'dest_tag_name': self.dest_tag,
|
||||
'id': 2,
|
||||
'name': self.target}
|
||||
self.scm_url = 'git://test.redhat.com/rpms/pkg-1.1.0' \
|
||||
'?#3fab2ea42ecdc30a41daf1306154dfa04c4d64fd'
|
||||
self.vm = 'test-vm'
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_win_build_without_option(self, stderr):
|
||||
expected = "Usage: %s win-build [options] <target> <URL> <VM>\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: Exactly three arguments (a build target, a SCM URL, " \
|
||||
"and a VM name) are required\n" % (self.progname, self.progname)
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_win_build(self.options, self.session, [])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_win_build_non_exist_build_target(self, stderr):
|
||||
expected = "Usage: %s win-build [options] <target> <URL> <VM>\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: No such build target: %s\n" % (self.progname, self.progname,
|
||||
self.target)
|
||||
self.session.getBuildTarget.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_win_build(self.options, self.session, [self.target, self.scm_url, self.vm])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_win_build_non_exist_dest_tag(self, stderr):
|
||||
expected = "Usage: %s win-build [options] <target> <URL> <VM>\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: No such destination tag: %s\n" % (self.progname, self.progname,
|
||||
self.dest_tag)
|
||||
self.session.getBuildTarget.return_value = self.target_info
|
||||
self.session.getTag.return_value = None
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_win_build(self.options, self.session, [self.target, self.scm_url, self.vm])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
|
||||
@mock.patch('sys.stderr', new_callable=StringIO)
|
||||
def test_handle_build_dest_tag_locked(self, stderr):
|
||||
expected = "Usage: %s win-build [options] <target> <URL> <VM>\n" \
|
||||
"(Specify the --help global option for a list of other help options)\n\n" \
|
||||
"%s: error: Destination tag %s is locked\n" % (self.progname, self.progname,
|
||||
self.dest_tag)
|
||||
dest_tag_info = {'name': self.dest_tag, 'locked': True}
|
||||
|
||||
self.session.getBuildTarget.return_value = self.target_info
|
||||
self.session.getTag.return_value = dest_tag_info
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
handle_win_build(self.options, self.session, [self.target, self.scm_url, self.vm])
|
||||
self.assertExitCode(ex, 2)
|
||||
self.assert_console_message(stderr, expected)
|
||||
Loading…
Add table
Add a link
Reference in a new issue