From 213c58141fafafc15e7f3b1006dd30fe2f014123 Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: Sep 08 2025 14:17:44 +0000
Subject: [PATCH 1/2] fix some mocking in unit tests


---

diff --git a/tests/test_plugins/test_kiwi_builder.py b/tests/test_plugins/test_kiwi_builder.py
index ae0fa57..7c7b4fc 100644
--- a/tests/test_plugins/test_kiwi_builder.py
+++ b/tests/test_plugins/test_kiwi_builder.py
@@ -29,10 +29,13 @@ class TestKiwiBuildTask(unittest.TestCase):
         self.options.allowed_scms = 'allowed_scms'
         self.options.allowed_scms_use_config = False
         self.options.allowed_scms_use_policy = True
-        kiwi.SCM = mock.MagicMock(side_effect=self.SCM)
-        koji.ensuredir = mock.MagicMock()
+        mock.patch.object(kiwi, 'SCM', side_effect=self.SCM).start()
+        mock.patch('koji.ensuredir').start()
         self.task = kiwi.KiwiBuildTask(123, 'kiwiBuild', {}, self.session, self.options)
 
+    def tearDown(self):
+        mock.patch.stopall()
+
     def test_get_nrvp_invalid_xml(self):
         # missing file
         with self.assertRaises(koji.GenericError):
diff --git a/tests/test_plugins/test_sidetag_hub.py b/tests/test_plugins/test_sidetag_hub.py
index ed0dd3a..e8c22a2 100644
--- a/tests/test_plugins/test_sidetag_hub.py
+++ b/tests/test_plugins/test_sidetag_hub.py
@@ -29,6 +29,8 @@ class TestCreateSideTagHub(unittest.TestCase):
             'id': 23,
             'name': 'username',
         }
+        mock.patch('sidetag_hub.ALLOWED_SUFFIXES', new=['suffix', 'another']).start()
+        mock.patch('sidetag_hub.NAME_TEMPLATE', new='{basetag}-sidetagTEST-{tag_id}').start()
 
     def tearDown(self):
         mock.patch.stopall()
@@ -42,7 +44,7 @@ class TestCreateSideTagHub(unittest.TestCase):
 
     def test_createsidetag_basic(self):
         self.query_executeOne.return_value = {'user_tags': 0}
-        sidetag_name = 'base_tag-side-12346'
+        sidetag_name = 'base_tag-sidetagTEST-12346'
         self.context.session.assertLogin = mock.MagicMock()
         self.context.session.user_id = 23
         self.get_user.return_value = self.user
@@ -72,17 +74,16 @@ class TestCreateSideTagHub(unittest.TestCase):
 
     def test_createsidetag_template_valid_and_debuginfo(self):
         self.query_executeOne.return_value = {'user_tags': 0}
-        sidetag_name = 'base_tag-sidetag-12346-suffix'
+        sidetag_name = 'base_tag-sidetagTEST-12346-suffix'
         self.context.session.assertLogin = mock.MagicMock()
         self.context.session.user_id = 23
         self.get_user.return_value = self.user
         self.get_tag.return_value = self.basetag
         self.nextval.return_value = 12345
         self._create_tag.return_value = 12346
-        sidetag_hub.ALLOWED_SUFFIXES = ['suffix', 'another']
-        sidetag_hub.NAME_TEMPLATE = '{basetag}-sidetag-{tag_id}'
 
         ret = sidetag_hub.createSideTag('base_tag', debuginfo=True, suffix='suffix')
+
         self.assertEqual(ret, {'name': sidetag_name, 'id': 12346, 'task_id': None, 'request': None})
 
     def test_createsidetag_template_forbidden_suffix(self):
@@ -104,8 +105,6 @@ class TestCreateSideTagHub(unittest.TestCase):
         self.context.session.user_id = 23
         self.get_user.return_value = self.user
         self.get_tag.return_value = self.basetag
-        sidetag_hub.ALLOWED_SUFFIXES = ['suffix', 'another']
-        sidetag_hub.NAME_TEMPLATE = '{basetag}-sidetag-{tag_id}'
 
         with self.assertRaises(koji.GenericError) as ex:
             sidetag_hub.createSideTag('base_tag', suffix='suffix')

From 820e2eb62cb746919106ac1a53135852fb326aff Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: Sep 10 2025 20:35:19 +0000
Subject: [PATCH 2/2] stabilize file list in test_draft_backlink.py


---

diff --git a/tests/test_hub/test_draft_backlink.py b/tests/test_hub/test_draft_backlink.py
index 36eb9d2..d84a7a5 100644
--- a/tests/test_hub/test_draft_backlink.py
+++ b/tests/test_hub/test_draft_backlink.py
@@ -149,7 +149,9 @@ class TestEnsureDraftBacklink(unittest.TestCase):
 
 def find_files(dirpath):
     '''Find all files under dir, report relative paths'''
-    for path, dirs, files in os.walk(dirpath):
+    for path, dirs, files in os.walk(dirpath, topdown=True):
+        # sort dirs in place for consistent traversal
+        dirs.sort()
         for fn in sorted(dirs + files):
             yield os.path.relpath(os.path.join(path, fn), dirpath)
 

