From e927d49e3c59200f7446aa3555eb0880b333f99b Mon Sep 17 00:00:00 2001
From: mprahl <mprahl@redhat.com>
Date: Nov 26 2019 15:54:26 +0000
Subject: [PATCH 1/2] ConsumerBaseTest to tests/helpers


This is so that it can be reused by other test classes.

---

diff --git a/tests/helpers.py b/tests/helpers.py
index 41944d6..5ce2012 100644
--- a/tests/helpers.py
+++ b/tests/helpers.py
@@ -473,3 +473,21 @@ class PDCModuleInfo(PDCModuleInfoFactory):
 
     def add_rpm(self, rpm):
         self.rpms.append(rpm)
+
+
+class ConsumerBaseTest(ModelsTestCase):
+
+    def _compose_state_change_msg(self, state=None):
+        msg = {'body': {
+            "msg_id": "2017-7afcb214-cf82-4130-92d2-22f45cf59cf7",
+            "topic": "org.fedoraproject.prod.odcs.state.change",
+            "signature": "qRZ6oXBpKD/q8BTjBNa4MREkAPxT+KzI8Oret+TSKazGq/6gk0uuprdFpkfBXLR5dd4XDoh3NQWp\nyC74VYTDVqJR7IsEaqHtrv01x1qoguU/IRWnzrkGwqXm+Es4W0QZjHisBIRRZ4ywYBG+DtWuskvy\n6/5Mc3dXaUBcm5TnT0c=\n",
+            "msg": {
+                "compose": {
+                    "id": 1,
+                    "state": 4,
+                }
+            }
+        }}
+
+        return msg
diff --git a/tests/test_consumer.py b/tests/test_consumer.py
index 5628d1f..7bb2f33 100644
--- a/tests/test_consumer.py
+++ b/tests/test_consumer.py
@@ -31,25 +31,7 @@ from freshmaker.handlers import fail_event_on_handler_exception
 from tests import helpers
 
 
-class ConsumerBaseTest(helpers.ModelsTestCase):
-
-    def _compose_state_change_msg(self, state=None):
-        msg = {'body': {
-            "msg_id": "2017-7afcb214-cf82-4130-92d2-22f45cf59cf7",
-            "topic": "org.fedoraproject.prod.odcs.state.change",
-            "signature": "qRZ6oXBpKD/q8BTjBNa4MREkAPxT+KzI8Oret+TSKazGq/6gk0uuprdFpkfBXLR5dd4XDoh3NQWp\nyC74VYTDVqJR7IsEaqHtrv01x1qoguU/IRWnzrkGwqXm+Es4W0QZjHisBIRRZ4ywYBG+DtWuskvy\n6/5Mc3dXaUBcm5TnT0c=\n",
-            "msg": {
-                "compose": {
-                    "id": 1,
-                    "state": 4,
-                }
-            }
-        }}
-
-        return msg
-
-
-class ConsumerTest(ConsumerBaseTest):
+class ConsumerTest(helpers.ConsumerBaseTest):
 
     @mock.patch("freshmaker.handlers.internal.UpdateDBOnODCSComposeFail.handle")
     @mock.patch("freshmaker.consumer.get_global_consumer")
@@ -165,7 +147,7 @@ class ConsumerTest(ConsumerBaseTest):
             self.assertTrue(build.state_reason, "Failed with traceback")
 
 
-class ParseBrewSignRPMEventTest(ConsumerBaseTest):
+class ParseBrewSignRPMEventTest(helpers.ModelsTestCase):
 
     @mock.patch('freshmaker.events.conf.parsers',
                 new=['freshmaker.parsers.brew.sign_rpm:BrewSignRpmParser'])

From d8bfc8f844ec9f64c2ef010e4c2399db6bb2f82e Mon Sep 17 00:00:00 2001
From: mprahl <mprahl@redhat.com>
Date: Nov 26 2019 15:54:35 +0000
Subject: [PATCH 2/2] Fix the unit tests from an issue in PR #444


---

diff --git a/tests/helpers.py b/tests/helpers.py
index 5ce2012..7eb150d 100644
--- a/tests/helpers.py
+++ b/tests/helpers.py
@@ -26,7 +26,7 @@ import uuid
 import unittest
 import koji
 
-from mock import patch, MagicMock
+from mock import patch, MagicMock, PropertyMock
 from functools import wraps
 
 import freshmaker.consumer
@@ -477,6 +477,32 @@ class PDCModuleInfo(PDCModuleInfoFactory):
 
 class ConsumerBaseTest(ModelsTestCase):
 
+    def setUp(self):
+        super(ConsumerBaseTest, self).setUp()
+        self.patched_parsers = patch(
+            "freshmaker.config.Config.parsers",
+            new_callable=PropertyMock,
+            return_value=[
+                "freshmaker.parsers.internal:FreshmakerManualRebuildParser",
+                "freshmaker.parsers.odcs:ComposeStateChangeParser",
+            ]
+        )
+        self.patched_parsers.start()
+        self.patched_handlers = patch(
+            "freshmaker.config.Config.handlers",
+            new_callable=PropertyMock,
+            return_value=[
+                "freshmaker.handlers.internal:UpdateDBOnODCSComposeFail",
+                "freshmaker.handlers.koji:RebuildImagesOnODCSComposeDone",
+            ]
+        )
+        self.patched_handlers.start()
+
+    def tearDown(self):
+        super(ConsumerBaseTest, self).setUp()
+        self.patched_parsers.stop()
+        self.patched_handlers.stop()
+
     def _compose_state_change_msg(self, state=None):
         msg = {'body': {
             "msg_id": "2017-7afcb214-cf82-4130-92d2-22f45cf59cf7",
diff --git a/tests/test_monitor.py b/tests/test_monitor.py
index 5d2f6c0..7bf66df 100644
--- a/tests/test_monitor.py
+++ b/tests/test_monitor.py
@@ -60,7 +60,7 @@ class TestViews(helpers.ModelsTestCase):
                  if l.startswith('# TYPE')]), num_of_metrics)
 
 
-class ConsumerTest(helpers.ModelsTestCase):
+class ConsumerTest(helpers.ConsumerBaseTest):
     def setUp(self):
         super(ConsumerTest, self). setUp()
         self.client = app.test_client()

