diff --git a/app/notifications/rest.py b/app/notifications/rest.py index 4781cd10b..925910bdb 100644 --- a/app/notifications/rest.py +++ b/app/notifications/rest.py @@ -17,7 +17,8 @@ notifications = Blueprint('notifications', __name__) @notifications.route('/', methods=['GET']) def get_notifications(notification_id): - return jsonify(notify_alpha_client.fetch_notification_by_id(notification_id)), 200 + # TODO return notification id details + return jsonify({'id': notification_id}), 200 @notifications.route('/sms', methods=['POST']) @@ -27,14 +28,10 @@ def create_sms_notification(): notification, errors = sms_template_notification_schema.load(resp_json) if errors: return jsonify(result="error", message=errors), 400 - template_id = notification['template'] - # TODO: remove once beta is reading notifications from the queue - message = templates_dao.get_model_templates(template_id).content - add_notification_to_queue(api_user['client'], template_id, 'sms', notification) - # TODO: remove once beta is reading notifications from the queue - return jsonify(notify_alpha_client.send_sms( - mobile_number=notification['to'], message=message)), 200 + add_notification_to_queue(api_user['client'], notification['template'], 'sms', notification) + # TODO data to be returned + return jsonify({}), 200 @notifications.route('/email', methods=['POST']) @@ -43,14 +40,9 @@ def create_email_notification(): notification, errors = email_notification_schema.load(resp_json) if errors: return jsonify(result="error", message=errors), 400 - # At the moment we haven't hooked up - # template handling for sending email notifications. add_notification_to_queue(api_user['client'], "admin", 'email', notification) - return jsonify(notify_alpha_client.send_email( - notification['to_address'], - notification['body'], - notification['from_address'], - notification['subject'])) + # TODO data to be returned + return jsonify({}), 200 @notifications.route('/sms/service/', methods=['POST']) @@ -74,10 +66,6 @@ def create_sms_for_service(service_id): message = "Invalid template: id {} for service id: {}".format(template.id, service_id) return jsonify(result="error", message=message), 400 - # Actual client is delivery app, but this is sent on behalf of service add_notification_to_queue(service_id, template_id, 'sms', notification) - - # TODO: remove once beta is reading notifications from the queue - content = template.content - return jsonify(notify_alpha_client.send_sms( - mobile_number=notification['to'], message=content)), 200 + # TODO data to be returned + return jsonify({}), 200 diff --git a/app/user/rest.py b/app/user/rest.py index 05aef526d..02d46732d 100644 --- a/app/user/rest.py +++ b/app/user/rest.py @@ -133,15 +133,10 @@ def send_user_code(user_id): from app.dao.users_dao import create_secret_code secret_code = create_secret_code() create_user_code(user, secret_code, verify_code.get('code_type')) - # TODO this will need to fixed up when we stop using - # notify_alpha_client if verify_code.get('code_type') == 'sms': mobile = user.mobile_number if verify_code.get('to', None) is None else verify_code.get('to') notification = {'to': mobile, 'content': secret_code} add_notification_to_queue(api_user['client'], 'admin', 'sms', notification) - notify_alpha_client.send_sms( - mobile_number=mobile, - message=secret_code) elif verify_code.get('code_type') == 'email': email = user.email_address if verify_code.get('to', None) is None else verify_code.get('to') notification = { @@ -150,11 +145,6 @@ def send_user_code(user_id): 'subject': 'Verification code', 'body': secret_code} add_notification_to_queue(api_user['client'], 'admin', 'email', notification) - notify_alpha_client.send_email( - email, - secret_code, - notification['from_address'], - notification['subject']) else: abort(500) return jsonify({}), 204 diff --git a/requirements.txt b/requirements.txt index 96d3663b6..8c297ceea 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,5 +17,3 @@ boto3==1.2.3 git+https://github.com/alphagov/notifications-python-client.git@0.2.1#egg=notifications-python-client==0.2.1 git+https://github.com/alphagov/notifications-utils.git@0.0.3#egg=notifications-utils==0.0.3 - -git+https://github.com/alphagov/notify-api-client.git@0.1.6#egg=notify-api-client==0.1.6 diff --git a/tests/app/conftest.py b/tests/app/conftest.py index e1abea888..338e18022 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -155,24 +155,6 @@ def sample_admin_service_id(notify_db, notify_db_session): return admin_service.id -@pytest.fixture(scope='function') -def mock_notify_client_send_sms(mocker): - def _send(mobile_number, message): - pass - - mock_class = mocker.patch('app.notify_alpha_client.send_sms', side_effect=_send) - return mock_class - - -@pytest.fixture(scope='function') -def mock_notify_client_send_email(mocker): - def _send(email_address, message, from_address, subject): - pass - - mock_class = mocker.patch('app.notify_alpha_client.send_email', side_effect=_send) - return mock_class - - @pytest.fixture(scope='function') def mock_secret_code(mocker): def _create(): diff --git a/tests/app/notifications/test_rest.py b/tests/app/notifications/test_rest.py index fb0f2aa8f..5ce297fe2 100644 --- a/tests/app/notifications/test_rest.py +++ b/tests/app/notifications/test_rest.py @@ -14,18 +14,6 @@ def test_get_notifications( """ with notify_api.test_request_context(): with notify_api.test_client() as client: - mocker.patch( - 'app.notify_alpha_client.fetch_notification_by_id', - return_value={ - 'notifications': [ - { - 'id': 'my_id', - 'notification': 'some notify' - } - ] - } - ) - auth_header = create_authorization_header( service_id=sample_api_key.service_id, path=url_for('notifications.get_notifications', notification_id=123), @@ -35,12 +23,7 @@ def test_get_notifications( url_for('notifications.get_notifications', notification_id=123), headers=[auth_header]) - json_resp = json.loads(response.get_data(as_text=True)) assert response.status_code == 200 - assert len(json_resp['notifications']) == 1 - assert json_resp['notifications'][0]['id'] == 'my_id' - assert json_resp['notifications'][0]['notification'] == 'some notify' - notify_alpha_client.fetch_notification_by_id.assert_called_with("123") def test_get_notifications_empty_result( @@ -50,14 +33,6 @@ def test_get_notifications_empty_result( """ with notify_api.test_request_context(): with notify_api.test_client() as client: - mocker.patch( - 'app.notify_alpha_client.fetch_notification_by_id', - return_value={ - 'notifications': [ - ] - } - ) - auth_header = create_authorization_header( service_id=sample_api_key.service_id, path=url_for('notifications.get_notifications', notification_id=123), @@ -67,10 +42,7 @@ def test_get_notifications_empty_result( url_for('notifications.get_notifications', notification_id=123), headers=[auth_header]) - json_resp = json.loads(response.get_data(as_text=True)) assert response.status_code == 200 - assert len(json_resp['notifications']) == 0 - notify_alpha_client.fetch_notification_by_id.assert_called_with("123") def test_create_sms_should_reject_if_no_phone_numbers( @@ -80,10 +52,6 @@ def test_create_sms_should_reject_if_no_phone_numbers( """ with notify_api.test_request_context(): with notify_api.test_client() as client: - mocker.patch( - 'app.notify_alpha_client.send_sms', - return_value='success' - ) data = { 'template': "my message" } @@ -102,7 +70,6 @@ def test_create_sms_should_reject_if_no_phone_numbers( assert response.status_code == 400 assert json_resp['result'] == 'error' assert 'Missing data for required field.' in json_resp['message']['to'][0] - assert not notify_alpha_client.send_sms.called def test_should_reject_bad_phone_numbers( @@ -112,10 +79,6 @@ def test_should_reject_bad_phone_numbers( """ with notify_api.test_request_context(): with notify_api.test_client() as client: - mocker.patch( - 'app.notify_alpha_client.send_sms', - return_value='success' - ) data = { 'to': 'invalid', 'template': "my message" @@ -134,7 +97,6 @@ def test_should_reject_bad_phone_numbers( assert response.status_code == 400 assert json_resp['result'] == 'error' assert 'Invalid phone number, must be of format +441234123123' in json_resp['message']['to'] - assert not notify_alpha_client.send_sms.called def test_send_notification_restrict_mobile(notify_api, @@ -150,14 +112,9 @@ def test_send_notification_restrict_mobile(notify_api, """ with notify_api.test_request_context(): with notify_api.test_client() as client: - Service.query.filter_by( id=sample_template.service.id).update({'restricted': True}) invalid_mob = '+449999999999' - mocker.patch( - 'app.notify_alpha_client.send_sms', - return_value={} - ) data = { 'to': invalid_mob, 'template': sample_template.id @@ -177,7 +134,6 @@ def test_send_notification_restrict_mobile(notify_api, json_resp = json.loads(response.get_data(as_text=True)) assert response.status_code == 400 assert 'Invalid phone number for restricted service' in json_resp['message']['restricted'] - assert not notify_alpha_client.send_sms.called def test_send_notification_invalid_template_id(notify_api, @@ -196,10 +152,6 @@ def test_send_notification_invalid_template_id(notify_api, Service.query.filter_by( id=sample_template.service.id).update({'restricted': True}) invalid_mob = '+449999999999' - mocker.patch( - 'app.notify_alpha_client.send_sms', - return_value={} - ) data = { 'to': invalid_mob, 'template': 9999 @@ -219,7 +171,6 @@ def test_send_notification_invalid_template_id(notify_api, json_resp = json.loads(response.get_data(as_text=True)) assert response.status_code == 400 assert 'Template not found' in json_resp['message']['template'] - assert not notify_alpha_client.send_sms.called @moto.mock_sqs @@ -235,20 +186,6 @@ def test_should_allow_valid_message(notify_api, """ with notify_api.test_request_context(): with notify_api.test_client() as client: - mocker.patch( - 'app.notify_alpha_client.send_sms', - return_value={ - "notification": { - "createdAt": "2015-11-03T09:37:27.414363Z", - "id": 100, - "jobId": 65, - "message": "valid", - "method": "sms", - "status": "created", - "to": sample_user.mobile_number - } - } - ) data = { 'to': '+441234123123', 'template': sample_template.id @@ -263,11 +200,7 @@ def test_should_allow_valid_message(notify_api, data=json.dumps(data), headers=[('Content-Type', 'application/json'), auth_header]) - json_resp = json.loads(response.get_data(as_text=True)) assert response.status_code == 200 - assert json_resp['notification']['id'] == 100 - notify_alpha_client.send_sms.assert_called_with(mobile_number='+441234123123', - message=sample_template.content) @moto.mock_sqs @@ -284,22 +217,6 @@ def test_send_email_valid_data(notify_api, from_address = "from@notify.com" subject = "This is the subject" message = "This is the message" - mocker.patch( - 'app.notify_alpha_client.send_email', - return_value={ - "notification": { - "createdAt": "2015-11-03T09:37:27.414363Z", - "id": 100, - "jobId": 65, - "subject": subject, - "message": message, - "method": "email", - "status": "created", - "to": to_address, - "from": from_address - } - } - ) data = { 'to': to_address, 'from': from_address, @@ -316,11 +233,7 @@ def test_send_email_valid_data(notify_api, data=json.dumps(data), headers=[('Content-Type', 'application/json'), auth_header]) - json_resp = json.loads(response.get_data(as_text=True)) assert response.status_code == 200 - assert json_resp['notification']['id'] == 100 - notify_alpha_client.send_email.assert_called_with( - to_address, message, from_address, subject) @moto.mock_sqs @@ -333,20 +246,6 @@ def test_valid_message_with_service_id(notify_api, mocker): with notify_api.test_request_context(): with notify_api.test_client() as client: - mocker.patch( - 'app.notify_alpha_client.send_sms', - return_value={ - "notification": { - "createdAt": "2015-11-03T09:37:27.414363Z", - "id": 100, - "jobId": 65, - "message": "valid", - "method": "sms", - "status": "created", - "to": sample_user.mobile_number - } - } - ) job_id = uuid.uuid4() service_id = sample_template.service.id url = url_for('notifications.create_sms_for_service', service_id=service_id) @@ -365,11 +264,7 @@ def test_valid_message_with_service_id(notify_api, data=json.dumps(data), headers=[('Content-Type', 'application/json'), auth_header]) - json_resp = json.loads(response.get_data(as_text=True)) assert response.status_code == 200 - assert json_resp['notification']['id'] == 100 - notify_alpha_client.send_sms.assert_called_with(mobile_number='+441234123123', - message=sample_template.content) @moto.mock_sqs diff --git a/tests/app/user/test_rest_verify.py b/tests/app/user/test_rest_verify.py index b52a4dc8e..a58fa6a1a 100644 --- a/tests/app/user/test_rest_verify.py +++ b/tests/app/user/test_rest_verify.py @@ -253,7 +253,6 @@ def test_send_user_code_for_sms(notify_api, notify_db_session, sample_sms_code, sqs_client_conn, - mock_notify_client_send_sms, mock_secret_code): """ Tests POST endpoint '//code' successful sms @@ -271,8 +270,6 @@ def test_send_user_code_for_sms(notify_api, headers=[('Content-Type', 'application/json'), auth_header]) assert resp.status_code == 204 - mock_notify_client_send_sms.assert_called_once_with(mobile_number=sample_sms_code.user.mobile_number, - message='11111') @moto.mock_sqs @@ -281,7 +278,6 @@ def test_send_user_code_for_sms_with_optional_to_field(notify_api, notify_db_session, sample_sms_code, sqs_client_conn, - mock_notify_client_send_sms, mock_secret_code): """ Tests POST endpoint '//code' successful sms with optional to field @@ -299,8 +295,6 @@ def test_send_user_code_for_sms_with_optional_to_field(notify_api, headers=[('Content-Type', 'application/json'), auth_header]) assert resp.status_code == 204 - mock_notify_client_send_sms.assert_called_once_with(mobile_number='+441119876757', - message='11111') @moto.mock_sqs @@ -309,7 +303,6 @@ def test_send_user_code_for_email(notify_api, notify_db_session, sample_email_code, sqs_client_conn, - mock_notify_client_send_email, mock_secret_code): """ Tests POST endpoint '//code' successful email @@ -326,10 +319,6 @@ def test_send_user_code_for_email(notify_api, data=data, headers=[('Content-Type', 'application/json'), auth_header]) assert resp.status_code == 204 - mock_notify_client_send_email.assert_called_once_with(sample_email_code.user.email_address, - '11111', - 'notify@digital.cabinet-office.gov.uk', - 'Verification code') @moto.mock_sqs @@ -338,7 +327,6 @@ def test_send_user_code_for_email_uses_optional_to_field(notify_api, notify_db_session, sample_email_code, sqs_client_conn, - mock_notify_client_send_email, mock_secret_code): """ Tests POST endpoint '//code' successful email with included in body @@ -355,10 +343,6 @@ def test_send_user_code_for_email_uses_optional_to_field(notify_api, data=data, headers=[('Content-Type', 'application/json'), auth_header]) assert resp.status_code == 204 - mock_notify_client_send_email.assert_called_once_with('different@email.gov.uk', - '11111', - 'notify@digital.cabinet-office.gov.uk', - 'Verification code') def test_request_verify_code_schema_invalid_code_type(notify_api, notify_db, notify_db_session, sample_user):