def get_inbox_partials(service_id): if 'inbound_sms' not in current_service['permissions']: abort(403) messages_to_show = list() inbound_messages = service_api_client.get_inbound_sms(service_id) for message in inbound_messages: if format_phone_number_human_readable(message['user_number']) not in { format_phone_number_human_readable(message['user_number']) for message in messages_to_show }: messages_to_show.append(message) if not inbound_messages: inbound_number = inbound_number_client.get_inbound_sms_number_for_service( service_id)['data']['number'] else: inbound_number = None return { 'messages': render_template( 'views/dashboard/_inbox_messages.html', messages=messages_to_show, count_of_messages=len(inbound_messages), count_of_users=len(messages_to_show), inbound_number=inbound_number, ) }
def get_user_number(service_id, notification_id): try: user_number = service_api_client.get_inbound_sms_by_id(service_id, notification_id)['user_number'] except HTTPError as e: if e.status_code != 404: raise user_number = notification_api_client.get_notification(service_id, notification_id)['to'] return format_phone_number_human_readable(user_number)
def get_user_number(service_id, notification_id): try: number_e164 = service_api_client.get_inbound_sms_by_id( service_id, notification_id)['user_number'] except HTTPError: notification = notification_api_client.get_notification( service_id, notification_id) number_e164 = notification['normalised_to'] # For old records normalised_to may be empty or it may be stored in the # old format (without storing the leading plus sign). If this is the # case, use the to field instead and create the E.164 format on the fly. if not number_e164 or not number_e164.startswith('+'): try: number_e164 = validate_and_format_phone_number_and_allow_international( notification['to']) except Exception: return notification['to'] number = e164_to_phone_number(number_e164) return format_phone_number_human_readable(number)
def test_format_phone_number_human_readable_doenst_throw(): assert format_phone_number_human_readable('ALPHANUM3R1C') == 'ALPHANUM3R1C'
def test_format_uk_and_international_phone_numbers(phone_number, expected_formatted): assert format_phone_number_human_readable(phone_number) == expected_formatted
def test_format_local_and_international_phone_numbers(phone_number, expected_formatted): assert format_phone_number_human_readable( e164_to_phone_number(phone_number)) == expected_formatted