From e5fff34d0fe9f9460344501aa58f3974f9e61bc8 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Dec 21 2021 13:46:15 +0000 Subject: fix unit tests --- diff --git a/tests/test_hub/test_list_builds.py b/tests/test_hub/test_list_builds.py index 8c49bda..361fd29 100644 --- a/tests/test_hub/test_list_builds.py +++ b/tests/test_hub/test_list_builds.py @@ -41,9 +41,10 @@ class TestListBuilds(unittest.TestCase): 'volume_id': 0, 'volume_name': 'DEFAULT'}] - def test_wrong_package(self): + @mock.patch('kojihub.get_package_id') + def test_wrong_package(self, get_package_id): package = 'test-package' - kojihub.get_package_id.return_value = None + get_package_id.return_value = None rv = self.exports.listBuilds(packageID=package) self.assertEqual(rv, []) diff --git a/tests/test_hub/test_list_tags.py b/tests/test_hub/test_list_tags.py index a0f4f8d..1523144 100644 --- a/tests/test_hub/test_list_tags.py +++ b/tests/test_hub/test_list_tags.py @@ -27,22 +27,21 @@ class TestListTags(unittest.TestCase): self.exports.listTags(build=build_name) self.assertEqual("No such build: %s" % build_name, str(cm.exception)) - def test_non_exist_package(self): - package_id = 999 + @mock.patch('kojihub.lookup_package') + def test_non_exist_package(self, lookup_package): self.cursor.fetchone.return_value = None self.context.cnx.cursor.return_value = self.cursor - kojihub.lookup_package.return_value = koji.GenericError + lookup_package.side_effect = koji.GenericError('Expected error') + + package_id = 999 with self.assertRaises(koji.GenericError) as cm: self.exports.listTags(package=package_id) - self.assertEqual("No such package: %s" % package_id, str(cm.exception)) + self.assertEqual('Expected error', str(cm.exception)) package_name = 'test-pkg' - self.cursor.fetchone.return_value = None - self.context.cnx.cursor.return_value = self.cursor - kojihub.lookup_package.return_value = koji.GenericError with self.assertRaises(koji.GenericError) as cm: self.exports.listTags(package=package_name) - self.assertEqual("No such package: %s" % package_name, str(cm.exception)) + self.assertEqual("Expected error", str(cm.exception)) def test_build_package_not_none(self): build_id = 999