From ce624342d841cd16c9aefc478a5312784d79cdd9 Mon Sep 17 00:00:00 2001
From: Jana Cupova <root@localhost>
Date: Jan 02 2024 12:06:22 +0000
Subject: [PATCH 1/2] Fix unittests for python-mock-5.x


Fixes: https://pagure.io/koji/issue/3967

---

diff --git a/tests/test_cli/test_latest_build.py b/tests/test_cli/test_latest_build.py
index 73baa98..0cef965 100644
--- a/tests/test_cli/test_latest_build.py
+++ b/tests/test_cli/test_latest_build.py
@@ -56,7 +56,7 @@ https://docs.pagure.org/koji/HOWTO/#package-organization
             exit_code=2,
             activate_session=None)
         self.activate_session_mock.assert_not_called()
-        self.ensure_connection.called_once()
+        self.ensure_connection.assert_called_once()
 
     def test_handle_latest_build_all_and_pkg(self):
         expected = "%s: error: A package name may not be combined with --all\n" % self.progname
@@ -68,7 +68,7 @@ https://docs.pagure.org/koji/HOWTO/#package-organization
             exit_code=2,
             activate_session=None)
         self.activate_session_mock.assert_not_called()
-        self.ensure_connection.called_once()
+        self.ensure_connection.assert_called_once()
 
     def test_handle_latest_build_help(self):
         self.assert_help(
diff --git a/tests/test_cli/test_untag_build.py b/tests/test_cli/test_untag_build.py
index d0cf5cc..e1c42c6 100644
--- a/tests/test_cli/test_untag_build.py
+++ b/tests/test_cli/test_untag_build.py
@@ -98,7 +98,7 @@ class TestUntagBuild(utils.CliTestCase):
         self.assert_console_message(stdout, expected)
         self.activate_session_mock.assert_called_once_with(self.session, self.options)
         self.session.getTag.assert_called_once_with(self.tag)
-        self.session.multicall.has_calls()
+        self.session.multicall.assert_called()
 
     @mock.patch('sys.stdout', new_callable=StringIO)
     def test_untag_build_all_verbose(self, stdout):
@@ -111,7 +111,7 @@ class TestUntagBuild(utils.CliTestCase):
         self.assert_console_message(stdout, expected)
         self.activate_session_mock.assert_called_once_with(self.session, self.options)
         self.session.getTag.assert_called_once_with(self.tag)
-        self.session.multicall.has_calls()
+        self.session.multicall.assert_called()
 
     @mock.patch('sys.stdout', new_callable=StringIO)
     def test_untag_build_all_non_latest_verbose(self, stdout):
@@ -125,7 +125,7 @@ class TestUntagBuild(utils.CliTestCase):
         self.assert_console_message(stdout, expected)
         self.activate_session_mock.assert_called_once_with(self.session, self.options)
         self.session.getTag.assert_called_once_with(self.tag)
-        self.session.multicall.has_calls()
+        self.session.multicall.assert_called()
 
     @mock.patch('sys.stdout', new_callable=StringIO)
     def test_untag_build_all_non_latest_verbose_only_one_pkg(self, stdout):
@@ -142,7 +142,7 @@ class TestUntagBuild(utils.CliTestCase):
         self.assert_console_message(stdout, expected)
         self.activate_session_mock.assert_called_once_with(self.session, self.options)
         self.session.getTag.assert_called_once_with(self.tag)
-        self.session.multicall.has_calls()
+        self.session.multicall.assert_called()
 
     @mock.patch('sys.stdout', new_callable=StringIO)
     def test_untag_build_all_non_latest_force_test(self, stdout):
diff --git a/tests/test_hub/test_delete_external_repo.py b/tests/test_hub/test_delete_external_repo.py
index d079ca4..2303f5b 100644
--- a/tests/test_hub/test_delete_external_repo.py
+++ b/tests/test_hub/test_delete_external_repo.py
@@ -37,7 +37,7 @@ class TestDeleteExternalRepo(unittest.TestCase):
         self.context_db.session.user_id = 23
         self.get_external_repo.return_value = {'id': repo_id}
         self.get_tag_external_repos.return_value = [{'id': repo_id, 'tag_id': tag_ids[0]},
-                                                    {'id': repo_id, 'tag_id': tag_ids[0]}]
+                                                    {'id': repo_id, 'tag_id': tag_ids[1]}]
         self.remove_external_repo_from_tag.side_effect = [None, None]
         kojihub.delete_external_repo(repo_id)
 
