mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 14:08:47 -04:00
Merge branch 'master' of https://github.com/alphagov/notifications-api
This commit is contained in:
@@ -117,9 +117,13 @@ def register_blueprint(application):
|
|||||||
ses_callback_blueprint.before_request(requires_no_auth)
|
ses_callback_blueprint.before_request(requires_no_auth)
|
||||||
application.register_blueprint(ses_callback_blueprint)
|
application.register_blueprint(ses_callback_blueprint)
|
||||||
|
|
||||||
sms_callback_blueprint.before_request(restrict_ip_sms)
|
# delivery receipts
|
||||||
|
# TODO: make sure research mode can still trigger sms callbacks, then re-enable this
|
||||||
|
# sms_callback_blueprint.before_request(restrict_ip_sms)
|
||||||
|
sms_callback_blueprint.before_request(requires_no_auth)
|
||||||
application.register_blueprint(sms_callback_blueprint)
|
application.register_blueprint(sms_callback_blueprint)
|
||||||
|
|
||||||
|
# inbound sms
|
||||||
receive_notifications_blueprint.before_request(restrict_ip_sms)
|
receive_notifications_blueprint.before_request(restrict_ip_sms)
|
||||||
application.register_blueprint(receive_notifications_blueprint)
|
application.register_blueprint(receive_notifications_blueprint)
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ from app.models import (
|
|||||||
BRANDING_ORG_BANNER,
|
BRANDING_ORG_BANNER,
|
||||||
BRANDING_GOVUK,
|
BRANDING_GOVUK,
|
||||||
EMAIL_TYPE,
|
EMAIL_TYPE,
|
||||||
|
NOTIFICATION_CREATED,
|
||||||
NOTIFICATION_TECHNICAL_FAILURE,
|
NOTIFICATION_TECHNICAL_FAILURE,
|
||||||
NOTIFICATION_SENT,
|
NOTIFICATION_SENT,
|
||||||
NOTIFICATION_SENDING
|
NOTIFICATION_SENDING
|
||||||
@@ -55,7 +56,16 @@ def send_sms_to_provider(notification):
|
|||||||
if service.research_mode or notification.key_type == KEY_TYPE_TEST:
|
if service.research_mode or notification.key_type == KEY_TYPE_TEST:
|
||||||
notification.billable_units = 0
|
notification.billable_units = 0
|
||||||
update_notification(notification, provider)
|
update_notification(notification, provider)
|
||||||
send_sms_response(provider.get_name(), str(notification.id), notification.to)
|
try:
|
||||||
|
send_sms_response(provider.get_name(), str(notification.id), notification.to)
|
||||||
|
except:
|
||||||
|
# when we retry, we only do anything if the notification is in created - it's currently in sending,
|
||||||
|
# so set it back so that we actually attempt the callback again
|
||||||
|
notification.sent_at = None
|
||||||
|
notification.sent_by = None
|
||||||
|
notification.status = NOTIFICATION_CREATED
|
||||||
|
dao_update_notification(notification)
|
||||||
|
raise
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
provider.send_sms(
|
provider.send_sms(
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ inherit: manifest-api-base.yml
|
|||||||
|
|
||||||
routes:
|
routes:
|
||||||
- route: notify-api-preview.cloudapps.digital
|
- route: notify-api-preview.cloudapps.digital
|
||||||
- route: api-paas.notify.works
|
|
||||||
- route: api.notify.works
|
- route: api.notify.works
|
||||||
|
|
||||||
instances: 1
|
instances: 1
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ inherit: manifest-api-base.yml
|
|||||||
|
|
||||||
routes:
|
routes:
|
||||||
- route: notify-api-production.cloudapps.digital
|
- route: notify-api-production.cloudapps.digital
|
||||||
- route: api-paas.notifications.service.gov.uk
|
|
||||||
- route: api.notifications.service.gov.uk
|
- route: api.notifications.service.gov.uk
|
||||||
instances: 2
|
instances: 2
|
||||||
memory: 1G
|
memory: 1G
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ inherit: manifest-api-base.yml
|
|||||||
|
|
||||||
routes:
|
routes:
|
||||||
- route: notify-api-staging.cloudapps.digital
|
- route: notify-api-staging.cloudapps.digital
|
||||||
- route: api-paas.staging-notify.works
|
|
||||||
- route: api.staging-notify.works
|
- route: api.staging-notify.works
|
||||||
instances: 2
|
instances: 2
|
||||||
memory: 1G
|
memory: 1G
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from unittest.mock import ANY, call
|
|||||||
import pytest
|
import pytest
|
||||||
from notifications_utils.recipients import validate_and_format_phone_number
|
from notifications_utils.recipients import validate_and_format_phone_number
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
from requests import HTTPError
|
||||||
|
|
||||||
import app
|
import app
|
||||||
from app import mmg_client, firetext_client
|
from app import mmg_client, firetext_client
|
||||||
@@ -235,6 +236,20 @@ def test_should_call_send_sms_response_task_if_research_mode(
|
|||||||
assert not persisted_notification.personalisation
|
assert not persisted_notification.personalisation
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_leave_as_created_if_fake_callback_function_fails(sample_notification, mocker):
|
||||||
|
mocker.patch('app.delivery.send_to_providers.send_sms_response', side_effect=HTTPError)
|
||||||
|
|
||||||
|
sample_notification.key_type = KEY_TYPE_TEST
|
||||||
|
|
||||||
|
with pytest.raises(HTTPError):
|
||||||
|
send_to_providers.send_sms_to_provider(
|
||||||
|
sample_notification
|
||||||
|
)
|
||||||
|
assert sample_notification.status == 'created'
|
||||||
|
assert sample_notification.sent_at is None
|
||||||
|
assert sample_notification.sent_by is None
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('research_mode,key_type', [
|
@pytest.mark.parametrize('research_mode,key_type', [
|
||||||
(True, KEY_TYPE_NORMAL),
|
(True, KEY_TYPE_NORMAL),
|
||||||
(False, KEY_TYPE_TEST)
|
(False, KEY_TYPE_TEST)
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ def test_post_email_notification_returns_201(client, sample_email_template_with_
|
|||||||
assert response.status_code == 201
|
assert response.status_code == 201
|
||||||
resp_json = json.loads(response.get_data(as_text=True))
|
resp_json = json.loads(response.get_data(as_text=True))
|
||||||
assert validate(resp_json, post_email_response) == resp_json
|
assert validate(resp_json, post_email_response) == resp_json
|
||||||
notification = Notification.query.first()
|
notification = Notification.query.one()
|
||||||
assert resp_json['id'] == str(notification.id)
|
assert resp_json['id'] == str(notification.id)
|
||||||
assert resp_json['reference'] == reference
|
assert resp_json['reference'] == reference
|
||||||
assert notification.reference is None
|
assert notification.reference is None
|
||||||
|
|||||||
Reference in New Issue
Block a user