From bf5da960535ed5ccd4f3a1704596aeb18b11a14f Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Aug 28 2019 13:46:02 +0000 Subject: Fix lookup_name usage + tests Fixes: https://pagure.io/koji/issue/1632 --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 96196c9..eeb2b7a 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -6637,8 +6637,8 @@ def import_archive_internal(filepath, buildinfo, type, typeInfo, buildroot_id=No btype = lookup_name('btype', type, strict=False) if btype is None: raise koji.BuildError('unsupported build type: %s' % type) - if btype not in get_build_type(buildinfo, strict=True): - raise koji.ImportError('Build does not have type %s', btype) + if btype['name'] not in get_build_type(buildinfo, strict=True): + raise koji.ImportError('Build does not have type %s' % btype['name']) archiveinfo['btype_id'] = btype['id'] # cg extra data diff --git a/tests/test_hub/test_complete_image_build.py b/tests/test_hub/test_complete_image_build.py index 1bdde53..aa3015b 100644 --- a/tests/test_hub/test_complete_image_build.py +++ b/tests/test_hub/test_complete_image_build.py @@ -131,7 +131,7 @@ class TestCompleteImageBuild(unittest.TestCase): if table == 'btype': return { 'id': 'BTYPEID:%s' % info, - 'name': 'BTYPE:%s' % info, + 'name': info, } else: raise Exception("Cannot fake call") @@ -189,6 +189,7 @@ class TestCompleteImageBuild(unittest.TestCase): 'source': None, 'state': koji.BUILD_STATES['BUILDING'], 'volume_id': 0, + 'extra': {}, } image_info = {'build_id': buildinfo['id']} self.get_build.return_value = buildinfo diff --git a/tests/test_hub/test_complete_maven_build.py b/tests/test_hub/test_complete_maven_build.py index 42ba161..d2a5778 100644 --- a/tests/test_hub/test_complete_maven_build.py +++ b/tests/test_hub/test_complete_maven_build.py @@ -73,7 +73,7 @@ class TestCompleteMavenBuild(unittest.TestCase): def my_lookup_name(self, table, info, **kw): if table == 'btype': - return mock.MagicMock() + return {'name': 'maven', 'id': 1234} else: raise Exception("Cannot fake call") @@ -121,6 +121,7 @@ class TestCompleteMavenBuild(unittest.TestCase): buildinfo['state'] = koji.BUILD_STATES['BUILDING'] buildinfo['volume_id'] = 0 buildinfo['volume_name'] = 'DEFAULT' + buildinfo['extra'] = {} maven_info = self.maven_data['maven_info'].copy() maven_info['build_id'] = buildinfo['id'] self.get_build.return_value = buildinfo