mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-09 09:19:48 -04:00
Set up clients wrapper to hold all the clients
- tests FAIL if there is a provider in the DB and not in the CODE - tests PASS is there a provider in the CODE and not in the DB
This commit is contained in:
@@ -7,6 +7,7 @@ from flask_marshmallow import Marshmallow
|
|||||||
from werkzeug.local import LocalProxy
|
from werkzeug.local import LocalProxy
|
||||||
from notifications_utils import logging
|
from notifications_utils import logging
|
||||||
from app.celery.celery import NotifyCelery
|
from app.celery.celery import NotifyCelery
|
||||||
|
from app.clients import Clients
|
||||||
from app.clients.sms.mmg import MMGClient
|
from app.clients.sms.mmg import MMGClient
|
||||||
from app.clients.sms.twilio import TwilioClient
|
from app.clients.sms.twilio import TwilioClient
|
||||||
from app.clients.sms.firetext import FiretextClient
|
from app.clients.sms.firetext import FiretextClient
|
||||||
@@ -25,8 +26,7 @@ mmg_client = MMGClient()
|
|||||||
aws_ses_client = AwsSesClient()
|
aws_ses_client = AwsSesClient()
|
||||||
encryption = Encryption()
|
encryption = Encryption()
|
||||||
|
|
||||||
sms_clients = []
|
clients = Clients()
|
||||||
email_clients = []
|
|
||||||
|
|
||||||
api_user = LocalProxy(lambda: _request_ctx_stack.top.api_user)
|
api_user = LocalProxy(lambda: _request_ctx_stack.top.api_user)
|
||||||
|
|
||||||
@@ -50,6 +50,7 @@ def create_app(app_name=None):
|
|||||||
aws_ses_client.init_app(application.config['AWS_REGION'])
|
aws_ses_client.init_app(application.config['AWS_REGION'])
|
||||||
notify_celery.init_app(application)
|
notify_celery.init_app(application)
|
||||||
encryption.init_app(application)
|
encryption.init_app(application)
|
||||||
|
clients.init_app(sms_clients=[firetext_client, mmg_client], email_clients=[aws_ses_client])
|
||||||
|
|
||||||
from app.service.rest import service as service_blueprint
|
from app.service.rest import service as service_blueprint
|
||||||
from app.user.rest import user as user_blueprint
|
from app.user.rest import user as user_blueprint
|
||||||
@@ -77,9 +78,6 @@ def create_app(app_name=None):
|
|||||||
application.register_blueprint(template_statistics_blueprint)
|
application.register_blueprint(template_statistics_blueprint)
|
||||||
application.register_blueprint(events_blueprint)
|
application.register_blueprint(events_blueprint)
|
||||||
|
|
||||||
email_clients = [aws_ses_client]
|
|
||||||
sms_clients = [mmg_client, firetext_client]
|
|
||||||
|
|
||||||
return application
|
return application
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
class ClientException(Exception):
|
class ClientException(Exception):
|
||||||
'''
|
'''
|
||||||
Base Exceptions for sending notifications that fail
|
Base Exceptions for sending notifications that fail
|
||||||
@@ -16,3 +15,21 @@ class Client(object):
|
|||||||
STATISTICS_REQUESTED = 'requested'
|
STATISTICS_REQUESTED = 'requested'
|
||||||
STATISTICS_DELIVERED = 'delivered'
|
STATISTICS_DELIVERED = 'delivered'
|
||||||
STATISTICS_FAILURE = 'failure'
|
STATISTICS_FAILURE = 'failure'
|
||||||
|
|
||||||
|
|
||||||
|
class Clients(object):
|
||||||
|
sms_clients = {}
|
||||||
|
email_clients = {}
|
||||||
|
|
||||||
|
def init_app(self, sms_clients, email_clients):
|
||||||
|
for client in sms_clients:
|
||||||
|
self.sms_clients[client.name] = client
|
||||||
|
|
||||||
|
for client in email_clients:
|
||||||
|
self.email_clients[client.name] = client
|
||||||
|
|
||||||
|
def sms_client(self, name):
|
||||||
|
return self.sms_clients.get(name)
|
||||||
|
|
||||||
|
def email_client(self, name):
|
||||||
|
return self.email_clients.get(name)
|
||||||
|
|||||||
24
tests/app/dao/test_provider_details.py
Normal file
24
tests/app/dao/test_provider_details.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
from app.models import ProviderDetails
|
||||||
|
from app import clients
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_error_if_any_provider_in_database_not_in_code(notify_db, notify_db_session, notify_api):
|
||||||
|
providers = ProviderDetails.query.all()
|
||||||
|
|
||||||
|
for provider in providers:
|
||||||
|
if provider.notification_type == 'sms':
|
||||||
|
assert clients.sms_client(provider.identifier)
|
||||||
|
if provider.notification_type == 'email':
|
||||||
|
assert clients.email_client(provider.identifier)
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_not_error_if_any_provider_in_code_not_in_database(notify_db, notify_db_session, notify_api):
|
||||||
|
providers = ProviderDetails.query.all()
|
||||||
|
|
||||||
|
ProviderDetails.query.filter_by(identifier='mmg').delete()
|
||||||
|
|
||||||
|
for provider in providers:
|
||||||
|
if provider.notification_type == 'sms':
|
||||||
|
assert clients.sms_client(provider.identifier)
|
||||||
|
if provider.notification_type == 'email':
|
||||||
|
assert clients.email_client(provider.identifier)
|
||||||
Reference in New Issue
Block a user