From a0b8ec8bfd56b7760088f85244d8be79e4135778 Mon Sep 17 00:00:00 2001 From: Jana Cupova Date: Mar 24 2022 12:05:30 +0000 Subject: Use builtins.type when option is called type in readTaggedRPMS Fixes: https://pagure.io/koji/issue/3283 --- diff --git a/hub/kojihub.py b/hub/kojihub.py index bfe11e4..2a96907 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -25,6 +25,7 @@ from __future__ import absolute_import import base64 +import builtins import calendar import datetime import fcntl @@ -1489,7 +1490,7 @@ def readTaggedRPMS(tag, package=None, arch=None, event=None, inherit=False, late elif isinstance(arch, (list, tuple)): clauses.append('rpminfo.arch IN %(arch)s') else: - raise koji.GenericError('Invalid type for arch option: %s' % type(arch)) + raise koji.GenericError('Invalid type for arch option: %s' % builtins.type(arch)) fields, aliases = zip(*fields) query = QueryProcessor(tables=tables, joins=joins, clauses=clauses, diff --git a/tests/test_hub/test_read_tagged_rpms.py b/tests/test_hub/test_read_tagged_rpms.py new file mode 100644 index 0000000..fec282c --- /dev/null +++ b/tests/test_hub/test_read_tagged_rpms.py @@ -0,0 +1,33 @@ +import unittest + +import mock + +import koji +import kojihub + + +class TestReadTaggedRPMS(unittest.TestCase): + + def setUp(self): + self.context = mock.patch('kojihub.context').start() + # It seems MagicMock will not automatically handle attributes that + # start with "assert" + self.exports = kojihub.RootExports() + self.readTaggedBuilds = mock.patch('kojihub.readTaggedBuilds').start() + self.tag_name = 'test-tag' + self.build_list = [ + {'build_id': 1, 'create_event': 1172, 'creation_event_id': 1171, 'epoch': None, + 'id': 1, 'name': 'test-pkg', 'nvr': 'test-pkg-2.52-1.fc35', 'owner_id': 1, + 'owner_name': 'kojiuser', 'package_id': 1, 'package_name': 'test-pkg', + 'release': '1.fc35', 'state': 1, 'tag_id': 1, 'tag_name': 'test-tag', + 'task_id': None, 'version': '2.52', 'volume_id': 0, 'volume_name': 'DEFAULT'}] + + def tearDown(self): + mock.patch.stopall() + + def test_get_tagged_rpms_rpmsigs_arch_type_error(self): + self.readTaggedBuilds.return_value = self.build_list + error_message = 'Invalid type for arch option: %s' % type(1245) + with self.assertRaises(koji.GenericError) as cm: + kojihub.readTaggedRPMS(self.tag_name, arch=1245) + self.assertEqual(error_message, str(cm.exception))