Store the normalised number on the notification

This commit is contained in:
Imdad Ahad
2017-05-23 14:47:55 +01:00
parent 389515ce02
commit cbc92a6173
3 changed files with 50 additions and 13 deletions

View File

@@ -165,19 +165,20 @@ def send_sms(self,
return return
try: try:
saved_notification = persist_notification(template_id=notification['template'], saved_notification = persist_notification(
template_version=notification['template_version'], template_id=notification['template'],
recipient=notification['to'], template_version=notification['template_version'],
service=service, recipient=notification['to'],
personalisation=notification.get('personalisation'), service=service,
notification_type=SMS_TYPE, personalisation=notification.get('personalisation'),
api_key_id=api_key_id, notification_type=SMS_TYPE,
key_type=key_type, api_key_id=api_key_id,
created_at=created_at, key_type=key_type,
job_id=notification.get('job', None), created_at=created_at,
job_row_number=notification.get('row_number', None), job_id=notification.get('job', None),
notification_id=notification_id job_row_number=notification.get('row_number', None),
) notification_id=notification_id
)
provider_tasks.deliver_sms.apply_async( provider_tasks.deliver_sms.apply_async(
[str(saved_notification.id)], [str(saved_notification.id)],

View File

@@ -72,6 +72,7 @@ def persist_notification(
if notification_type == SMS_TYPE: if notification_type == SMS_TYPE:
formatted_recipient = validate_and_format_phone_number(recipient, international=True) formatted_recipient = validate_and_format_phone_number(recipient, international=True)
recipient_info = get_international_phone_info(formatted_recipient) recipient_info = get_international_phone_info(formatted_recipient)
notification.normalised_to = formatted_recipient
notification.international = recipient_info.international notification.international = recipient_info.international
notification.phone_prefix = recipient_info.country_prefix notification.phone_prefix = recipient_info.country_prefix
notification.rate_multiplier = recipient_info.billable_units notification.rate_multiplier = recipient_info.billable_units

View File

@@ -348,3 +348,38 @@ def test_persist_scheduled_notification(sample_notification):
assert len(scheduled_notification) == 1 assert len(scheduled_notification) == 1
assert scheduled_notification[0].notification_id == sample_notification.id assert scheduled_notification[0].notification_id == sample_notification.id
assert scheduled_notification[0].scheduled_for == datetime.datetime(2017, 5, 12, 13, 15) assert scheduled_notification[0].scheduled_for == datetime.datetime(2017, 5, 12, 13, 15)
@pytest.mark.parametrize('recipient, expected_recipient_normalised', [
('7900900123', '447900900123'),
('+447900 900 123', '447900900123'),
(' 07700900222', '447700900222'),
('07700900222', '447700900222'),
(' 73122345678', '73122345678'),
('360623400400', '360623400400'),
('-077-00900222-', '447700900222'),
('(360623(400400)', '360623400400')
])
def test_persist_sms_notification_stores_normalised_number(
sample_job,
sample_api_key,
mocker,
recipient,
expected_recipient_normalised
):
persist_notification(
template_id=sample_job.template.id,
template_version=sample_job.template.version,
recipient=recipient,
service=sample_job.service,
personalisation=None,
notification_type='sms',
api_key_id=sample_api_key.id,
key_type=sample_api_key.key_type,
job_id=sample_job.id,
)
persisted_notification = Notification.query.all()[0]
assert persisted_notification.to == recipient
assert persisted_notification.normalised_to == expected_recipient_normalised