PR#1508: fix btype lookup in list_archive_files()
Merges #1508 https://pagure.io/koji/pull-request/1508 Fixes: #1507 https://pagure.io/koji/issue/1507 list_archive_files does not handle multi-type builds
This commit is contained in:
commit
92fcb60e79
2 changed files with 25 additions and 43 deletions
|
|
@ -4498,6 +4498,7 @@ def _get_tarball_list(archive_id, tarpath):
|
|||
'group': entry.gname})
|
||||
return result
|
||||
|
||||
|
||||
def list_archive_files(archive_id, queryOpts=None, strict=False):
|
||||
"""
|
||||
Get information about the files contained in the archive with the given ID.
|
||||
|
|
@ -4507,9 +4508,8 @@ def list_archive_files(archive_id, queryOpts=None, strict=False):
|
|||
name: name of the file (string)
|
||||
size: uncompressed size of the file (integer)
|
||||
|
||||
If strict is True, raise GenericError if:
|
||||
- the btype of this archive is not maven, win or image
|
||||
- archive_type is not one that we are able to expand
|
||||
If strict is True, raise GenericError if archive_type is not one that we
|
||||
are able to expand
|
||||
|
||||
Regardless of strict, an error will be raised if the archive_id is invalid
|
||||
"""
|
||||
|
|
@ -4517,30 +4517,30 @@ def list_archive_files(archive_id, queryOpts=None, strict=False):
|
|||
|
||||
archive_type = get_archive_type(type_id=archive_info['type_id'], strict=True)
|
||||
build_info = get_build(archive_info['build_id'], strict=True)
|
||||
maven_info = get_maven_build(build_info['id'])
|
||||
win_info = get_win_build(build_info['id'])
|
||||
image_info = get_image_build(archive_info['build_id'])
|
||||
btype = archive_info['btype']
|
||||
|
||||
if maven_info:
|
||||
if btype == 'maven':
|
||||
maven_archive = get_maven_archive(archive_info['id'], strict=True)
|
||||
archive_info.update(maven_archive)
|
||||
file_path = os.path.join(koji.pathinfo.mavenbuild(build_info),
|
||||
koji.pathinfo.mavenfile(archive_info))
|
||||
elif win_info:
|
||||
elif btype == 'win':
|
||||
win_archive = get_win_archive(archive_info['id'], strict=True)
|
||||
archive_info.update(win_archive)
|
||||
file_path = os.path.join(koji.pathinfo.winbuild(build_info),
|
||||
koji.pathinfo.winfile(archive_info))
|
||||
elif image_info:
|
||||
elif btype == 'image':
|
||||
image_archive = get_image_archive(archive_info['id'], strict=True)
|
||||
archive_info.update(image_archive)
|
||||
file_path = os.path.join(koji.pathinfo.imagebuild(build_info),
|
||||
archive_info['filename'])
|
||||
elif btype:
|
||||
# for non-legacy types, btype info is in the 'extra' field
|
||||
file_path = os.path.join(koji.pathinfo.typedir(build_info, btype),
|
||||
archive_info['filename'])
|
||||
else:
|
||||
# TODO: support other build types
|
||||
if strict:
|
||||
raise koji.GenericError("Unsupported build type")
|
||||
return _applyQueryOpts([], queryOpts)
|
||||
# should not happen
|
||||
raise koji.GenericError("Missing build type info for archive %s" % archive_id)
|
||||
|
||||
if archive_type['name'] in ('zip', 'jar'):
|
||||
filelist = _get_zipfile_list(archive_id, file_path)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ except ImportError:
|
|||
import koji
|
||||
import kojihub
|
||||
|
||||
GET_ARCHIVE_RV = {'id': 1, 'build_id': 2, 'type_id': 3,
|
||||
GET_ARCHIVE_RV = {'id': 1, 'build_id': 2, 'type_id': 3, 'btype': 'btype',
|
||||
'filename': 'somearchive.zip'}
|
||||
GET_ARCHIVE_TYPE_RV = {'id': 3, 'name': 'zip'}
|
||||
GET_BUILD_RV = {'id': 2, 'name': 'somebuild', 'version': '1.2.3',
|
||||
|
|
@ -18,18 +18,14 @@ GET_BUILD_RV = {'id': 2, 'name': 'somebuild', 'version': '1.2.3',
|
|||
class TestListArchiveFiles(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.mm = mock.MagicMock()
|
||||
self.mm.get_image_build = mock.patch('kojihub.get_image_build',
|
||||
return_value=None).start()
|
||||
self.mm.get_win_build = mock.patch('kojihub.get_win_build',
|
||||
return_value=None).start()
|
||||
self.mm.get_maven_build = mock.patch('kojihub.get_maven_build',
|
||||
return_value=None).start()
|
||||
# Note: the following mocks copy() the return value dict because some
|
||||
# of the tests modify it
|
||||
self.mm.get_build = mock.patch('kojihub.get_build',
|
||||
return_value=GET_BUILD_RV).start()
|
||||
return_value=GET_BUILD_RV.copy()).start()
|
||||
self.mm.get_archive_type = mock.patch('kojihub.get_archive_type',
|
||||
return_value=GET_ARCHIVE_TYPE_RV).start()
|
||||
return_value=GET_ARCHIVE_TYPE_RV.copy()).start()
|
||||
self.mm.get_archive = mock.patch('kojihub.get_archive',
|
||||
return_value=GET_ARCHIVE_RV).start()
|
||||
return_value=GET_ARCHIVE_RV.copy()).start()
|
||||
|
||||
def tearDown(self):
|
||||
mock.patch.stopall()
|
||||
|
|
@ -40,9 +36,6 @@ class TestListArchiveFiles(unittest.TestCase):
|
|||
self.mm.get_archive_type.assert_called_once_with(type_id=3,
|
||||
strict=True)
|
||||
self.mm.get_build.assert_called_once_with(2, strict=True)
|
||||
self.mm.get_maven_build.assert_called_once_with(2)
|
||||
self.mm.get_win_build.assert_called_once_with(2)
|
||||
self.mm.get_image_build.assert_called_once_with(2)
|
||||
self.assertListEqual(rv, [])
|
||||
|
||||
@mock.patch('kojihub.get_maven_archive',
|
||||
|
|
@ -52,17 +45,14 @@ class TestListArchiveFiles(unittest.TestCase):
|
|||
'version': '1.0.0'})
|
||||
@mock.patch('kojihub._get_zipfile_list', return_value=[])
|
||||
def test_simple_strict_empty(self, get_zipfile_list, get_maven_archive):
|
||||
self.mm.get_maven_build.return_value = {'build_id': 2,
|
||||
'group_id': 'gid',
|
||||
'artifact_id': 'aid',
|
||||
'version': '1.0.0'}
|
||||
rv = kojihub.list_archive_files(1, strict=True)
|
||||
self.assertListEqual(rv, [])
|
||||
|
||||
def test_simple_strict_bad_btype(self):
|
||||
def test_simple_strict_missing_btype(self):
|
||||
self.mm.get_archive.return_value['btype'] = None
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.list_archive_files(1, strict=True)
|
||||
self.assertEqual(cm.exception.args[0], "Unsupported build type")
|
||||
self.assertEqual(cm.exception.args[0][:18], "Missing build type")
|
||||
|
||||
@mock.patch('kojihub.get_maven_archive',
|
||||
return_value={'archive_id': 1,
|
||||
|
|
@ -71,10 +61,6 @@ class TestListArchiveFiles(unittest.TestCase):
|
|||
'version': '1.0.0'})
|
||||
def test_simple_strict_bad_archive_type(self, get_maven_archive):
|
||||
self.mm.get_archive_type.return_value = {'id': 9, 'name': 'txt'}
|
||||
self.mm.get_maven_build.return_value = {'build_id': 2,
|
||||
'group_id': 'gid',
|
||||
'artifact_id': 'aid',
|
||||
'version': '1.0.0'}
|
||||
with self.assertRaises(koji.GenericError) as cm:
|
||||
kojihub.list_archive_files(1, strict=True)
|
||||
self.assertEqual(cm.exception.args[0], "Unsupported archive type: txt")
|
||||
|
|
@ -94,10 +80,7 @@ class TestListArchiveFiles(unittest.TestCase):
|
|||
'mtime': 103420},
|
||||
])
|
||||
def test_maven_archive(self, get_zipfile_list, get_maven_archive):
|
||||
self.mm.get_maven_build.return_value = {'build_id': 2,
|
||||
'group_id': 'gid',
|
||||
'artifact_id': 'aid',
|
||||
'version': '1.0.0'}
|
||||
self.mm.get_archive.return_value['btype'] = 'maven'
|
||||
rv = kojihub.list_archive_files(1)
|
||||
get_maven_archive.assert_called_once_with(1, strict=True)
|
||||
get_zipfile_list.assert_called_once_with(1,
|
||||
|
|
@ -122,8 +105,7 @@ class TestListArchiveFiles(unittest.TestCase):
|
|||
'mtime': 103420},
|
||||
])
|
||||
def test_win_archive(self, get_zipfile_list, get_win_archive):
|
||||
self.mm.get_win_build.return_value = {'build_id': 2,
|
||||
'platform': 'all'}
|
||||
self.mm.get_archive.return_value['btype'] = 'win'
|
||||
rv = kojihub.list_archive_files(1)
|
||||
get_win_archive.assert_called_once_with(1, strict=True)
|
||||
get_zipfile_list.assert_called_once_with(1,
|
||||
|
|
@ -153,7 +135,7 @@ class TestListArchiveFiles(unittest.TestCase):
|
|||
])
|
||||
def test_image_archive(self, get_tarball_list, get_image_archive):
|
||||
self.mm.get_archive_type.return_value = {'id': 3, 'name': 'tar'}
|
||||
self.mm.get_image_build.return_value = {'build_id': 2}
|
||||
self.mm.get_archive.return_value['btype'] = 'image'
|
||||
rv = kojihub.list_archive_files(1, queryOpts={'countOnly': True})
|
||||
get_image_archive.assert_called_once_with(1, strict=True)
|
||||
get_tarball_list.assert_called_once_with(1,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue