async def test_startup_registers_one_connection_per_vhost_into_app_state( self, register): conn = AMQPConnection( hostname="127.0.0.1", username="******", password="******", prefetch=1024, ) app = App(connections=[conn]) app.routes_registry = self.routes_registry await self.signal_handler.startup(app) self.assertIn(conn, app.connections) register.assert_has_calls([ call(consumer.queue) for consumer in app[RouteTypes.AMQP_RABBITMQ]["consumers"] ])
async def test_startup_registers_one_connection_per_vhost_into_app_state( self, register): app = App( host="127.0.0.1", user="******", password="******", prefetch_count=1024, ) app.routes_registry = self.routes_registry await self.signal_handler.startup(app) self.assertIsInstance(app[RouteTypes.AMQP_RABBITMQ]["connection"], AMQPConnection) register.assert_has_calls([ call(consumer.queue) for consumer in app[RouteTypes.AMQP_RABBITMQ]["consumers"] ])
async def test_startup_initializes_and_starts_one_consumer_per_route( self, Consumer): connection = AMQPConnection( hostname="127.0.0.1", username="******", password="******", prefetch=1024, ) app = App(connections=[connection]) app.routes_registry = self.routes_registry app.loop = Mock(create_task=CoroutineMock()) # asynctest.MagicMock( # routes_registry=, # loop=Mock(create_task=CoroutineMock()), # ) app[RouteTypes.AMQP_RABBITMQ] = {"connections": [connection]} await self.signal_handler.startup(app) Consumer.assert_has_calls( [ call( route_info=self.routes_registry.amqp_routes[0], host=connection.hostname, username=connection.username, password=connection.password, prefetch_count=connection.prefetch, ), call( route_info=self.routes_registry.amqp_routes[1], host=connection.hostname, username=connection.username, password=connection.password, prefetch_count=connection.prefetch, ), ], any_order=True, ) Consumer.return_value.start.assert_has_calls([call(), call()]) self.assertEqual( app[RouteTypes.AMQP_RABBITMQ]["consumers"], [Consumer.return_value, Consumer.return_value], )