Initialise clients outside the app

This avoids the annoying problem where you can’t import a client unless
the app has already been initialised.
This commit is contained in:
Chris Hill-Scott
2018-10-26 15:39:32 +01:00
parent 2bf2103cce
commit 9e798506c5
21 changed files with 77 additions and 41 deletions

View File

@@ -40,7 +40,7 @@ from werkzeug.local import LocalProxy
from app import proxy_fix
from app.config import configs
from app.asset_fingerprinter import AssetFingerprinter
from app.asset_fingerprinter import asset_fingerprinter
from app.notify_client.models import Service
from app.navigation import (
CaseworkNavigation,
@@ -48,55 +48,34 @@ from app.navigation import (
MainNavigation,
OrgNavigation
)
from app.notify_client.service_api_client import ServiceAPIClient
from app.notify_client.api_key_api_client import ApiKeyApiClient
from app.notify_client.invite_api_client import InviteApiClient
from app.notify_client.job_api_client import JobApiClient
from app.notify_client.notification_api_client import NotificationApiClient
from app.notify_client.status_api_client import StatusApiClient
from app.notify_client.template_statistics_api_client import TemplateStatisticsApiClient
from app.notify_client.user_api_client import UserApiClient
from app.notify_client.events_api_client import EventsApiClient
from app.notify_client.provider_client import ProviderClient
from app.notify_client.email_branding_client import EmailBrandingClient
from app.notify_client.service_api_client import service_api_client
from app.notify_client.api_key_api_client import api_key_api_client
from app.notify_client.invite_api_client import invite_api_client
from app.notify_client.job_api_client import job_api_client
from app.notify_client.notification_api_client import notification_api_client
from app.notify_client.status_api_client import status_api_client
from app.notify_client.template_statistics_api_client import template_statistics_client
from app.notify_client.user_api_client import user_api_client
from app.notify_client.events_api_client import events_api_client
from app.notify_client.provider_client import provider_client
from app.notify_client.email_branding_client import email_branding_client
from app.notify_client.models import AnonymousUser
from app.notify_client.organisations_api_client import OrganisationsClient
from app.notify_client.org_invite_api_client import OrgInviteApiClient
from app.notify_client.letter_jobs_client import LetterJobsClient
from app.notify_client.inbound_number_client import InboundNumberClient
from app.notify_client.billing_api_client import BillingAPIClient
from app.notify_client.complaint_api_client import ComplaintApiClient
from app.notify_client.platform_stats_api_client import PlatformStatsAPIClient
from app.notify_client.organisations_api_client import organisations_client
from app.notify_client.org_invite_api_client import org_invite_api_client
from app.notify_client.letter_jobs_client import letter_jobs_client
from app.notify_client.inbound_number_client import inbound_number_client
from app.notify_client.billing_api_client import billing_api_client
from app.notify_client.complaint_api_client import complaint_api_client
from app.notify_client.platform_stats_api_client import platform_stats_api_client
from app.commands import setup_commands
from app.utils import get_cdn_domain, gmt_timezones, id_safe
login_manager = LoginManager()
csrf = CSRFProtect()
asset_fingerprinter = AssetFingerprinter()
antivirus_client = AntivirusClient()
statsd_client = StatsdClient()
zendesk_client = ZendeskClient()
service_api_client = ServiceAPIClient()
user_api_client = UserApiClient()
api_key_api_client = ApiKeyApiClient()
job_api_client = JobApiClient()
notification_api_client = NotificationApiClient()
status_api_client = StatusApiClient()
invite_api_client = InviteApiClient()
template_statistics_client = TemplateStatisticsApiClient()
events_api_client = EventsApiClient()
provider_client = ProviderClient()
email_branding_client = EmailBrandingClient()
organisations_client = OrganisationsClient()
org_invite_api_client = OrgInviteApiClient()
letter_jobs_client = LetterJobsClient()
inbound_number_client = InboundNumberClient()
billing_api_client = BillingAPIClient()
complaint_api_client = ComplaintApiClient()
platform_stats_api_client = PlatformStatsAPIClient()
# The current service attached to the request stack.
def _get_current_service():

View File

@@ -44,3 +44,6 @@ class AssetFingerprinter(object):
with codecs.open(asset_file_path, encoding='utf-8') as asset_file:
contents = asset_file.read()
return contents
asset_fingerprinter = AssetFingerprinter()

View File

@@ -30,3 +30,6 @@ class ApiKeyApiClient(NotifyAdminAPIClient):
return self.post(
url='/service/{0}/api-key/revoke/{1}'.format(service_id, key_id),
data=data)
api_key_api_client = ApiKeyApiClient()

View File

@@ -41,3 +41,6 @@ class BillingAPIClient(NotifyAdminAPIClient):
url='/service/{0}/billing/free-sms-fragment-limit'.format(service_id),
data=data
)
billing_api_client = BillingAPIClient()

