def test_rpc_consumer(get_rpc_exchange, queue_consumer, mock_container): container = mock_container container.shared_extensions = {} container.config = {} container.service_name = "exampleservice" container.service_cls = Mock(rpcmethod=lambda: None) exchange = Mock() get_rpc_exchange.return_value = exchange consumer = RpcConsumer().bind(container) entrypoint = Rpc().bind(container, "rpcmethod") entrypoint.rpc_consumer = consumer entrypoint.setup() consumer.setup() queue_consumer.setup() queue = consumer.queue assert queue.name == "rpc-exampleservice" assert queue.routing_key == "exampleservice.*" assert queue.exchange == exchange assert queue.durable queue_consumer.register_provider.assert_called_once_with(consumer) consumer.register_provider(entrypoint) assert consumer._providers == set([entrypoint]) routing_key = "exampleservice.rpcmethod" assert consumer.get_provider_for_method(routing_key) == entrypoint routing_key = "exampleservice.invalidmethod" with pytest.raises(MethodNotFound): consumer.get_provider_for_method(routing_key) consumer.unregister_provider(entrypoint) assert consumer._providers == set()
def test_rpc_invalid_message(): entrypoint = Rpc() with pytest.raises(MalformedRequest) as exc: entrypoint.handle_message({'args': ()}, None) # missing 'kwargs' assert 'Message missing `args` or `kwargs`' in str(exc)