Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_multi_fnmatch(self):
"""Test multi_fnmatch function"""
patterns = "example.py example*.py [0-9]*.py [0-9]_*_exmple.py"
self.assertTrue(koji.util.multi_fnmatch('example.py', patterns))
self.assertTrue(koji.util.multi_fnmatch('example.py', patterns.split()))
self.assertTrue(koji.util.multi_fnmatch('01.py', patterns.split()))
self.assertTrue(koji.util.multi_fnmatch('01_koji:util_example.py', patterns.split()))
self.assertTrue(koji.util.multi_fnmatch('example_01.py', patterns.split()))
self.assertFalse(koji.util.multi_fnmatch('sample.py', patterns.split()))
def test_maven_config_opt_adapter(self):
"""Test class MavenConfigOptAdapter"""
conf = mock.MagicMock()
section = 'section'
adapter = koji.util.MavenConfigOptAdapter(conf, section)
self.assertIs(adapter._conf, conf)
self.assertIs(adapter._section, section)
conf.has_option.return_value = True
adapter.goals
adapter.properties
adapter.someattr
conf.has_option.return_value = False
with self.assertRaises(AttributeError) as cm:
adapter.noexistsattr
self.assertEquals(cm.exception.args[0], 'noexistsattr')
self.assertEquals(conf.mock_calls, [call.has_option(section, 'goals'),
call.get(section, 'goals'),
call.get().split(),
call.has_option(section, 'properties'),
call.get(section, 'properties'),
call.get().splitlines(),
def test_too_exclusive(self):
tag_arches = [koji.canonArch(a) for a in self.getBuildConfig()['arches'].split()]
# random choice involved, so we repeat this a few times
for i in range(20):
self.readSRPMHeader.return_value = FakeHeader(
buildarchs=['noarch'], exclusivearch=['missing_arch'], excludearch=[])
with self.assertRaises(koji.BuildError):
result = self.handler.choose_taskarch('noarch', 'srpm', 'build_tag')
def test_all_excluded(self):
tag_arches = [koji.canonArch(a) for a in self.getBuildConfig()['arches'].split()]
# random choice involved, so we repeat this a few times
for i in range(20):
self.readSRPMHeader.return_value = FakeHeader(
buildarchs=['noarch'], exclusivearch=[], excludearch=tag_arches)
with self.assertRaises(koji.BuildError):
result = self.handler.choose_taskarch('noarch', 'srpm', 'build_tag')
def test_get_host_invalid_hostinfo(self):
with self.assertRaises(koji.GenericError):
self.exports.getHost({'host_id': 567})
self.assertEqual(len(self.queries), 0)
def test_non_existing_file(self, list_archive_files):
list_archive_files.return_value = FILES
rv = kojihub.get_archive_file(1, 'archive3.xml')
list_archive_files.assert_called_with(1, strict=False)
self.assertEqual(rv, None)
list_archive_files.reset_mock()
with self.assertRaises(koji.GenericError) as cm:
kojihub.get_archive_file(1, 'archive3.xml', strict=True)
list_archive_files.assert_called_with(1, strict=True)
self.assertEqual(cm.exception.args[0], 'No such file: archive3.xml in archive#1')
def test_edit_host_missing(self):
kojihub.get_host = mock.MagicMock()
kojihub.get_host.side_effect = koji.GenericError
with self.assertRaises(koji.GenericError):
self.exports.editHost('hostname')
kojihub.get_host.assert_called_once_with('hostname', strict=True)
self.assertEqual(self.inserts, [])
self.assertEqual(self.updates, [])
self.command = self.get_default_command()
else:
self.command = cmd
# Check koji command
if not self.is_command_valid():
raise ValueError('Koji command "%s" is not valid' % self.command)
# Assuming command is valid, set configuration file and read it
self.config = self.CONFIG_MAP[self.command]
self.read_config()
# Setup koji session
server_url = self.config_options['server']
session_options = self.get_session_options()
self.session = koji.ClientSession(server_url,
session_options)
def test_server_principal_rdns(self, getfqdn):
opts = {'krb_rdns': True}
session = koji.ClientSession('http://koji.example.com:30/kojihub', opts)
cprinc = mock.MagicMock()
cprinc.realm = "REALM"
getfqdn.return_value = 'koji02.example.com'
princ = session._serverPrincipal(cprinc)
self.assertEqual(princ, 'host/koji02.example.com@REALM')
getfqdn.assert_called_with('koji.example.com')
from __future__ import absolute_import
import mock
import koji
from koji.xmlrpcplus import Fault
class BaseFakeClientSession(koji.ClientSession):
def __init__(self, *a, **kw):
super(BaseFakeClientSession, self).__init__(*a, **kw)
def multiCall(self, strict=False):
if not self.multicall:
raise Exception("not in multicall")
ret = []
self.multicall = False
calls = self._calls
self._calls = []
for call in calls:
method = call['methodName']
args, kwargs = koji.decode_args(call['params'])
try:
result = self._callMethod(method, args, kwargs)