From f2ee8f3eb7907cf05e94bd0a6566d03da2733e19 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Tue, 5 Apr 2016 14:39:59 +0100 Subject: [PATCH] WIP --- app/clients/sms/firetext.py | 2 ++ app/clients/sms/mmg.py | 2 -- app/notifications/rest.py | 10 ++++------ tests/app/celery/test_tasks.py | 21 +++++++++++---------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/app/clients/sms/firetext.py b/app/clients/sms/firetext.py index 8175a7e19..87e0119a6 100644 --- a/app/clients/sms/firetext.py +++ b/app/clients/sms/firetext.py @@ -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) diff --git a/app/clients/sms/mmg.py b/app/clients/sms/mmg.py index 985eddf84..0f6a9f031 100644 --- a/app/clients/sms/mmg.py +++ b/app/clients/sms/mmg.py @@ -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'] diff --git a/app/notifications/rest.py b/app/notifications/rest.py index ddccbae0b..b3bbd3205 100644 --- a/app/notifications/rest.py +++ b/app/notifications/rest.py @@ -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 diff --git a/tests/app/celery/test_tasks.py b/tests/app/celery/test_tasks.py index 767a4cb5c..a8b6890cd 100644 --- a/tests/app/celery/test_tasks.py +++ b/tests/app/celery/test_tasks.py @@ -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):