How to use the rele.middleware.register_middleware function in rele

To help you get started, we’ve selected a few rele examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mercadona / rele / tests / apm / test_apm_plugin.py View on Github external
def test_message_is_published_even_when_apm_fails_setting_up_apm(
            self, publisher, config):
        with patch('rele.contrib.apm_middleware.'
                   'Client.__init__') as client_mock:
            client_mock.side_effect = Exception(
                'Something went wrong initializing APM'
            )
            config.middleware = ['rele.contrib.APMMiddleware']
            register_middleware(config)

            publisher.publish(
                topic='order-cancelled',
                data={'foo': 'bar'},
                myattr='hello'
            )

            assert publisher._client.publish.called_once()
github mercadona / rele / tests / apm / test_apm_plugin.py View on Github external
def apm_middleware(config):
    config.middleware = ['rele.contrib.APMMiddleware']
    register_middleware(config)
github mercadona / rele / tests / test_worker.py View on Github external
def test_stop_closes_db_connections(self, mock_db_close_all, config, worker):
        config.middleware = ["rele.contrib.DjangoDBMiddleware"]
        register_middleware(config=config)

        with pytest.raises(SystemExit):
            worker.stop()

        mock_db_close_all.assert_called_once()
github mercadona / rele / tests / test_subscription.py View on Github external
def test_old_django_connections_closed_when_middleware_is_used(
        self, mock_close_old_connections, message_wrapper, config
    ):
        config.middleware = ["rele.contrib.DjangoDBMiddleware"]
        register_middleware(config)
        callback = Callback(sub_stub)
        res = callback(message_wrapper)

        assert res == 123
        assert mock_close_old_connections.call_count == 2
github mercadona / rele / rele / config.py View on Github external
def setup(setting=None, **kwargs):
    if setting is None:
        setting = {}

    config = Config(setting)
    init_global_publisher(config)
    register_middleware(config, **kwargs)
    return config