diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index 29632e69d..6a759f261 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -26,8 +26,8 @@ from app.models import ( NOTIFICATION_TEMPORARY_FAILURE, NOTIFICATION_PERMANENT_FAILURE, KEY_TYPE_NORMAL, KEY_TYPE_TEST, - LETTER_TYPE -) + LETTER_TYPE, + NOTIFICATION_SENT) from app.dao.dao_utils import transactional from app.statsd_decorators import statsd diff --git a/app/delivery/send_to_providers.py b/app/delivery/send_to_providers.py index 6634daa32..4eb2f61e9 100644 --- a/app/delivery/send_to_providers.py +++ b/app/delivery/send_to_providers.py @@ -15,7 +15,8 @@ from app.dao.provider_details_dao import ( ) from app.celery.research_mode_tasks import send_sms_response, send_email_response from app.dao.templates_dao import dao_get_template_by_id -from app.models import SMS_TYPE, KEY_TYPE_TEST, BRANDING_ORG, EMAIL_TYPE, NOTIFICATION_TECHNICAL_FAILURE +from app.models import SMS_TYPE, KEY_TYPE_TEST, BRANDING_ORG, EMAIL_TYPE, NOTIFICATION_TECHNICAL_FAILURE, \ + NOTIFICATION_SENT, NOTIFICATION_SENDING def send_sms_to_provider(notification): @@ -44,7 +45,7 @@ def send_sms_to_provider(notification): else: try: provider.send_sms( - to=validate_and_format_phone_number(notification.to), + to=validate_and_format_phone_number(notification.to, internationl=notification.international), content=str(template), reference=str(notification.id), sender=service.sms_sender @@ -54,7 +55,7 @@ def send_sms_to_provider(notification): raise e else: notification.billable_units = template.fragment_count - update_notification(notification, provider) + update_notification(notification, provider, notification.international) current_app.logger.info( "SMS {} sent to provider {} at {}".format(notification.id, provider.get_name(), notification.sent_at) @@ -113,10 +114,13 @@ def send_email_to_provider(notification): statsd_client.timing("email.total-time", delta_milliseconds) -def update_notification(notification, provider): +def update_notification(notification, provider, international=False): notification.sent_at = datetime.utcnow() notification.sent_by = provider.get_name() - notification.status = 'sending' + if international: + notification.status = NOTIFICATION_SENT + else: + notification.status = NOTIFICATION_SENDING dao_update_notification(notification) diff --git a/tests/app/dao/test_notification_dao.py b/tests/app/dao/test_notification_dao.py index 99d1200ec..e43f5f5de 100644 --- a/tests/app/dao/test_notification_dao.py +++ b/tests/app/dao/test_notification_dao.py @@ -352,6 +352,14 @@ def test_should_update_status_by_id_if_created(notify_db, notify_db_session): assert updated.status == 'failed' +def test_should_not_update_status_by_reference_if_in_sent_status(notify_db, notify_db_session): + assert 1 == 2 + + +def test_should_not_update_status_by_id_if_in_sent_status(notify_db, notify_db_session): + assert 1 == 2 + + def test_should_not_update_status_by_reference_if_not_sending(notify_db, notify_db_session): notification = sample_notification(notify_db, notify_db_session, status='created', reference='reference') assert Notification.query.get(notification.id).status == 'created' diff --git a/tests/app/delivery/test_send_to_providers.py b/tests/app/delivery/test_send_to_providers.py index 063d86e71..3965c2af3 100644 --- a/tests/app/delivery/test_send_to_providers.py +++ b/tests/app/delivery/test_send_to_providers.py @@ -474,6 +474,7 @@ def test_should_update_billable_units_according_to_research_mode_and_key_type(no assert sample_notification.billable_units == billable_units +<<<<<<< HEAD def test_should_send_sms_to_international_providers( restore_provider_details, sample_sms_template_with_html, @@ -530,3 +531,11 @@ def test_should_send_sms_to_international_providers( assert notification_uk.sent_by == 'firetext' assert notification_int.status == 'sending' assert notification_int.sent_by == 'mmg' + + +def test_should_send_international_sms_with_formatted_phone_number(): + assert 1 == 2 + + +def test_should_set_international_phone_number_to_sent_status(): + assert 1 == 2