@@ -50,6 +50,6 @@ class TestDeleteExternalRepo(unittest.TestCase):
 
         self.get_external_repo.assert_called_once_with(123, strict=True)
         self.get_tag_external_repos.assert_called_once_with(repo_info=123)
-        self.remove_external_repo_from_tag.has_calls(
+        self.remove_external_repo_from_tag.assert_has_calls(
             [mock.call(tag_info=tag_ids[0], repo_info=repo_id),
              mock.call(tag_info=tag_ids[1], repo_info=repo_id)])
diff --git a/tests/test_hub/test_dist_repo.py b/tests/test_hub/test_dist_repo.py
index 3efb8c8..50bb4c7 100644
--- a/tests/test_hub/test_dist_repo.py
+++ b/tests/test_hub/test_dist_repo.py
@@ -123,7 +123,7 @@ class TestDistRepo(unittest.TestCase):
 
         ret = exports.distRepo('tag', 'keys')
 
-        session.hasPerm.has_calls(mock.call('dist_repo'), mock.call('admin'))
+        session.hasPerm.assert_has_calls([mock.call('dist-repo'), mock.call('admin')])
         assert_policy.assert_called_once_with('dist_repo', {'tag': 'tag'})
         dist_repo_init.assert_called_once()
         make_task.assert_called_once()
diff --git a/tests/test_hub/test_edit_build_target.py b/tests/test_hub/test_edit_build_target.py
index ac0d94e..0f4fd7c 100644
--- a/tests/test_hub/test_edit_build_target.py
+++ b/tests/test_hub/test_edit_build_target.py
@@ -47,9 +47,9 @@ class TestEditBuildTarget(unittest.TestCase):
             self.exports.editBuildTarget(self.target_name, self.name, self.build_tag,
                                          self.dest_tag)
         self.assertEqual(f"No such build target: {self.target_name}", str(cm.exception))
-        self.session.assertPerm.called_once_with('target')
-        self.verify_name_internal.called_once_with(name=self.name)
-        self.lookup_build_target.called_once_with(self.target_name)
+        self.session.assertPerm.assert_called_once_with('target')
+        self.verify_name_internal.assert_called_once_with(self.name)
+        self.lookup_build_target.assert_called_once_with(self.target_name)
 
     def test_target_wrong_format(self):
         name = 'build-target-rename+'
@@ -72,10 +72,10 @@ class TestEditBuildTarget(unittest.TestCase):
             self.exports.editBuildTarget(self.target_name, self.name, self.build_tag,
                                          self.dest_tag)
         self.assertEqual(f"build tag '{self.build_tag}' does not exist", str(cm.exception))
-        self.session.assertPerm.called_once_with('target')
-        self.verify_name_internal.called_once_with(name=self.name)
-        self.lookup_build_target.called_once_with(self.target_name)
-        self.get_tag.called_once_with(self.build_tag)
+        self.session.assertPerm.assert_called_once_with('target')
+        self.verify_name_internal.assert_called_once_with(self.name)
+        self.lookup_build_target.assert_called_once_with(self.target_name)
+        self.get_tag.assert_called_once_with(self.build_tag)
 
     def test_target_non_exist_dest_tag(self):
         self.verify_name_internal.return_value = None
@@ -85,10 +85,10 @@ class TestEditBuildTarget(unittest.TestCase):
             self.exports.editBuildTarget(self.target_name, self.name, self.build_tag,
                                          self.dest_tag)
         self.assertEqual(f"destination tag '{self.dest_tag}' does not exist", str(cm.exception))
-        self.session.assertPerm.called_once_with('target')
-        self.verify_name_internal.called_once_with(name=self.name)
-        self.lookup_build_target.called_once_with(self.target_name)
-        self.get_tag.has_calls([mock.call(self.build_tag), mock.call(self.dest_tag)])
+        self.session.assertPerm.assert_called_once_with('target')
+        self.verify_name_internal.assert_called_once_with(self.name)
+        self.lookup_build_target.assert_called_once_with(self.target_name)
+        self.get_tag.assert_has_calls([mock.call(self.build_tag), mock.call(self.dest_tag)])
 
     def test_target_exists(self):
         self.verify_name_internal.return_value = None
@@ -100,7 +100,7 @@ class TestEditBuildTarget(unittest.TestCase):
                                          self.dest_tag)
         self.assertEqual(f'name "{self.name}" is already taken by build target 2',
                          str(cm.exception))
