mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-20 22:39:43 -04:00
WIP
This commit is contained in:
@@ -9,6 +9,8 @@ from requests import request, RequestException, HTTPError
|
|||||||
from app.clients import ClientResponse, STATISTICS_DELIVERED, STATISTICS_FAILURE
|
from app.clients import ClientResponse, STATISTICS_DELIVERED, STATISTICS_FAILURE
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class FiretextResponses(ClientResponse):
|
class FiretextResponses(ClientResponse):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
ClientResponse.__init__(self)
|
ClientResponse.__init__(self)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from flask import current_app
|
from flask import current_app
|
||||||
from monotonic import monotonic
|
from monotonic import monotonic
|
||||||
from requests import (request, RequestException, HTTPError)
|
from requests import (request, RequestException, HTTPError)
|
||||||
|
|
||||||
from app.clients import (ClientResponse, STATISTICS_DELIVERED, STATISTICS_FAILURE)
|
from app.clients import (ClientResponse, STATISTICS_DELIVERED, STATISTICS_FAILURE)
|
||||||
from app.clients.sms import (SmsClient, SmsClientException)
|
from app.clients.sms import (SmsClient, SmsClientException)
|
||||||
|
|
||||||
@@ -31,7 +30,6 @@ class FiretextResponses(ClientResponse):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MMGClientException(SmsClientException):
|
class MMGClientException(SmsClientException):
|
||||||
def __init__(self, error_response):
|
def __init__(self, error_response):
|
||||||
self.code = error_response['Error']
|
self.code = error_response['Error']
|
||||||
|
|||||||
@@ -145,8 +145,6 @@ def is_not_a_notification(source):
|
|||||||
|
|
||||||
@notifications.route('/notifications/sms/mmg', methods=['POST'])
|
@notifications.route('/notifications/sms/mmg', methods=['POST'])
|
||||||
def process_mmg_response():
|
def process_mmg_response():
|
||||||
print('here')
|
|
||||||
current_app.logger.info('MMG client callback json{}'.format(request.json))
|
|
||||||
current_app.logger.info('MMG client callback form{}'.format(request.form))
|
current_app.logger.info('MMG client callback form{}'.format(request.form))
|
||||||
status, error1 = _get_from_response(form=request.form, field='status', client_name='MMG')
|
status, error1 = _get_from_response(form=request.form, field='status', client_name='MMG')
|
||||||
reference, error2 = _get_from_response(form=request.form, field='reference', client_name='MMG')
|
reference, error2 = _get_from_response(form=request.form, field='reference', client_name='MMG')
|
||||||
@@ -154,7 +152,6 @@ def process_mmg_response():
|
|||||||
errors.remove(None)
|
errors.remove(None)
|
||||||
if len(errors) > 0:
|
if len(errors) > 0:
|
||||||
return jsonify(result='error', message=errors), 400
|
return jsonify(result='error', message=errors), 400
|
||||||
|
|
||||||
if reference == 'send-sms-code':
|
if reference == 'send-sms-code':
|
||||||
return jsonify(result="success", message="MMG callback succeeded: send-sms-code"), 200
|
return jsonify(result="success", message="MMG callback succeeded: send-sms-code"), 200
|
||||||
|
|
||||||
@@ -163,10 +160,10 @@ def _get_from_response(form, field, client_name):
|
|||||||
error = None
|
error = None
|
||||||
form_field = None
|
form_field = None
|
||||||
if len(form.get(field, '')) <= 0:
|
if len(form.get(field, '')) <= 0:
|
||||||
print(
|
current_app.logger.info(
|
||||||
"{} callback failed: {} missing".format(client_name, field)
|
"{} callback failed: {} missing".format(client_name, field)
|
||||||
)
|
)
|
||||||
error="{} callback failed: {} missing".format(client_name, field)
|
error = "{} callback failed: {} missing".format(client_name, field)
|
||||||
else:
|
else:
|
||||||
form_field = form[field]
|
form_field = form[field]
|
||||||
return form_field, error
|
return form_field, error
|
||||||
@@ -177,7 +174,8 @@ def process_firetext_response():
|
|||||||
status, error1 = _get_from_response(form=request.form, field='status', client_name='Firetext')
|
status, error1 = _get_from_response(form=request.form, field='status', client_name='Firetext')
|
||||||
reference, error2 = _get_from_response(form=request.form, field='reference', client_name='Firetext')
|
reference, error2 = _get_from_response(form=request.form, field='reference', client_name='Firetext')
|
||||||
errors = [error1, error2]
|
errors = [error1, error2]
|
||||||
errors = errors.filter(None)
|
errors = errors.remove(None)
|
||||||
|
|
||||||
if len(errors) > 0:
|
if len(errors) > 0:
|
||||||
return jsonify(result='error', message=errors), 400
|
return jsonify(result='error', message=errors), 400
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,10 @@ from app.celery.tasks import (
|
|||||||
delete_failed_notifications,
|
delete_failed_notifications,
|
||||||
delete_successful_notifications
|
delete_successful_notifications
|
||||||
)
|
)
|
||||||
from app import (firetext_client, aws_ses_client, encryption, DATETIME_FORMAT)
|
from app import (firetext_client, aws_ses_client, encryption, DATETIME_FORMAT, mmg_client)
|
||||||
from app.clients.email.aws_ses import AwsSesClientException
|
from app.clients.email.aws_ses import AwsSesClientException
|
||||||
from app.clients.sms.firetext import FiretextClientException
|
from app.clients.sms.firetext import FiretextClientException
|
||||||
|
from app.clients.sms.mmg import MMGClientException
|
||||||
from app.dao import notifications_dao, jobs_dao
|
from app.dao import notifications_dao, jobs_dao
|
||||||
from sqlalchemy.exc import SQLAlchemyError
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
from sqlalchemy.orm.exc import NoResultFound
|
from sqlalchemy.orm.exc import NoResultFound
|
||||||
@@ -654,23 +655,23 @@ def test_should_send_sms_code(mocker):
|
|||||||
|
|
||||||
encrypted_notification = encryption.encrypt(notification)
|
encrypted_notification = encryption.encrypt(notification)
|
||||||
|
|
||||||
mocker.patch('app.firetext_client.send_sms')
|
mocker.patch('app.mmg_client.send_sms')
|
||||||
send_sms_code(encrypted_notification)
|
send_sms_code(encrypted_notification)
|
||||||
firetext_client.send_sms.assert_called_once_with(format_phone_number(validate_phone_number(notification['to'])),
|
mmg_client.send_sms.assert_called_once_with(format_phone_number(validate_phone_number(notification['to'])),
|
||||||
notification['secret_code'],
|
notification['secret_code'],
|
||||||
'send-sms-code')
|
'send-sms-code')
|
||||||
|
|
||||||
|
|
||||||
def test_should_throw_firetext_client_exception(mocker):
|
def test_should_throw_mmg_client_exception(mocker):
|
||||||
notification = {'to': '+447234123123',
|
notification = {'to': '+447234123123',
|
||||||
'secret_code': '12345'}
|
'secret_code': '12345'}
|
||||||
|
|
||||||
encrypted_notification = encryption.encrypt(notification)
|
encrypted_notification = encryption.encrypt(notification)
|
||||||
mocker.patch('app.firetext_client.send_sms', side_effect=FiretextClientException(firetext_error()))
|
mocker.patch('app.mmg_client.send_sms', side_effect=MMGClientException(firetext_error()))
|
||||||
send_sms_code(encrypted_notification)
|
send_sms_code(encrypted_notification)
|
||||||
firetext_client.send_sms.assert_called_once_with(format_phone_number(validate_phone_number(notification['to'])),
|
mmg_client.send_sms.assert_called_once_with(format_phone_number(validate_phone_number(notification['to'])),
|
||||||
notification['secret_code'],
|
notification['secret_code'],
|
||||||
'send-sms-code')
|
'send-sms-code')
|
||||||
|
|
||||||
|
|
||||||
def test_should_send_email_code(mocker):
|
def test_should_send_email_code(mocker):
|
||||||
|
|||||||
Reference in New Issue
Block a user