From 732c203d3e224ca4e03b4ea575f1d2b3ceea8715 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Tue, 17 Nov 2020 12:35:18 +0000 Subject: [PATCH] rename clients to notification_provider_clients i think it's causing havoc with my attempts to mock stuff in the `app.clients` directory because it's also accessible at that path. the name's super vague and doesn't explain what it is anyway --- app/__init__.py | 6 +++--- app/clients/__init__.py | 2 +- app/delivery/send_to_providers.py | 4 ++-- tests/app/dao/test_provider_details_dao.py | 4 ++-- tests/app/delivery/test_send_to_providers.py | 7 +++++-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index e30655832..c412e4b8f 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -22,7 +22,7 @@ from werkzeug.exceptions import HTTPException as WerkzeugHTTPException from werkzeug.local import LocalProxy from app.celery.celery import NotifyCelery -from app.clients import Clients +from app.clients import NotificationProviderClients from app.clients.cbc_proxy import CBCProxyClient, CBCProxyNoopClient from app.clients.document_download import DocumentDownloadClient from app.clients.email.aws_ses import AwsSesClient @@ -65,7 +65,7 @@ cbc_proxy_client = CBCProxyNoopClient() document_download_client = DocumentDownloadClient() metrics = GDSMetrics() -clients = Clients() +notification_provider_clients = NotificationProviderClients() api_user = LocalProxy(lambda: _request_ctx_stack.top.api_user) authenticated_service = LocalProxy(lambda: _request_ctx_stack.top.authenticated_service) @@ -106,7 +106,7 @@ def create_app(application): ) # If a stub url is provided for SES, then use the stub client rather than the real SES boto client email_clients = [aws_ses_stub_client] if application.config['SES_STUB_URL'] else [aws_ses_client] - clients.init_app(sms_clients=[firetext_client, mmg_client], email_clients=email_clients) + notification_provider_clients.init_app(sms_clients=[firetext_client, mmg_client], email_clients=email_clients) notify_celery.init_app(application) encryption.init_app(application) diff --git a/app/clients/__init__.py b/app/clients/__init__.py index 74750c51a..ecf60204f 100644 --- a/app/clients/__init__.py +++ b/app/clients/__init__.py @@ -17,7 +17,7 @@ STATISTICS_DELIVERED = 'delivered' STATISTICS_FAILURE = 'failure' -class Clients(object): +class NotificationProviderClients(object): sms_clients = {} email_clients = {} diff --git a/app/delivery/send_to_providers.py b/app/delivery/send_to_providers.py index 3f92e54d1..902126d6d 100644 --- a/app/delivery/send_to_providers.py +++ b/app/delivery/send_to_providers.py @@ -9,7 +9,7 @@ from notifications_utils.recipients import ( ) from notifications_utils.template import HTMLEmailTemplate, PlainTextEmailTemplate, SMSMessageTemplate -from app import clients, statsd_client, create_uuid +from app import notification_provider_clients, statsd_client, create_uuid from app.dao.notifications_dao import ( dao_update_notification ) @@ -144,7 +144,7 @@ def provider_to_use(notification_type, international=False): chosen_provider = random.choices(active_providers, weights=[p.priority for p in active_providers])[0] - return clients.get_client_by_name_and_type(chosen_provider.identifier, notification_type) + return notification_provider_clients.get_client_by_name_and_type(chosen_provider.identifier, notification_type) def get_logo_url(base_url, logo_file): diff --git a/tests/app/dao/test_provider_details_dao.py b/tests/app/dao/test_provider_details_dao.py index 2d42975e2..a25deaa6a 100644 --- a/tests/app/dao/test_provider_details_dao.py +++ b/tests/app/dao/test_provider_details_dao.py @@ -5,7 +5,7 @@ from freezegun import freeze_time from sqlalchemy.sql import desc from app.models import ProviderDetails, ProviderDetailsHistory -from app import clients +from app import notification_provider_clients from app.dao.provider_details_dao import ( get_alternative_sms_provider, get_provider_details_by_identifier, @@ -76,7 +76,7 @@ def test_can_get_email_providers(notify_db_session): def test_should_not_error_if_any_provider_in_code_not_in_database(restore_provider_details): ProviderDetails.query.filter_by(identifier='mmg').delete() - assert clients.get_sms_client('mmg') + assert notification_provider_clients.get_sms_client('mmg') @freeze_time('2000-01-01T00:00:00') diff --git a/tests/app/delivery/test_send_to_providers.py b/tests/app/delivery/test_send_to_providers.py index 367f86059..6cf1013a4 100644 --- a/tests/app/delivery/test_send_to_providers.py +++ b/tests/app/delivery/test_send_to_providers.py @@ -9,7 +9,7 @@ from notifications_utils.recipients import validate_and_format_phone_number from requests import HTTPError import app -from app import clients, mmg_client, firetext_client +from app import notification_provider_clients, mmg_client, firetext_client from app.dao import notifications_dao from app.dao.provider_details_dao import get_provider_details_by_identifier from app.delivery import send_to_providers @@ -535,7 +535,10 @@ def test_update_notification_to_sending_does_not_update_status_from_a_final_stat ): template = create_template(sample_service) notification = create_notification(template=template, status=starting_status) - send_to_providers.update_notification_to_sending(notification, clients.get_client_by_name_and_type("mmg", "sms")) + send_to_providers.update_notification_to_sending( + notification, + notification_provider_clients.get_client_by_name_and_type("mmg", "sms") + ) assert notification.status == expected_status