mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-05 00:30:04 -04:00
Now that we allow multiple SMS senders for a service, update the sender for SMS to be the default SMS sender, regardless if it is inbound number or not
This commit is contained in:
@@ -12,6 +12,7 @@ import app
|
||||
from app import mmg_client, firetext_client
|
||||
from app.dao import (provider_details_dao, notifications_dao)
|
||||
from app.dao.provider_details_dao import dao_switch_sms_provider_to_provider_with_identifier
|
||||
from app.dao.service_sms_sender_dao import dao_add_sms_sender_for_service
|
||||
from app.delivery import send_to_providers
|
||||
from app.models import (
|
||||
Notification,
|
||||
@@ -31,8 +32,8 @@ from tests.app.db import (
|
||||
create_notification,
|
||||
create_inbound_number,
|
||||
create_reply_to_email,
|
||||
create_reply_to_email_for_notification
|
||||
)
|
||||
create_reply_to_email_for_notification,
|
||||
create_service_sms_sender)
|
||||
|
||||
|
||||
def test_should_return_highest_priority_active_provider(restore_provider_details):
|
||||
@@ -699,14 +700,18 @@ def test_should_handle_sms_sender_and_prefix_message(
|
||||
)
|
||||
|
||||
|
||||
def test_should_use_inbound_number_as_sender_if_set(
|
||||
sample_service,
|
||||
mocker
|
||||
def test_should_use_inbound_number_as_sender_if_default_sms_sender(
|
||||
notify_db_session,
|
||||
mocker
|
||||
):
|
||||
sample_service.sms_sender = 'test sender'
|
||||
template = create_template(sample_service, content='bar')
|
||||
service = create_service(sms_sender='test sender')
|
||||
inbound_number = create_inbound_number('1')
|
||||
dao_add_sms_sender_for_service(service_id=service.id,
|
||||
sms_sender=inbound_number.number,
|
||||
is_default=True,
|
||||
inbound_number_id=inbound_number.id)
|
||||
template = create_template(service, content='bar')
|
||||
notification = create_notification(template)
|
||||
inbound_number = create_inbound_number('1', service_id=sample_service.id)
|
||||
|
||||
mocker.patch('app.mmg_client.send_sms')
|
||||
mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
@@ -721,6 +726,32 @@ def test_should_use_inbound_number_as_sender_if_set(
|
||||
)
|
||||
|
||||
|
||||
def test_should_use_default_sms_sender(
|
||||
notify_db_session,
|
||||
mocker
|
||||
):
|
||||
service = create_service(sms_sender='test sender')
|
||||
inbound_number = create_inbound_number('1')
|
||||
dao_add_sms_sender_for_service(service_id=service.id,
|
||||
sms_sender=inbound_number.number,
|
||||
is_default=False,
|
||||
inbound_number_id=inbound_number.id)
|
||||
template = create_template(service, content='bar')
|
||||
notification = create_notification(template)
|
||||
|
||||
mocker.patch('app.mmg_client.send_sms')
|
||||
mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
send_to_providers.send_sms_to_provider(notification)
|
||||
|
||||
mmg_client.send_sms.assert_called_once_with(
|
||||
to=ANY,
|
||||
content=ANY,
|
||||
reference=str(notification.id),
|
||||
sender='test sender'
|
||||
)
|
||||
|
||||
|
||||
def test_send_email_to_provider_get_linked_email_reply_to_default_is_false(
|
||||
sample_service,
|
||||
sample_email_template,
|
||||
|
||||
@@ -252,17 +252,11 @@ def test_inbound_number_returns_inbound_number(client, notify_db_session):
|
||||
assert service.get_inbound_number() == inbound_number.number
|
||||
|
||||
|
||||
def test_inbound_number_returns_sms_sender(client, notify_db_session):
|
||||
service = create_service(sms_sender='testing')
|
||||
|
||||
assert service.get_inbound_number() == service.sms_sender
|
||||
|
||||
|
||||
def test_inbound_number_returns_from_number_config(client, notify_db_session):
|
||||
def test_inbound_number_returns_none_when_no_inbound_number(client, notify_db_session):
|
||||
with set_config(client.application, 'FROM_NUMBER', 'test'):
|
||||
service = create_service(sms_sender=None)
|
||||
|
||||
assert service.get_inbound_number() == 'test'
|
||||
assert not service.get_inbound_number()
|
||||
|
||||
|
||||
def test_service_get_default_reply_to_email_address(sample_service):
|
||||
|
||||
@@ -8,7 +8,6 @@ from app.models import (
|
||||
ScheduledNotification,
|
||||
SCHEDULE_NOTIFICATIONS,
|
||||
EMAIL_TYPE,
|
||||
INTERNATIONAL_SMS_TYPE,
|
||||
SMS_TYPE
|
||||
)
|
||||
from flask import json, current_app
|
||||
@@ -25,7 +24,11 @@ from tests.app.conftest import (
|
||||
sample_template_without_sms_permission
|
||||
)
|
||||
|
||||
from tests.app.db import create_inbound_number, create_service, create_template, create_reply_to_email
|
||||
from tests.app.db import (
|
||||
create_service,
|
||||
create_template,
|
||||
create_reply_to_email
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("reference", [None, "reference_from_client"])
|
||||
@@ -64,15 +67,16 @@ def test_post_sms_notification_returns_201(client, sample_template_with_placehol
|
||||
assert mocked.called
|
||||
|
||||
|
||||
def test_post_sms_notification_uses_inbound_number_as_sender(client, sample_template_with_placeholders, mocker):
|
||||
def test_post_sms_notification_uses_inbound_number_as_sender(client, notify_db_session, mocker):
|
||||
service = create_service(sms_sender='1', do_create_inbound_number=True)
|
||||
template = create_template(service=service, content="Hello (( Name))\nYour thing is due soon")
|
||||
mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
|
||||
data = {
|
||||
'phone_number': '+447700900855',
|
||||
'template_id': str(sample_template_with_placeholders.id),
|
||||
'template_id': str(template.id),
|
||||
'personalisation': {' Name': 'Jo'}
|
||||
}
|
||||
inbound_number = create_inbound_number('1', service_id=sample_template_with_placeholders.service_id)
|
||||
auth_header = create_authorization_header(service_id=sample_template_with_placeholders.service_id)
|
||||
auth_header = create_authorization_header(service_id=service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/sms',
|
||||
@@ -85,7 +89,8 @@ def test_post_sms_notification_uses_inbound_number_as_sender(client, sample_temp
|
||||
assert len(notifications) == 1
|
||||
notification_id = notifications[0].id
|
||||
assert resp_json['id'] == str(notification_id)
|
||||
assert resp_json['content']['from_number'] == inbound_number.number
|
||||
assert resp_json['content']['from_number'] == '1'
|
||||
mocked.assert_called_once_with([str(notification_id)], queue='send-sms-tasks')
|
||||
|
||||
|
||||
@pytest.mark.parametrize("notification_type, key_send_to, send_to",
|
||||
|
||||
Reference in New Issue
Block a user