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

@@ -2,7 +2,6 @@ from flask_login import current_user
from flask import has_request_context, request, abort
from notifications_python_client.base import BaseAPIClient
from notifications_python_client import __version__
from notifications_utils.clients.redis.redis_client import RedisClient
def _attach_current_user(data):
@@ -14,8 +13,6 @@ def _attach_current_user(data):
class NotifyAdminAPIClient(BaseAPIClient):
redis_client = RedisClient()
def __init__(self):
super().__init__("a" * 73, "b")
@@ -24,8 +21,6 @@ class NotifyAdminAPIClient(BaseAPIClient):
self.service_id = app.config['ADMIN_CLIENT_USER_NAME']
self.api_key = app.config['ADMIN_CLIENT_SECRET']
self.route_secret = app.config['ROUTE_SECRET_KEY_1']
self.redis_client.init_app(app)
self.redis_client.redis_store.decode_responses = True
def generate_headers(self, api_token):
headers = {