From 69c299dd6c7a233c02d674e721643f2bc3fb21fa Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Fri, 2 Jun 2017 13:34:02 +0100 Subject: [PATCH] ensure international numbers are handled correctly the international flag semantically means 'Should we throw an error if an international number is passed in?' (and the answer is no. We should not.) --- app/inbound_sms/rest.py | 2 +- app/notifications/receive_notifications.py | 4 ++-- tests/app/inbound_sms/test_rest.py | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/inbound_sms/rest.py b/app/inbound_sms/rest.py index 8ebcff298..d4072dea3 100644 --- a/app/inbound_sms/rest.py +++ b/app/inbound_sms/rest.py @@ -24,7 +24,7 @@ def get_inbound_sms_for_service(service_id): if user_number: # we use this to normalise to an international phone number - user_number = validate_and_format_phone_number(user_number) + user_number = validate_and_format_phone_number(user_number, international=True) results = dao_get_inbound_sms_for_service(service_id, limit, user_number) diff --git a/app/notifications/receive_notifications.py b/app/notifications/receive_notifications.py index d053a4198..0ed644904 100644 --- a/app/notifications/receive_notifications.py +++ b/app/notifications/receive_notifications.py @@ -64,8 +64,8 @@ def format_mmg_datetime(date): def create_inbound_mmg_sms_object(service, json): - message = format_message(json['Message']) - user_number = validate_and_format_phone_number(json['MSISDN']) + message = format_mmg_message(json['Message']) + user_number = validate_and_format_phone_number(json['MSISDN'], international=True) provider_date = json.get('DateRecieved') if provider_date: diff --git a/tests/app/inbound_sms/test_rest.py b/tests/app/inbound_sms/test_rest.py index 25f5d7cff..da10ecb6b 100644 --- a/tests/app/inbound_sms/test_rest.py +++ b/tests/app/inbound_sms/test_rest.py @@ -67,6 +67,21 @@ def test_get_inbound_sms_filters_user_number(admin_request, sample_service, user assert sms['data'][0]['user_number'] == str(one.user_number) +def test_get_inbound_sms_filters_international_user_number(admin_request, sample_service): + # user_number in the db is international and normalised + one = create_inbound_sms(sample_service, user_number='12025550104') + two = create_inbound_sms(sample_service) + + sms = admin_request.get( + 'inbound_sms.get_inbound_sms_for_service', + endpoint_kwargs={'service_id': sample_service.id, 'user_number': '+1 (202) 555-0104'} + ) + + assert len(sms['data']) == 1 + assert sms['data'][0]['id'] == str(one.id) + assert sms['data'][0]['user_number'] == str(one.user_number) + + def test_get_inbound_sms_summary(admin_request, sample_service): other_service = create_service(service_name='other_service') with freeze_time('2017-01-01'):