Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
def apm_middleware(config):
config.middleware = ['rele.contrib.APMMiddleware']
register_middleware(config)
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()
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
def setup(setting=None, **kwargs):
if setting is None:
setting = {}
config = Config(setting)
init_global_publisher(config)
register_middleware(config, **kwargs)
return config