def test_messaging_callback_greenwave(self, Handler): msg = Message(topic="org.fedoraproject.prod.greenwave.decision.update", body={}) handler = mock.Mock() Handler.side_effect = lambda: handler Consumer()(msg) handler.assert_called_once_with(msg)
def test_messaging_callback_exception(self, error): """Test catching an exception when processing messages.""" msg = Message( topic="org.fedoraproject.prod.buildsys.tag", body={} ) consumer = Consumer() with mock.patch.object( consumer, 'handler_infos', [HandlerInfo('.buildsys.tag', 'Automatic Update', mock.Mock())], ) as handler_infos: with pytest.raises(Nack) as exc: handler_infos[0].handler.side_effect = Exception("Something bad happened") consumer(msg) logmsg = (f"Something bad happened: Unable to handle message in " f"{consumer.handler_infos[-1].name} handler: {msg}") error.assert_called_with(logmsg) excmsg = ("Unable to (fully) handle message.\nAffected handlers:\n" + "".join(f"\t{hi.name}: Something bad happened\n" for hi in consumer.handler_infos) + "Message:\n{msg}") assert str(exc.value) == excmsg
def test_messaging_callback_resultsdb(self, Handler): msg = Message(topic="org.fedoraproject.prod.resultsdb.result.new", body={}) handler = mock.Mock() Handler.side_effect = lambda: handler Consumer()(msg) handler.assert_called_once_with(msg)
def test_messaging_callback_signed(self, Handler): msg = Message(topic="org.fedoraproject.prod.buildsys.tag", body={}) handler = mock.Mock() Handler.side_effect = lambda: handler Consumer()(msg) handler.assert_called_once_with(msg)
def test_messaging_callback_updates_edit(self, Handler): msg = Message(topic="org.fedoraproject.prod.bodhi.update.edit", body={}) handler = mock.Mock() Handler.side_effect = lambda: handler Consumer()(msg) handler.assert_called_once_with(msg)
def test_messaging_callback_composer_installed(self, Handler): """Test receiving a composer.start message when the composer is installed.""" msg = Message(topic="org.fedoraproject.prod.bodhi.composer.start", body={}) handler = mock.Mock() Handler.side_effect = lambda: handler Consumer()(msg) handler.assert_called_once_with(msg)
def test__init___(self, info, initialize_db, setup_buildsystem, set_bugtracker): """Test the __init__() method.""" consumer = Consumer() assert any(x.name == 'Signed' and isinstance(x.handler, signed.SignedHandler) for x in consumer.handler_infos) info.assert_called_once_with('Initializing Bodhi') initialize_db.assert_called_once_with(config.config) setup_buildsystem.assert_called_once_with(config.config) set_bugtracker.assert_called_once_with()
def test__init___with_composer(self, info, initialize_db, setup_buildsystem, set_bugtracker): """Test the __init__() method when the composer is installed.""" consumer = Consumer() self.assertTrue(isinstance(consumer.composer_handler, composer.ComposerHandler)) self.assertTrue(isinstance(consumer.signed_handler, signed.SignedHandler)) self.assertTrue(isinstance(consumer.updates_handler, updates.UpdatesHandler)) info.assert_called_once_with('Initializing Bodhi') initialize_db.assert_called_once_with(config.config) setup_buildsystem.assert_called_once_with(config.config) set_bugtracker.assert_called_once_with()
def test_messaging_callback_composer_not_installed(self, error): """Test receiving a composer.start message when the composer is not installed.""" msg = Message(topic="org.fedoraproject.prod.bodhi.composer.start", body={}) with self.assertRaises(Nack) as exc: Consumer()(msg) msg = ( 'Unable to process composer.start message topics because the Composer is not ' f'installed: Unable to handle message: {msg}') error.assert_called_once_with(msg) self.assertEqual(str(exc.exception), msg)
def test_messaging_callback_signed_automatic_update( self, SignedHandler, AutomaticUpdateHandler): msg = Message(topic="org.fedoraproject.prod.buildsys.tag", body={}) signed_handler = mock.Mock() SignedHandler.side_effect = lambda: signed_handler automatic_update_handler = mock.Mock() AutomaticUpdateHandler.side_effect = lambda: automatic_update_handler Consumer()(msg) signed_handler.assert_called_once_with(msg) automatic_update_handler.assert_called_once_with(msg)
def test__init___without_composer(self, info, initialize_db, setup_buildsystem, set_bugtracker): """Test the __init__() method when the composer is not installed.""" consumer = Consumer() self.assertIsNone(consumer.composer_handler) self.assertTrue(isinstance(consumer.signed_handler, signed.SignedHandler)) self.assertTrue(isinstance(consumer.updates_handler, updates.UpdatesHandler)) self.assertEqual( info.mock_calls, [mock.call('Initializing Bodhi'), mock.call('The composer is not installed - Bodhi will ignore composer.start ' 'messages.')]) initialize_db.assert_called_once_with(config.config) setup_buildsystem.assert_called_once_with(config.config) set_bugtracker.assert_called_once_with()