View File

@@ -13,3 +13,6 @@ class ComplaintApiClient(NotifyAdminAPIClient):
def get_complaint_count(self, params_dict=None):
return self.get('/complaint/count-by-date-range', params=params_dict)
complaint_api_client = ComplaintApiClient()

View File

@@ -50,3 +50,6 @@ class EmailBrandingClient(NotifyAdminAPIClient):
"brand_type": brand_type
}
return self.post(url="/email-branding/{}".format(branding_id), data=data)
email_branding_client = EmailBrandingClient()

View File

@@ -12,3 +12,6 @@ class EventsApiClient(NotifyAdminAPIClient):
}
resp = self.post(url='/events', data=data)
return resp['data']
events_api_client = EventsApiClient()

View File

@@ -14,3 +14,6 @@ class InboundNumberClient(NotifyAdminAPIClient):
def get_inbound_sms_number_for_service(self, service_id):
return self.get('/inbound-number/service/{}'.format(service_id))
inbound_number_client = InboundNumberClient()

View File

@@ -57,3 +57,6 @@ class InviteApiClient(NotifyAdminAPIClient):
invited_user = InvitedUser(**invite)
invited_users.append(invited_user)
return invited_users
invite_api_client = InviteApiClient()

View File

@@ -125,3 +125,6 @@ class JobApiClient(NotifyAdminAPIClient):
job['data']['notifications_requested'] = stats['requested']
return job
job_api_client = JobApiClient()

View File

@@ -20,3 +20,6 @@ class LetterJobsClient(NotifyAdminAPIClient):
url='/letters/returned',
data={'references': references}
)
letter_jobs_client = LetterJobsClient()

View File

@@ -92,3 +92,6 @@ class NotificationApiClient(NotifyAdminAPIClient):
)
return self.get(url=get_url)
notification_api_client = NotificationApiClient()

View File

@@ -49,3 +49,6 @@ class OrgInviteApiClient(NotifyAdminAPIClient):
invited_user = InvitedOrgUser(**invite)
invited_users.append(invited_user)
return invited_users
org_invite_api_client = OrgInviteApiClient()

View File

@@ -52,3 +52,6 @@ class OrganisationsClient(NotifyAdminAPIClient):
url="/organisations/unique",
params={"org_id": org_id, "name": name}
)["result"]
organisations_client = OrganisationsClient()

View File

@@ -9,3 +9,6 @@ class PlatformStatsAPIClient(NotifyAdminAPIClient):
def get_aggregate_platform_stats(self, params_dict=None):
return self.get("/platform-stats", params=params_dict)
platform_stats_api_client = PlatformStatsAPIClient()

View File

@@ -27,3 +27,6 @@ class ProviderClient(NotifyAdminAPIClient):
}
data = _attach_current_user(data)
return self.post(url='/provider-details/{}'.format(provider_id), data=data)
provider_client = ProviderClient()

View File

@@ -506,3 +506,6 @@ class ServiceAPIClient(NotifyAdminAPIClient):
def get_service_data_retention_by_id(self, service_id, data_retention_id):
return self.get("service/{}/data-retention/{}".format(service_id, data_retention_id))
service_api_client = ServiceAPIClient()

View File

@@ -8,3 +8,6 @@ class StatusApiClient(NotifyAdminAPIClient):
def get_status(self, *params):
return self.get(url='/_status', *params)
status_api_client = StatusApiClient()

View File

@@ -26,3 +26,6 @@ class TemplateStatisticsApiClient(NotifyAdminAPIClient):
return self.get(
url='/service/{}/template-statistics/{}'.format(service_id, template_id)
)['data']
template_statistics_client = TemplateStatisticsApiClient()

View File

@@ -226,3 +226,6 @@ class UserApiClient(NotifyAdminAPIClient):
def user_belongs_to_service(self, user, service_id):
return service_id in self.get_service_ids_for_user(user)
user_api_client = UserApiClient()

View File

@@ -1,4 +1,4 @@
from app import ComplaintApiClient
from app.notify_client.complaint_api_client import ComplaintApiClient
def test_get_all_complaints(mocker):