move (non-api) clients (inc redis) from app/__init__.py to extensions

when clients are defined in app/__init__.py, it increases the chance of 
cyclical imports. By moving module level client singletons out to a 
separate extensions file, we stop cyclical imports, but keep the same 
code flow - the clients are still initialised in `create_app` in 
`__init__.py`.

The redis client in particular is no longer separate - previously redis 
was set up on the `NotifyAdminAPIClient` base class, but now there's one 
singleton in `app.extensions`. This was done so that we can access redis 
from outside of the existing clients.
This commit is contained in:
Leo Hemsted
2019-02-14 14:25:31 +00:00
parent 51e56614c0
commit f6367f2278
15 changed files with 64 additions and 55 deletions

View File

@@ -324,7 +324,7 @@ def test_returns_value_from_cache(
):
mock_redis_get = mocker.patch(
'app.notify_client.RedisClient.get',
'app.extensions.RedisClient.get',
return_value=cache_value,
)
mock_api_get = mocker.patch(
@@ -332,7 +332,7 @@ def test_returns_value_from_cache(
return_value={'data_from': 'api'},
)
mock_redis_set = mocker.patch(
'app.notify_client.RedisClient.set',
'app.extensions.RedisClient.set',
)
assert client_method(*extra_args) == expected_return_value
@@ -375,7 +375,7 @@ def test_deletes_service_cache(
extra_kwargs,
):
mocker.patch('app.notify_client.current_user', id='1')
mock_redis_delete = mocker.patch('app.notify_client.RedisClient.delete')
mock_redis_delete = mocker.patch('app.extensions.RedisClient.delete')
mock_request = mocker.patch('notifications_python_client.base.BaseAPIClient.request')
getattr(client, method)(*extra_args, **extra_kwargs)
@@ -423,7 +423,7 @@ def test_deletes_caches_when_modifying_templates(
expected_cache_deletes,
):
mocker.patch('app.notify_client.current_user', id='1')
mock_redis_delete = mocker.patch('app.notify_client.RedisClient.delete')
mock_redis_delete = mocker.patch('app.extensions.RedisClient.delete')
mock_request = mocker.patch('notifications_python_client.base.BaseAPIClient.request')
getattr(service_api_client, method)(*extra_args)