CLI mock-config: when topdir option, remove topurl value
Fixes: https://pagure.io/koji/issue/2675
This commit is contained in:
parent
0b911ed0c4
commit
f528fd9ca4
2 changed files with 185 additions and 164 deletions
|
|
@ -1043,9 +1043,11 @@ def anon_handle_mock_config(goptions, session, args):
|
||||||
parser.add_option("--buildroot",
|
parser.add_option("--buildroot",
|
||||||
help="Duplicate the mock config for the specified buildroot id")
|
help="Duplicate the mock config for the specified buildroot id")
|
||||||
parser.add_option("--mockdir", default="/var/lib/mock", metavar="DIR", help="Specify mockdir")
|
parser.add_option("--mockdir", default="/var/lib/mock", metavar="DIR", help="Specify mockdir")
|
||||||
parser.add_option("--topdir", metavar="DIR", help="Specify topdir")
|
parser.add_option("--topdir", metavar="DIR",
|
||||||
parser.add_option("--topurl", metavar="URL", default=goptions.topurl,
|
help="Specify topdir, topdir tops the topurl")
|
||||||
help="URL under which Koji files are accessible")
|
parser.add_option("--topurl", metavar="URL",
|
||||||
|
help="URL under which Koji files are accessible, "
|
||||||
|
"when topdir is specified, topdir tops the topurl")
|
||||||
parser.add_option("--distribution", default="Koji Testing",
|
parser.add_option("--distribution", default="Koji Testing",
|
||||||
help="Change the distribution macro")
|
help="Change the distribution macro")
|
||||||
parser.add_option("--yum-proxy", help="Specify a yum proxy")
|
parser.add_option("--yum-proxy", help="Specify a yum proxy")
|
||||||
|
|
@ -1062,7 +1064,12 @@ def anon_handle_mock_config(goptions, session, args):
|
||||||
opts = {}
|
opts = {}
|
||||||
for k in ('topdir', 'topurl', 'distribution', 'mockdir', 'yum_proxy'):
|
for k in ('topdir', 'topurl', 'distribution', 'mockdir', 'yum_proxy'):
|
||||||
if hasattr(options, k):
|
if hasattr(options, k):
|
||||||
opts[k] = getattr(options, k)
|
if getattr(options, k) is not None:
|
||||||
|
opts[k] = getattr(options, k)
|
||||||
|
if opts.get('topdir') and opts.get('topurl'):
|
||||||
|
del opts['topurl']
|
||||||
|
if not opts.get('topdir') and not opts.get('topurl'):
|
||||||
|
opts['topurl'] = goptions.topurl
|
||||||
if options.buildroot:
|
if options.buildroot:
|
||||||
try:
|
try:
|
||||||
br_id = int(options.buildroot)
|
br_id = int(options.buildroot)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import unittest
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import six
|
import six
|
||||||
|
import koji
|
||||||
|
|
||||||
from koji_cli.commands import anon_handle_mock_config
|
from koji_cli.commands import anon_handle_mock_config
|
||||||
from . import utils
|
from . import utils
|
||||||
|
|
@ -15,6 +16,12 @@ class TestMockConfig(utils.CliTestCase):
|
||||||
maxDiff = None
|
maxDiff = None
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
self.options = mock.MagicMock()
|
||||||
|
self.options.debug = False
|
||||||
|
self.session = mock.MagicMock()
|
||||||
|
self.session.getAPIVersion.return_value = koji.API_VERSION
|
||||||
|
self.gen_config_mock = mock.patch('koji.genMockConfig').start()
|
||||||
|
self.ensure_connection_mock = mock.patch('koji_cli.commands.ensure_connection').start()
|
||||||
self.maxDiff = None
|
self.maxDiff = None
|
||||||
self.common_args = [
|
self.common_args = [
|
||||||
'--distribution', 'fedora',
|
'--distribution', 'fedora',
|
||||||
|
|
@ -58,16 +65,9 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
|
||||||
%s: error: {message}
|
%s: error: {message}
|
||||||
""" % (self.progname, self.progname)
|
""" % (self.progname, self.progname)
|
||||||
|
|
||||||
@mock.patch('sys.stderr', new_callable=six.StringIO)
|
|
||||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||||
@mock.patch('koji.genMockConfig')
|
def test_handle_mock_config_buildroot_option(self, stdout):
|
||||||
@mock.patch('koji_cli.commands.ensure_connection')
|
|
||||||
def test_handle_mock_config_buildroot_option(
|
|
||||||
self, ensure_connection_mock, gen_config_mock, stdout, stderr):
|
|
||||||
"""Test anon_handle_mock_config buildroot options"""
|
"""Test anon_handle_mock_config buildroot options"""
|
||||||
arguments = []
|
|
||||||
options = mock.MagicMock()
|
|
||||||
|
|
||||||
buildroot_info = {
|
buildroot_info = {
|
||||||
'repo_id': 101,
|
'repo_id': 101,
|
||||||
'tag_name': 'tag_name',
|
'tag_name': 'tag_name',
|
||||||
|
|
@ -75,100 +75,103 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
|
||||||
}
|
}
|
||||||
|
|
||||||
# Mock out the xmlrpc server
|
# Mock out the xmlrpc server
|
||||||
session = mock.MagicMock()
|
self.session.getBuildroot.return_value = buildroot_info
|
||||||
session.getBuildroot.return_value = buildroot_info
|
|
||||||
|
|
||||||
# Mock config
|
# Mock config
|
||||||
gen_config_mock.return_value = self.mock_output
|
self.gen_config_mock.return_value = self.mock_output
|
||||||
|
|
||||||
# buildroot check
|
# buildroot check
|
||||||
arguments = ['--buildroot', 'root', self.progname]
|
arguments = ['--buildroot', 'root', self.progname]
|
||||||
expected = self.format_error_message("Buildroot id must be an integer")
|
expected = self.format_error_message("Buildroot id must be an integer")
|
||||||
self.assert_system_exit(
|
self.assert_system_exit(
|
||||||
anon_handle_mock_config,
|
anon_handle_mock_config,
|
||||||
options,
|
self.options, self.session, arguments,
|
||||||
session,
|
|
||||||
arguments,
|
|
||||||
stderr=expected,
|
stderr=expected,
|
||||||
|
exit_code=2,
|
||||||
activate_session=None)
|
activate_session=None)
|
||||||
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
arguments = self.common_args + ['--buildroot', '1',
|
arguments = self.common_args + ['--buildroot', '1', '--name', self.progname]
|
||||||
'--name', self.progname]
|
|
||||||
opts = self.common_opts.copy()
|
opts = self.common_opts.copy()
|
||||||
opts.update({
|
opts.update({
|
||||||
'repoid': buildroot_info['repo_id'],
|
'repoid': buildroot_info['repo_id'],
|
||||||
'tag_name': buildroot_info['tag_name'],
|
'tag_name': buildroot_info['tag_name'],
|
||||||
'tag_macros': {},
|
'tag_macros': {},
|
||||||
})
|
})
|
||||||
anon_handle_mock_config(options, session, arguments)
|
del opts['topurl']
|
||||||
self.assert_console_message(
|
anon_handle_mock_config(self.options, self.session, arguments)
|
||||||
stdout, "%s\n" % gen_config_mock.return_value)
|
self.assert_console_message(stdout, "%s\n" % self.gen_config_mock.return_value)
|
||||||
gen_config_mock.assert_called_with(
|
self.gen_config_mock.assert_called_with(self.progname, buildroot_info['arch'], **opts)
|
||||||
self.progname, buildroot_info['arch'], **opts)
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
arguments = self.common_args + ['--buildroot', '1',
|
arguments = self.common_args + ['--buildroot', '1',
|
||||||
'--name', self.progname,
|
'--name', self.progname,
|
||||||
'--latest']
|
'--latest']
|
||||||
opts['repoid'] = 'latest'
|
opts['repoid'] = 'latest'
|
||||||
anon_handle_mock_config(options, session, arguments)
|
anon_handle_mock_config(self.options, self.session, arguments)
|
||||||
self.assert_console_message(
|
self.assert_console_message(stdout, "%s\n" % self.gen_config_mock.return_value)
|
||||||
stdout, "%s\n" % gen_config_mock.return_value)
|
self.gen_config_mock.assert_called_with(self.progname, buildroot_info['arch'], **opts)
|
||||||
gen_config_mock.assert_called_with(
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
self.progname, buildroot_info['arch'], **opts)
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
# if buildroot is not existing
|
# if buildroot is not existing
|
||||||
buildroot_id = '999999'
|
buildroot_id = '999999'
|
||||||
arguments = ['--buildroot', buildroot_id]
|
arguments = ['--buildroot', buildroot_id]
|
||||||
|
self.session.getBuildroot.return_value = None
|
||||||
expected = "No such buildroot: %s" % buildroot_id + "\n"
|
expected = "No such buildroot: %s" % buildroot_id + "\n"
|
||||||
session.getBuildroot.return_value = None
|
self.assert_system_exit(
|
||||||
with self.assertRaises(SystemExit) as ex:
|
anon_handle_mock_config,
|
||||||
anon_handle_mock_config(options, session, arguments)
|
self.options, self.session, arguments,
|
||||||
self.assertExitCode(ex, 1)
|
stderr=expected,
|
||||||
self.assert_console_message(stderr, expected)
|
exit_code=1,
|
||||||
|
activate_session=None)
|
||||||
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
@mock.patch('sys.stderr', new_callable=six.StringIO)
|
|
||||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||||
@mock.patch('koji.genMockConfig')
|
def test_handle_mock_config_task_option(self, stdout):
|
||||||
@mock.patch('koji_cli.commands.ensure_connection')
|
|
||||||
def test_handle_mock_config_task_option(
|
|
||||||
self, ensure_connection_mock, gen_config_mock, stdout, stderr):
|
|
||||||
"""Test anon_handle_mock_config task options"""
|
"""Test anon_handle_mock_config task options"""
|
||||||
arguments = []
|
|
||||||
task_id = 1001
|
task_id = 1001
|
||||||
options = mock.MagicMock()
|
self.session.listBuildroots.return_value = ''
|
||||||
|
|
||||||
session = mock.MagicMock()
|
|
||||||
session.listBuildroots.return_value = ''
|
|
||||||
|
|
||||||
# Mock config
|
# Mock config
|
||||||
gen_config_mock.return_value = ''
|
self.gen_config_mock.return_value = ''
|
||||||
|
|
||||||
arguments = ['--task', 'task']
|
arguments = ['--task', 'task']
|
||||||
expected = self.format_error_message("Task id must be an integer")
|
expected = self.format_error_message("Task id must be an integer")
|
||||||
self.assert_system_exit(
|
self.assert_system_exit(
|
||||||
anon_handle_mock_config,
|
anon_handle_mock_config,
|
||||||
options,
|
self.options, self.session, arguments,
|
||||||
session,
|
|
||||||
arguments,
|
|
||||||
stderr=expected,
|
stderr=expected,
|
||||||
|
exit_code=2,
|
||||||
activate_session=None)
|
activate_session=None)
|
||||||
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
arguments = ['--task', str(task_id)]
|
arguments = ['--task', str(task_id)]
|
||||||
expected = "No buildroots for task %s (or no such task)\n" % str(task_id)
|
expected = "No buildroots for task %s (or no such task)\n" % str(task_id)
|
||||||
with self.assertRaises(SystemExit) as ex:
|
self.assert_system_exit(
|
||||||
anon_handle_mock_config(options, session, arguments)
|
anon_handle_mock_config,
|
||||||
self.assertExitCode(ex, 1)
|
self.options, self.session, arguments,
|
||||||
self.assert_console_message(stderr, expected)
|
stderr=expected,
|
||||||
|
exit_code=1,
|
||||||
|
activate_session=None)
|
||||||
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
multi_broots = [
|
multi_broots = [
|
||||||
{'id': 1101, 'repo_id': 101, 'tag_name': 'tag_101', 'arch': 'x86_64'},
|
{'id': 1101, 'repo_id': 101, 'tag_name': 'tag_101', 'arch': 'x86_64'},
|
||||||
{'id': 1111, 'repo_id': 111, 'tag_name': 'tag_111', 'arch': 'x86_64'},
|
{'id': 1111, 'repo_id': 111, 'tag_name': 'tag_111', 'arch': 'x86_64'},
|
||||||
{'id': 1121, 'repo_id': 121, 'tag_name': 'tag_121', 'arch': 'x86_64'}
|
{'id': 1121, 'repo_id': 121, 'tag_name': 'tag_121', 'arch': 'x86_64'}
|
||||||
]
|
]
|
||||||
session.listBuildroots.return_value = multi_broots
|
self.session.listBuildroots.return_value = multi_broots
|
||||||
anon_handle_mock_config(options, session, arguments)
|
anon_handle_mock_config(self.options, self.session, arguments)
|
||||||
expected = "Multiple buildroots found: %s" % [br['id'] for br in multi_broots]
|
expected = "Multiple buildroots found: %s" % [br['id'] for br in multi_broots]
|
||||||
self.assert_console_message(stdout, "%s\n\n" % expected)
|
self.assert_console_message(stdout, "%s\n\n" % expected)
|
||||||
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
opts = self.common_opts.copy()
|
opts = self.common_opts.copy()
|
||||||
opts.update({
|
opts.update({
|
||||||
|
|
@ -176,62 +179,63 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
|
||||||
'tag_name': multi_broots[0]['tag_name'],
|
'tag_name': multi_broots[0]['tag_name'],
|
||||||
'tag_macros': {},
|
'tag_macros': {},
|
||||||
})
|
})
|
||||||
|
del opts['topurl']
|
||||||
arguments = self.common_args + ['--task', str(task_id),
|
arguments = self.common_args + ['--task', str(task_id),
|
||||||
'--name', self.progname,
|
'--name', self.progname,
|
||||||
'--latest']
|
'--latest']
|
||||||
session.listBuildroots.return_value = [multi_broots[0]]
|
self.session.listBuildroots.return_value = [multi_broots[0]]
|
||||||
gen_config_mock.return_value = self.mock_output
|
self.gen_config_mock.return_value = self.mock_output
|
||||||
anon_handle_mock_config(options, session, arguments)
|
anon_handle_mock_config(self.options, self.session, arguments)
|
||||||
self.assert_console_message(
|
self.assert_console_message(stdout, "%s\n" % self.gen_config_mock.return_value)
|
||||||
stdout, "%s\n" % gen_config_mock.return_value)
|
self.gen_config_mock.assert_called_with(self.progname, multi_broots[0]['arch'], **opts)
|
||||||
gen_config_mock.assert_called_with(
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
self.progname, multi_broots[0]['arch'], **opts)
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
@mock.patch('sys.stderr', new_callable=six.StringIO)
|
@mock.patch('sys.stderr', new_callable=six.StringIO)
|
||||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||||
@mock.patch('koji.genMockConfig')
|
def test_handle_mock_config_tag_option(self, stdout, stderr):
|
||||||
@mock.patch('koji_cli.commands.ensure_connection')
|
|
||||||
def test_handle_mock_config_tag_option(
|
|
||||||
self, ensure_connection_mock, gen_config_mock, stdout, stderr):
|
|
||||||
"""Test anon_handle_mock_config with tag option"""
|
"""Test anon_handle_mock_config with tag option"""
|
||||||
arguments = []
|
|
||||||
tag = 'tag'
|
|
||||||
tag = {'id': 201, 'name': 'tag', 'arch': 'x86_64'}
|
tag = {'id': 201, 'name': 'tag', 'arch': 'x86_64'}
|
||||||
options = mock.MagicMock()
|
self.session.getTag.return_value = None
|
||||||
|
self.session.getBuildConfig.return_value = None
|
||||||
# Mock out the xmlrpc server
|
self.session.getRepo.return_value = None
|
||||||
session = mock.MagicMock()
|
|
||||||
session.getTag.return_value = None
|
|
||||||
session.getBuildConfig.return_value = None
|
|
||||||
session.getRepo.return_value = None
|
|
||||||
|
|
||||||
arguments = ['--tag', tag['name']]
|
arguments = ['--tag', tag['name']]
|
||||||
expected = "Please specify an arch\n"
|
expected = "Please specify an arch\n"
|
||||||
with self.assertRaises(SystemExit) as ex:
|
self.assert_system_exit(
|
||||||
anon_handle_mock_config(options, session, arguments)
|
anon_handle_mock_config,
|
||||||
self.assertExitCode(ex, 1)
|
self.options, self.session, arguments,
|
||||||
self.assert_console_message(stderr, expected)
|
stderr=expected,
|
||||||
|
exit_code=1,
|
||||||
|
activate_session=None)
|
||||||
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
arguments = ['--tag', tag['name'], '--arch', tag['arch']]
|
arguments = ['--tag', tag['name'], '--arch', tag['arch']]
|
||||||
expected = self.format_error_message("No such tag: %s" % tag['name'])
|
expected = self.format_error_message("No such tag: %s" % tag['name'])
|
||||||
self.assert_system_exit(
|
self.assert_system_exit(
|
||||||
anon_handle_mock_config,
|
anon_handle_mock_config,
|
||||||
options,
|
self.options, self.session, arguments,
|
||||||
session,
|
|
||||||
arguments,
|
|
||||||
stderr=expected,
|
stderr=expected,
|
||||||
|
exit_code=2,
|
||||||
activate_session=None)
|
activate_session=None)
|
||||||
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
# return tag info
|
# return tag info
|
||||||
session.getTag.return_value = tag
|
self.session.getTag.return_value = tag
|
||||||
expected = "Could not get config info for tag: %(name)s\n" % tag
|
expected = "Could not get config info for tag: %(name)s\n" % tag
|
||||||
with self.assertRaises(SystemExit) as ex:
|
self.assert_system_exit(
|
||||||
anon_handle_mock_config(options, session, arguments)
|
anon_handle_mock_config,
|
||||||
self.assertExitCode(ex, 1)
|
self.options, self.session, arguments,
|
||||||
self.assert_console_message(stderr, expected)
|
stderr=expected,
|
||||||
|
exit_code=1,
|
||||||
|
activate_session=None)
|
||||||
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
# return build config
|
# return build config
|
||||||
session.getBuildConfig.return_value = {
|
self.session.getBuildConfig.return_value = {
|
||||||
'id': 301,
|
'id': 301,
|
||||||
'extra': {
|
'extra': {
|
||||||
'rpm.macro.random_macro1': 'random_macro_content1',
|
'rpm.macro.random_macro1': 'random_macro_content1',
|
||||||
|
|
@ -242,17 +246,22 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
|
||||||
'arches': 'x86_64',
|
'arches': 'x86_64',
|
||||||
}
|
}
|
||||||
expected = "Could not get a repo for tag: %(name)s\n" % tag
|
expected = "Could not get a repo for tag: %(name)s\n" % tag
|
||||||
with self.assertRaises(SystemExit) as ex:
|
self.assert_system_exit(
|
||||||
anon_handle_mock_config(options, session, arguments)
|
anon_handle_mock_config,
|
||||||
self.assertExitCode(ex, 1)
|
self.options, self.session, arguments,
|
||||||
self.assert_console_message(stderr, expected)
|
stderr=expected,
|
||||||
|
exit_code=1,
|
||||||
|
activate_session=None)
|
||||||
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
# return repo
|
# return repo
|
||||||
session.getRepo.return_value = {'id': 101}
|
self.session.getRepo.return_value = {'id': 101}
|
||||||
gen_config_mock.return_value = self.mock_output
|
self.gen_config_mock.return_value = self.mock_output
|
||||||
anon_handle_mock_config(options, session, arguments)
|
anon_handle_mock_config(self.options, self.session, arguments)
|
||||||
self.assert_console_message(
|
self.assert_console_message(stdout, "%s\n" % self.gen_config_mock.return_value)
|
||||||
stdout, "%s\n" % gen_config_mock.return_value)
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
arguments = self.common_args + ['--tag', tag['name'],
|
arguments = self.common_args + ['--tag', tag['name'],
|
||||||
'--arch', tag['arch'],
|
'--arch', tag['arch'],
|
||||||
|
|
@ -269,24 +278,27 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
|
||||||
'package_manager': 'yum',
|
'package_manager': 'yum',
|
||||||
'module_hotfixes': 1,
|
'module_hotfixes': 1,
|
||||||
})
|
})
|
||||||
anon_handle_mock_config(options, session, arguments)
|
del opts['topurl']
|
||||||
self.assert_console_message(
|
anon_handle_mock_config(self.options, self.session, arguments)
|
||||||
stdout, "%s\n" % gen_config_mock.return_value)
|
self.assert_console_message(stdout, "%s\n" % self.gen_config_mock.return_value)
|
||||||
gen_config_mock.assert_called_with(
|
self.gen_config_mock.assert_called_with(self.progname, tag['arch'], **opts)
|
||||||
self.progname, tag['arch'], **opts)
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
# return arch warning and config
|
# return arch warning and config
|
||||||
arch = 'test'
|
arch = 'test'
|
||||||
warn_msg = '%s is not in the list of tag arches' % arch
|
warn_msg = '%s is not in the list of tag arches' % arch
|
||||||
gen_config_mock.return_value = self.mock_output
|
self.gen_config_mock.return_value = self.mock_output
|
||||||
arguments = self.common_args + ['--tag', tag['name'], '--arch', arch,
|
arguments = self.common_args + ['--tag', tag['name'], '--arch', arch,
|
||||||
'--name', self.progname, '--latest']
|
'--name', self.progname, '--latest']
|
||||||
anon_handle_mock_config(options, session, arguments)
|
anon_handle_mock_config(self.options, self.session, arguments)
|
||||||
self.assert_console_message(stdout, "%s\n" % gen_config_mock.return_value)
|
self.assert_console_message(stdout, "%s\n" % self.gen_config_mock.return_value)
|
||||||
self.assert_console_message(stderr, "%s\n" % warn_msg)
|
self.assert_console_message(stderr, "%s\n" % warn_msg)
|
||||||
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
# return warning that tag arch is empty
|
# return warning that tag arch is empty
|
||||||
session.getBuildConfig.return_value = {
|
self.session.getBuildConfig.return_value = {
|
||||||
'id': 301,
|
'id': 301,
|
||||||
'extra': {
|
'extra': {
|
||||||
'rpm.macro.random_macro1': 'random_macro_content1',
|
'rpm.macro.random_macro1': 'random_macro_content1',
|
||||||
|
|
@ -298,22 +310,20 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
|
||||||
}
|
}
|
||||||
arch = 'test'
|
arch = 'test'
|
||||||
warn_msg = 'Tag %s has an empty arch list' % tag['name']
|
warn_msg = 'Tag %s has an empty arch list' % tag['name']
|
||||||
gen_config_mock.return_value = self.mock_output
|
self.gen_config_mock.return_value = self.mock_output
|
||||||
arguments = self.common_args + ['--tag', tag['name'], '--arch', arch,
|
arguments = self.common_args + ['--tag', tag['name'], '--arch', arch,
|
||||||
'--name', self.progname, '--latest']
|
'--name', self.progname, '--latest']
|
||||||
anon_handle_mock_config(options, session, arguments)
|
anon_handle_mock_config(self.options, self.session, arguments)
|
||||||
self.assert_console_message(stdout, "%s\n" % gen_config_mock.return_value)
|
self.assert_console_message(stdout, "%s\n" % self.gen_config_mock.return_value)
|
||||||
self.assert_console_message(stderr, "%s\n" % warn_msg)
|
self.assert_console_message(stderr, "%s\n" % warn_msg)
|
||||||
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
@mock.patch('sys.stderr', new_callable=six.StringIO)
|
@mock.patch('sys.stderr', new_callable=six.StringIO)
|
||||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||||
@mock.patch('koji.genMockConfig')
|
|
||||||
@mock.patch('koji_cli.commands.ensure_connection')
|
|
||||||
@mock.patch('koji_cli.commands.open')
|
@mock.patch('koji_cli.commands.open')
|
||||||
def test_handle_mock_config_target_option(
|
def test_handle_mock_config_target_option(self, openf, stdout, stderr):
|
||||||
self, openf, ensure_connection_mock, gen_config_mock, stdout, stderr):
|
|
||||||
"""Test anon_handle_mock_config with target option"""
|
"""Test anon_handle_mock_config with target option"""
|
||||||
arguments = []
|
|
||||||
arch = "x86_64"
|
arch = "x86_64"
|
||||||
target = {'id': 1,
|
target = {'id': 1,
|
||||||
'name': 'target',
|
'name': 'target',
|
||||||
|
|
@ -321,66 +331,73 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
|
||||||
'build_tag': 2,
|
'build_tag': 2,
|
||||||
'build_tag_name': 'target-build',
|
'build_tag_name': 'target-build',
|
||||||
'dest_tag_name': 'target'}
|
'dest_tag_name': 'target'}
|
||||||
options = mock.MagicMock()
|
self.session.getBuildTarget.return_value = None
|
||||||
|
self.session.getRepo.return_value = None
|
||||||
# Mock out the xmlrpc server
|
|
||||||
session = mock.MagicMock()
|
|
||||||
session.getBuildTarget.return_value = None
|
|
||||||
session.getRepo.return_value = None
|
|
||||||
|
|
||||||
arguments = ['--target', target['name']]
|
arguments = ['--target', target['name']]
|
||||||
expected = "Please specify an arch\n"
|
expected = "Please specify an arch\n"
|
||||||
with self.assertRaises(SystemExit) as ex:
|
self.assert_system_exit(
|
||||||
anon_handle_mock_config(options, session, arguments)
|
anon_handle_mock_config,
|
||||||
self.assertExitCode(ex, 1)
|
self.options, self.session, arguments,
|
||||||
self.assert_console_message(stderr, expected)
|
stderr=expected,
|
||||||
|
exit_code=1,
|
||||||
|
activate_session=None)
|
||||||
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
arguments = ['--target', target['name'],
|
arguments = ['--target', target['name'],
|
||||||
'--arch', arch]
|
'--arch', arch]
|
||||||
expected = self.format_error_message("No such build target: %s" % target['name'])
|
expected = self.format_error_message("No such build target: %s" % target['name'])
|
||||||
self.assert_system_exit(
|
self.assert_system_exit(
|
||||||
anon_handle_mock_config,
|
anon_handle_mock_config,
|
||||||
options,
|
self.options, self.session, arguments,
|
||||||
session,
|
|
||||||
arguments,
|
|
||||||
stderr=expected,
|
stderr=expected,
|
||||||
|
exit_code=2,
|
||||||
activate_session=None)
|
activate_session=None)
|
||||||
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
session.getBuildTarget.return_value = target
|
self.session.getBuildTarget.return_value = target
|
||||||
session.getBuildConfig.return_value = {'arches': 'x86_64', 'extra': {}}
|
self.session.getBuildConfig.return_value = {'arches': 'x86_64', 'extra': {}}
|
||||||
expected = "Could not get a repo for tag: %s\n" % target['build_tag_name']
|
expected = "Could not get a repo for tag: %s\n" % target['build_tag_name']
|
||||||
with self.assertRaises(SystemExit) as ex:
|
self.assert_system_exit(
|
||||||
anon_handle_mock_config(options, session, arguments)
|
anon_handle_mock_config,
|
||||||
self.assertExitCode(ex, 1)
|
self.options, self.session, arguments,
|
||||||
self.assert_console_message(stderr, expected)
|
stderr=expected,
|
||||||
|
exit_code=1,
|
||||||
|
activate_session=None)
|
||||||
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
arguments = self.common_args + ['--target', target['name'],
|
arguments = ['--distribution', 'fedora', '--topurl', '/top-url',
|
||||||
'--arch', arch,
|
'--yum-proxy', '/yum-proxy', '--target', target['name'], '--arch', arch,
|
||||||
'--name', self.progname]
|
'--name', self.progname]
|
||||||
opts = self.common_opts.copy()
|
opts = self.common_opts.copy()
|
||||||
opts.update({
|
opts.update({
|
||||||
'repoid': 101,
|
'repoid': 101,
|
||||||
'tag_name': target['build_tag_name'],
|
'tag_name': target['build_tag_name'],
|
||||||
'tag_macros': {},
|
'tag_macros': {},
|
||||||
})
|
})
|
||||||
session.getRepo.return_value = {'id': 101}
|
del opts['topdir']
|
||||||
gen_config_mock.return_value = self.mock_output
|
self.session.getRepo.return_value = {'id': 101}
|
||||||
anon_handle_mock_config(options, session, arguments)
|
self.gen_config_mock.return_value = self.mock_output
|
||||||
self.assert_console_message(
|
anon_handle_mock_config(self.options, self.session, arguments)
|
||||||
stdout, "%s\n" % gen_config_mock.return_value)
|
self.assert_console_message(stdout, "%s\n" % self.gen_config_mock.return_value)
|
||||||
gen_config_mock.assert_called_with(
|
self.gen_config_mock.assert_called_with(self.progname, arch, **opts)
|
||||||
self.progname, arch, **opts)
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
# --latest and -o (output) test
|
# --latest and -o (output) test
|
||||||
opts['repoid'] = 'latest'
|
opts['repoid'] = 'latest'
|
||||||
arguments.extend(['--latest', '-o', '/tmp/mock.out'])
|
arguments.extend(['--latest', '-o', '/tmp/mock.out'])
|
||||||
fobj = mock.MagicMock()
|
fobj = mock.MagicMock()
|
||||||
openf.return_value.__enter__.return_value = fobj
|
openf.return_value.__enter__.return_value = fobj
|
||||||
anon_handle_mock_config(options, session, arguments)
|
anon_handle_mock_config(self.options, self.session, arguments)
|
||||||
openf.assert_called_once()
|
openf.assert_called_once()
|
||||||
fobj.write.assert_called_once_with(self.mock_output)
|
fobj.write.assert_called_once_with(self.mock_output)
|
||||||
gen_config_mock.assert_called_with(
|
self.gen_config_mock.assert_called_with(self.progname, arch, **opts)
|
||||||
self.progname, arch, **opts)
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
# return arch warning and config
|
# return arch warning and config
|
||||||
arch = 'test'
|
arch = 'test'
|
||||||
|
|
@ -388,20 +405,16 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
|
||||||
'--arch', arch,
|
'--arch', arch,
|
||||||
'--name', self.progname]
|
'--name', self.progname]
|
||||||
warn_msg = '%s is not in the list of tag arches' % arch
|
warn_msg = '%s is not in the list of tag arches' % arch
|
||||||
gen_config_mock.return_value = self.mock_output
|
self.gen_config_mock.return_value = self.mock_output
|
||||||
anon_handle_mock_config(options, session, arguments)
|
anon_handle_mock_config(self.options, self.session, arguments)
|
||||||
self.assert_console_message(stdout, "%s\n" % gen_config_mock.return_value)
|
self.assert_console_message(stdout, "%s\n" % self.gen_config_mock.return_value)
|
||||||
self.assert_console_message(stderr, "%s\n" % warn_msg)
|
self.assert_console_message(stderr, "%s\n" % warn_msg)
|
||||||
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
@mock.patch('sys.stderr', new_callable=six.StringIO)
|
def test_handle_mock_config_errors(self):
|
||||||
@mock.patch('koji_cli.commands.ensure_connection')
|
|
||||||
def test_handle_mock_config_errors(self, ensure_connection_mock, stderr):
|
|
||||||
"""Test anon_handle_mock_config general error messages"""
|
"""Test anon_handle_mock_config general error messages"""
|
||||||
arguments = []
|
arguments = []
|
||||||
options = mock.MagicMock()
|
|
||||||
|
|
||||||
# Mock out the xmlrpc server
|
|
||||||
session = mock.MagicMock()
|
|
||||||
|
|
||||||
# Run it and check immediate output
|
# Run it and check immediate output
|
||||||
# argument is empty
|
# argument is empty
|
||||||
|
|
@ -409,22 +422,22 @@ config_opts['macros']['%distribution'] = 'Koji Testing'
|
||||||
"Please specify one of: --tag, --target, --task, --buildroot")
|
"Please specify one of: --tag, --target, --task, --buildroot")
|
||||||
self.assert_system_exit(
|
self.assert_system_exit(
|
||||||
anon_handle_mock_config,
|
anon_handle_mock_config,
|
||||||
options,
|
self.options, self.session, arguments,
|
||||||
session,
|
|
||||||
arguments,
|
|
||||||
stderr=expected,
|
stderr=expected,
|
||||||
activate_session=None)
|
activate_session=None)
|
||||||
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
# name is specified twice case
|
# name is specified twice case
|
||||||
arguments = [self.progname, '--name', 'name']
|
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(
|
self.assert_system_exit(
|
||||||
anon_handle_mock_config,
|
anon_handle_mock_config,
|
||||||
options,
|
self.options, self.session, arguments,
|
||||||
session,
|
|
||||||
arguments,
|
|
||||||
stderr=expected,
|
stderr=expected,
|
||||||
activate_session=None)
|
activate_session=None)
|
||||||
|
self.ensure_connection_mock.assert_called_once_with(self.session, self.options)
|
||||||
|
self.ensure_connection_mock.reset_mock()
|
||||||
|
|
||||||
def test_handle_mock_config_help(self):
|
def test_handle_mock_config_help(self):
|
||||||
"""Test anon_handle_mock_config help message full output"""
|
"""Test anon_handle_mock_config help message full output"""
|
||||||
|
|
@ -445,8 +458,9 @@ Options:
|
||||||
Duplicate the mock config for the specified buildroot
|
Duplicate the mock config for the specified buildroot
|
||||||
id
|
id
|
||||||
--mockdir=DIR Specify mockdir
|
--mockdir=DIR Specify mockdir
|
||||||
--topdir=DIR Specify topdir
|
--topdir=DIR Specify topdir, topdir tops the topurl
|
||||||
--topurl=URL URL under which Koji files are accessible
|
--topurl=URL URL under which Koji files are accessible, when topdir
|
||||||
|
is specified, topdir tops the topurl
|
||||||
--distribution=DISTRIBUTION
|
--distribution=DISTRIBUTION
|
||||||
Change the distribution macro
|
Change the distribution macro
|
||||||
--yum-proxy=YUM_PROXY
|
--yum-proxy=YUM_PROXY
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue