This commit is contained in:
Rebecca Law
2016-04-05 14:39:59 +01:00
parent 3820090a19
commit f2ee8f3eb7
4 changed files with 17 additions and 18 deletions

View File

@@ -9,6 +9,8 @@ from requests import request, RequestException, HTTPError
from app.clients import ClientResponse, STATISTICS_DELIVERED, STATISTICS_FAILURE
logger = logging.getLogger(__name__)
class FiretextResponses(ClientResponse):
def __init__(self):
ClientResponse.__init__(self)

View File

@@ -1,7 +1,6 @@
from flask import current_app
from monotonic import monotonic
from requests import (request, RequestException, HTTPError)
from app.clients import (ClientResponse, STATISTICS_DELIVERED, STATISTICS_FAILURE)
from app.clients.sms import (SmsClient, SmsClientException)
@@ -31,7 +30,6 @@ class FiretextResponses(ClientResponse):
}
class MMGClientException(SmsClientException):
def __init__(self, error_response):
self.code = error_response['Error']

View File

@@ -145,8 +145,6 @@ def is_not_a_notification(source):
@notifications.route('/notifications/sms/mmg', methods=['POST'])
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))
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')
@@ -154,7 +152,6 @@ def process_mmg_response():
errors.remove(None)
if len(errors) > 0:
return jsonify(result='error', message=errors), 400
if reference == 'send-sms-code':
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
form_field = None
if len(form.get(field, '')) <= 0:
print(
current_app.logger.info(
"{} callback failed: {} missing".format(client_name, field)
)
error="{} callback failed: {} missing".format(client_name, field)
error = "{} callback failed: {} missing".format(client_name, field)
else:
form_field = form[field]
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')
reference, error2 = _get_from_response(form=request.form, field='reference', client_name='Firetext')
errors = [error1, error2]
errors = errors.filter(None)
errors = errors.remove(None)
if len(errors) > 0:
return jsonify(result='error', message=errors), 400

View File

@@ -16,9 +16,10 @@ from app.celery.tasks import (
delete_failed_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.sms.firetext import FiretextClientException
from app.clients.sms.mmg import MMGClientException
from app.dao import notifications_dao, jobs_dao
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.orm.exc import NoResultFound
@@ -654,23 +655,23 @@ def test_should_send_sms_code(mocker):
encrypted_notification = encryption.encrypt(notification)
mocker.patch('app.firetext_client.send_sms')
mocker.patch('app.mmg_client.send_sms')
send_sms_code(encrypted_notification)
firetext_client.send_sms.assert_called_once_with(format_phone_number(validate_phone_number(notification['to'])),
notification['secret_code'],
'send-sms-code')
mmg_client.send_sms.assert_called_once_with(format_phone_number(validate_phone_number(notification['to'])),
notification['secret_code'],
'send-sms-code')
def test_should_throw_firetext_client_exception(mocker):
def test_should_throw_mmg_client_exception(mocker):
notification = {'to': '+447234123123',
'secret_code': '12345'}
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)
firetext_client.send_sms.assert_called_once_with(format_phone_number(validate_phone_number(notification['to'])),
notification['secret_code'],
'send-sms-code')
mmg_client.send_sms.assert_called_once_with(format_phone_number(validate_phone_number(notification['to'])),
notification['secret_code'],
'send-sms-code')
def test_should_send_email_code(mocker):