Handle case for international SMS - use correct phone validator, and also set status correctly.

This relies on some other code so this commit has placeholder failing tests to be populated when other PRs are merged.
This commit is contained in:
Martyn Inglis
2017-04-27 13:22:17 +01:00
committed by Imdad Ahad
parent 1b483f5f1e
commit 349fb3529e
4 changed files with 28 additions and 7 deletions

View File

@@ -26,8 +26,8 @@ from app.models import (
NOTIFICATION_TEMPORARY_FAILURE, NOTIFICATION_TEMPORARY_FAILURE,
NOTIFICATION_PERMANENT_FAILURE, NOTIFICATION_PERMANENT_FAILURE,
KEY_TYPE_NORMAL, KEY_TYPE_TEST, KEY_TYPE_NORMAL, KEY_TYPE_TEST,
LETTER_TYPE LETTER_TYPE,
) NOTIFICATION_SENT)
from app.dao.dao_utils import transactional from app.dao.dao_utils import transactional
from app.statsd_decorators import statsd from app.statsd_decorators import statsd

View File

@@ -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.celery.research_mode_tasks import send_sms_response, send_email_response
from app.dao.templates_dao import dao_get_template_by_id 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): def send_sms_to_provider(notification):
@@ -44,7 +45,7 @@ def send_sms_to_provider(notification):
else: else:
try: try:
provider.send_sms( 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), content=str(template),
reference=str(notification.id), reference=str(notification.id),
sender=service.sms_sender sender=service.sms_sender
@@ -54,7 +55,7 @@ def send_sms_to_provider(notification):
raise e raise e
else: else:
notification.billable_units = template.fragment_count notification.billable_units = template.fragment_count
update_notification(notification, provider) update_notification(notification, provider, notification.international)
current_app.logger.info( current_app.logger.info(
"SMS {} sent to provider {} at {}".format(notification.id, provider.get_name(), notification.sent_at) "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) 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_at = datetime.utcnow()
notification.sent_by = provider.get_name() notification.sent_by = provider.get_name()
notification.status = 'sending' if international:
notification.status = NOTIFICATION_SENT
else:
notification.status = NOTIFICATION_SENDING
dao_update_notification(notification) dao_update_notification(notification)

View File

@@ -352,6 +352,14 @@ def test_should_update_status_by_id_if_created(notify_db, notify_db_session):
assert updated.status == 'failed' 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): 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') notification = sample_notification(notify_db, notify_db_session, status='created', reference='reference')
assert Notification.query.get(notification.id).status == 'created' assert Notification.query.get(notification.id).status == 'created'

View File

@@ -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 assert sample_notification.billable_units == billable_units
<<<<<<< HEAD
def test_should_send_sms_to_international_providers( def test_should_send_sms_to_international_providers(
restore_provider_details, restore_provider_details,
sample_sms_template_with_html, 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_uk.sent_by == 'firetext'
assert notification_int.status == 'sending' assert notification_int.status == 'sending'
assert notification_int.sent_by == 'mmg' 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