-        self.session.assertPerm.called_once_with('target')
-        self.verify_name_internal.called_once_with(name=self.name)
-        self.lookup_build_target.called_once_with(self.target_name)
-        self.get_tag.has_calls([mock.call(self.build_tag), mock.call(self.dest_tag)])
+        self.session.assertPerm.assert_called_once_with('target')
+        self.verify_name_internal.assert_called_once_with(self.name)
+        self.lookup_build_target.assert_called_once_with(self.target_name)
+        self.get_tag.assert_has_calls([mock.call(self.build_tag), mock.call(self.dest_tag)])
diff --git a/tests/test_hub/test_pkglist.py b/tests/test_hub/test_pkglist.py
index 8f6d272..ded4a60 100644
--- a/tests/test_hub/test_pkglist.py
+++ b/tests/test_hub/test_pkglist.py
@@ -323,7 +323,7 @@ class TestPkglist(unittest.TestCase):
 
         self.get_tag.assert_called_once_with(self.tag['name'], strict=True)
         self.assertEqual(self.lookup_package.call_count, 1)
-        self.lookup_package.has_calls(mock.call(self.pkg['name'], strict=False))
+        self.lookup_package.assert_has_calls([mock.call(self.pkg['name'], strict=False)])
         self.get_user.assert_has_calls([
             mock.call(self.users[0]['name'], strict=True),
             mock.call(self.users[1]['id']),
@@ -345,7 +345,7 @@ class TestPkglist(unittest.TestCase):
 
         self.get_tag.assert_called_once_with(self.tag['name'], strict=True)
         self.assertEqual(self.lookup_package.call_count, 1)
-        self.lookup_package.has_calls(mock.call(self.pkg['name'], strict=False))
+        self.lookup_package.assert_has_calls([mock.call(self.pkg['name'], strict=False)])
         self.get_user.assert_not_called()
         self.assert_policy.assert_not_called()
         self.assertEqual(self.run_callbacks.call_count, 0)
@@ -388,9 +388,9 @@ class TestPkglist(unittest.TestCase):
 
         self.get_tag.assert_called_once_with(self.tag['name'], strict=True)
         self.assertEqual(self.lookup_package.call_count, 2)
-        self.lookup_package.has_calls(
-            mock.call(self.pkg['name'], strict=False),
-            mock.call(self.pkg['name'], create=True),
+        self.lookup_package.assert_has_calls(
+            [mock.call(self.pkg['name'], strict=False),
+             mock.call(self.pkg['name'], create=True),]
         )
         self.get_user.assert_has_calls([
             mock.call(self.users[0]['name'], strict=True),
@@ -417,9 +417,9 @@ class TestPkglist(unittest.TestCase):
 
         self.get_tag.assert_called_once_with(self.tag['name'], strict=True)
         self.assertEqual(self.lookup_package.call_count, 2)
-        self.lookup_package.has_calls(
-            mock.call(self.pkg['name'], strict=False),
-            mock.call(self.pkg['name'], create=True),
+        self.lookup_package.assert_has_calls(
+            [mock.call(self.pkg['name'], strict=False),
+             mock.call(self.pkg['name'], create=True),]
         )
         self.get_user.assert_called_once_with(self.users[1]['id'])
         self.assert_policy.assert_not_called()
@@ -446,9 +446,9 @@ class TestPkglist(unittest.TestCase):
 
         self.get_tag.assert_called_once_with(self.tag['name'], strict=True)
         self.assertEqual(self.lookup_package.call_count, 2)
-        self.lookup_package.has_calls(
-            mock.call(self.pkg['name'], strict=False),
-            mock.call(self.pkg['name'], create=True),
+        self.lookup_package.assert_has_calls(
+            [mock.call(self.pkg['name'], strict=False),
+             mock.call(self.pkg['name'], create=True),]
         )
         self.get_user.assert_called_once_with(self.users[1]['id'])
         self.assert_policy.assert_not_called()
@@ -486,9 +486,9 @@ class TestPkglist(unittest.TestCase):
 
         self.get_tag.assert_called_once_with(self.tag['name'], strict=True)
         self.assertEqual(self.lookup_package.call_count, 2)
-        self.lookup_package.has_calls(
-            mock.call(self.pkg['name'], strict=False),
-            mock.call(self.pkg['name'], create=True),
+        self.lookup_package.assert_has_calls(
+            [mock.call(self.pkg['name'], strict=False),
+             mock.call(self.pkg['name'], create=True)],
         )
         self.get_user.assert_called_once_with(self.users[1]['id'])
         self.assert_policy.assert_not_called()
@@ -519,9 +519,9 @@ class TestPkglist(unittest.TestCase):
 
         self.get_tag.assert_called_once_with(self.tag['name'], strict=True)
         self.assertEqual(self.lookup_package.call_count, 2)
-        self.lookup_package.has_calls(
-            mock.call(pkg['name'], strict=False),
-            mock.call(pkg['name'], create=True),
+        self.lookup_package.assert_has_calls(
+            [mock.call(pkg['name'], strict=False),
+             mock.call(pkg['name'], create=True),]
         )
         self.get_user.assert_has_calls([
             mock.call(self.users[0]['name'], strict=True),
@@ -557,9 +557,9 @@ class TestPkglist(unittest.TestCase):
 
         self.get_tag.assert_called_once_with(self.tag['name'], strict=True)
         self.assertEqual(self.lookup_package.call_count, 2)
-        self.lookup_package.has_calls(
-            mock.call(self.pkg['name'], strict=False),
-            mock.call(self.pkg['name'], create=True),
+        self.lookup_package.assert_has_calls(
+            [mock.call(self.pkg['name'], strict=False),
+             mock.call(self.pkg['name'], create=True),]
         )
         self.get_user.assert_has_calls([
             mock.call(self.users[0]['name'], strict=True),
diff --git a/tests/test_hub/test_tag_operations.py b/tests/test_hub/test_tag_operations.py
index b77bdf0..4429356 100644
--- a/tests/test_hub/test_tag_operations.py
+++ b/tests/test_hub/test_tag_operations.py
@@ -87,9 +87,8 @@ class TestTagBuild(unittest.TestCase):
         # call it
         kojihub._tag_build('sometag', 'name-version-release')
 
-        self.get_tag.called_once_with('sometag', strict=True)
-        self.get_build.called_once_with('name-version-release', strict=True)
-        self.context.session.assertPerm.called_with('admin')
+        self.get_tag.assert_called_once_with('sometag', strict=True)
+        self.get_build.assert_called_once_with('name-version-release', strict=True)
 
         # check the insert
         self.assertEqual(len(self.inserts), 1)
@@ -117,9 +116,9 @@ class TestTagBuild(unittest.TestCase):
         # call it
         kojihub._tag_build('sometag', 'name-version-release', user_id=self.userinfo['id'])
 
-        self.get_tag.called_once_with('sometag', strict=True)
+        self.get_tag.assert_called_once_with('sometag', strict=True)
         self.get_user.called_one_with(self.userinfo['id'], strict=True)
-        self.get_build.called_once_with('name-version-release', strict=True)
+        self.get_build.assert_called_once_with('name-version-release', strict=True)
         self.context.session.assertPerm.assert_not_called()
 
         # check the insert
@@ -148,9 +147,8 @@ class TestTagBuild(unittest.TestCase):
         # call it
         kojihub._untag_build('sometag', 'name-version-release')
 
-        self.get_tag.called_once_with('sometag', strict=True)
-        self.get_build.called_once_with('name-version-release', strict=True)
-        self.context.session.assertPerm.called_with('admin')
+        self.get_tag.assert_called_once_with('sometag', strict=True)
+        self.get_build.assert_called_once_with('name-version-release', strict=True)
         self.assertEqual(len(self.inserts), 0)
 
         # check the update
@@ -182,9 +180,9 @@ class TestTagBuild(unittest.TestCase):
         # call it
         kojihub._untag_build('sometag', 'name-version-release', user_id=self.userinfo['id'])
 
-        self.get_tag.called_once_with('sometag', strict=True)
-        self.get_user.called_one_with(self.userinfo['id'], strict=True)
-        self.get_build.called_once_with('name-version-release', strict=True)
+        self.get_tag.assert_called_once_with('sometag', strict=True)
+        self.get_user.assert_called_once_with(self.userinfo['id'], strict=True)
+        self.get_build.assert_called_once_with('name-version-release', strict=True)
         self.context.session.assertPerm.assert_not_called()
         self.assertEqual(len(self.inserts), 0)
 
diff --git a/tests/test_hub/test_user_groups.py b/tests/test_hub/test_user_groups.py
index 98e9b5c..d007444 100644
--- a/tests/test_hub/test_user_groups.py
+++ b/tests/test_hub/test_user_groups.py
@@ -62,7 +62,7 @@ class TestGrouplist(unittest.TestCase):
         with self.assertRaises(koji.GenericError):
             kojihub.new_group(name)
         self.context.session.assertPerm.assert_called_with('admin')
-        self.context.session.createUser.not_called()
+        self.context.session.createUser.assert_not_called()
 
         # user already exists
         self.context.session.assertPerm.side_effect = None
@@ -70,14 +70,14 @@ class TestGrouplist(unittest.TestCase):
         with self.assertRaises(koji.GenericError):
             kojihub.new_group(name)
         self.context.session.assertPerm.assert_called_with('admin')
-        self.context.session.createUser.not_called()
+        self.context.session.createUser.assert_not_called()
 
         # valid
         self.context.session.assertPerm.side_effect = None
         self.get_user.return_value = None
         kojihub.new_group(name)
         self.context.session.assertPerm.assert_called_with('admin')
-        self.context.session.createUser.called_with(name, usertype=koji.USERTYPES['GROUP'])
+        self.context.session.createUser.assert_called_with(name, usertype=koji.USERTYPES['GROUP'])
 
         # name is longer as expected
         name = 'new-group+'

From 1b8b96a70da393423714b68a13712d6e414e7126 Mon Sep 17 00:00:00 2001
From: Jana Cupova <root@localhost>
Date: Jan 02 2024 13:32:56 +0000
Subject: [PATCH 2/2] Add allowed versions of requests-mock for tests


---

diff --git a/test-requirements-py2.txt b/test-requirements-py2.txt
new file mode 100644
index 0000000..4a90729
--- /dev/null
+++ b/test-requirements-py2.txt
@@ -0,0 +1,7 @@
+-e .
+flake8
+flake8-import-order
+mock<=2.0.0
+requests-mock<1.11.0
+coverage
+pytest
diff --git a/tox.ini b/tox.ini
index 62eb2f9..34b990c 100644
--- a/tox.ini
+++ b/tox.ini
@@ -19,7 +19,6 @@ commands =
 [testenv]
 deps =
     -r{toxinidir}/requirements.txt
-    -r{toxinidir}/test-requirements.txt
 # We need to access python-rpm, at least, and potentially more on EL6
 sitepackages = true
 # Tell the rpm-py-installer package to download binaries instead of building
@@ -38,7 +37,7 @@ commands_pre =
 
 [testenv:py3]
 deps =
-    coverage
+    -r{toxinidir}/test-requirements.txt
 allowlist_externals = coverage3
 setenv = 
     {[testenv]setenv}
@@ -52,7 +51,9 @@ commands =
     coverage3 html -d {toxinidir}/htmlcov/py3 --rcfile .coveragerc3
 
 [testenv:py2]
-setenv = 
+deps =
+    -r{toxinidir}/test-requirements-py2.txt
+setenv =
     {[testenv]setenv}
     PYTHONPATH=.:plugins/builder/.:plugins/cli/.:cli/.:www/lib
     PYTHONHASHSEED=0
@@ -75,7 +76,7 @@ commands =
 # dependencies must be installed.
 [testenv:py2-rpmdeps]
 deps =
-    -r{toxinidir}/test-requirements.txt
+    -r{toxinidir}/test-requirements-py2.txt
 setenv =
     {[testenv:py2]setenv}
 commands_pre =

