class TestJSONTranslator(object): def setup_class(self): self.middleware = JSONTranslator() def test_request_content_lenght_none(self): result = self.middleware.process_request( req=mock.Mock(content_length=None), resp=mock.Mock()) assert result is None def test_request_no_body(self): with pytest.raises(falcon.HTTPBadRequest): # TODO: Search for a better way to mock this self.middleware.process_request(req=mock.Mock(stream=mock.Mock( read=mock.Mock(return_value=None))), resp=mock.Mock()) def test_response_no_result(self): result = self.middleware.process_response(req=mock.Mock(context={}), resp=mock.Mock(), resource=mock.Mock()) assert result is None def test_response_success(self): resp = mock.Mock() self.middleware.process_response( req=mock.Mock(context={'result': 'mocked_resp'}), resp=resp, resource=mock.Mock()) assert resp.body == '"mocked_resp"'
class TestJSONTranslator(object): def setup_class(self): self.middleware = JSONTranslator() def test_request_content_lenght_none(self): result = self.middleware.process_request( req=mock.Mock(content_length=None), resp=mock.Mock()) assert result is None def test_request_no_body(self): with pytest.raises(falcon.HTTPBadRequest): # TODO: Search for a better way to mock this self.middleware.process_request( req=mock.Mock(stream=mock.Mock( read=mock.Mock(return_value=None))), resp=mock.Mock()) def test_response_no_result(self): result = self.middleware.process_response( req=mock.Mock(context={}), resp=mock.Mock(), resource=mock.Mock()) assert result is None def test_response_success(self): resp = mock.Mock() self.middleware.process_response( req=mock.Mock(context={'result': 'mocked_resp'}), resp=resp, resource=mock.Mock()) assert resp.body == '"mocked_resp"'
""" It is just a example using HTTP falcon library. You can create and expose a Publisher API using RPC or anything else. You can also create your own falcon Resource. You can run it using: gunicorn -b 0.0.0.0:8000 example.publisher:app If you want to start more publishers using different routing_keys, you can just create different routes like: app.add_route('/publish/routing_key1', PublishResource(backend=RabbitMQPublisher(config1))) app.add_route('/publish/routing_key2', PublishResource(backend=RabbitMQPublisher(config2))) """ # NOQA import falcon from qpaca.middleware import JSONTranslator, RequireJSON from qpaca.resource import PublishResource from qpaca.backend.rabbitmq import RabbitMQPublisher app = falcon.API(middleware=[ RequireJSON(), JSONTranslator(), ]) # Routes app.add_route('/publish/', PublishResource(publisher=RabbitMQPublisher()))
def setup_class(self): self.middleware = JSONTranslator()