async def test_should_store_data_on_message(self, template, callback): message = Mock(1) message.body = "testing" self.behaviour.receive.return_value = message await self.behaviour.run() self.behaviour.receive.assert_awaited_once_with() self.agent.add_behaviour.assert_called_once_with( callback(), template(body="testing"))
async def test_should_not_call_callback_for_valid_message(self): self.barterdude.consume_amqp(["queue"], self.monitor, validation_schema=self.schema)( self.callback) self.decorator.assert_called_once() wrapper = self.decorator.call_args[0][0] message = Mock(Message) message.body = {"wrong": 'ok'} await wrapper([message]) self.callback.assert_not_called()
async def test_compress_decorator(compress, body, called, expected): cls = Mock() request = Mock() cls.compress = compress cls.body = body cls.func = CoroutineMock() cls.func = _add_compress_header(cls.func) await cls.func(cls, request) assert request.add_header.called is called if request.add_header.call_args: assert isinstance(request.add_header.call_args[0][0], expected)
def test_should_work_with_no_dict(self): test_message = "value" rbmq_message = Mock(RabbitMQMessage) rbmq_message.body = test_message message = Message(rbmq_message) self.assertEqual(message.body, test_message)