| |
@@ -44,6 +44,11 @@
|
| |
except ImportError:
|
| |
fedmsg = None
|
| |
|
| |
+ try:
|
| |
+ import fedora_messaging
|
| |
+ except ImportError:
|
| |
+ fedora_messaging = None
|
| |
+
|
| |
|
| |
@unittest.skipUnless(rhmsg, 'rhmsg is required to run this test case.')
|
| |
@unittest.skipIf(six.PY3, 'rhmsg has no Python 3 package so far.')
|
| |
@@ -152,3 +157,60 @@
|
| |
compose.state = COMPOSE_STATES['generating']
|
| |
|
| |
self.assert_messaging(compose)
|
| |
+
|
| |
+
|
| |
+ @unittest.skipUnless(fedora_messaging, 'fedora_messaging is required to run this test case.')
|
| |
+ class TestFedoraMessagingSendMessageWhenComposeIsCreated(ModelsBaseTest):
|
| |
+ """Test send message when compose is created"""
|
| |
+
|
| |
+ disable_event_handlers = False
|
| |
+
|
| |
+ def setUp(self):
|
| |
+ super(TestFedoraMessagingSendMessageWhenComposeIsCreated, self).setUp()
|
| |
+
|
| |
+ # Real lock is not required for running tests
|
| |
+ self.mock_lock = patch('threading.Lock')
|
| |
+ self.mock_lock.start()
|
| |
+
|
| |
+ def tearDown(self):
|
| |
+ self.mock_lock.stop()
|
| |
+
|
| |
+ def setup_composes(self):
|
| |
+ self.compose = Compose.create(db.session,
|
| |
+ "mine",
|
| |
+ PungiSourceType.KOJI_TAG,
|
| |
+ "f25",
|
| |
+ COMPOSE_RESULTS["repository"],
|
| |
+ 3600)
|
| |
+ db.session.commit()
|
| |
+
|
| |
+ @patch.object(conf, 'messaging_backend', new='fedora-messaging')
|
| |
+ @patch('fedora_messaging.api.Message')
|
| |
+ @patch('fedora_messaging.api.publish')
|
| |
+ def assert_messaging(self, compose, publish, Message):
|
| |
+ # The db.session.commit() calls on-commit handler which produces the fedora-messaging
|
| |
+ # message.
|
| |
+ db.session.commit()
|
| |
+
|
| |
+ Message.assert_called_once_with(
|
| |
+ topic="compose.state-changed",
|
| |
+ body={'event': 'state-changed', 'compose': compose.json()})
|
| |
+
|
| |
+ publish.assert_called_once_with(Message.return_value)
|
| |
+
|
| |
+ def test_send_message(self):
|
| |
+ compose = Compose.create(db.session,
|
| |
+ "me",
|
| |
+ PungiSourceType.MODULE,
|
| |
+ "testmodule-master",
|
| |
+ COMPOSE_RESULTS["repository"],
|
| |
+ 3600)
|
| |
+
|
| |
+ self.assert_messaging(compose)
|
| |
+
|
| |
+ def test_message_on_state_change(self):
|
| |
+ compose = db.session.query(Compose).filter(
|
| |
+ Compose.id == self.compose.id).all()[0]
|
| |
+ compose.state = COMPOSE_STATES['generating']
|
| |
+
|
| |
+ self.assert_messaging(compose)
|
| |
While upgrading ODCS in Fedora to latest version, I've also decided
to port it to fedora-messaging. This is quite easy for ODCS, because
we only send message to the bus.