mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-04 00:00:27 -04:00
Added an optional parameter in the form for POST /v2/notifications/sms and /service/<service_id>/send-notification to pass in the SMS sender id.
The send_sms_to_provider still needs to use the SMS sender being passed in to the POST. As part of https://www.pivotaltracker.com/story/show/152106587
This commit is contained in:
@@ -8,8 +8,8 @@ from app.models import (
|
||||
ScheduledNotification,
|
||||
SCHEDULE_NOTIFICATIONS,
|
||||
EMAIL_TYPE,
|
||||
SMS_TYPE
|
||||
)
|
||||
SMS_TYPE,
|
||||
NotificationSmsSender)
|
||||
from flask import json, current_app
|
||||
|
||||
from app.models import Notification
|
||||
@@ -27,8 +27,8 @@ from tests.app.conftest import (
|
||||
from tests.app.db import (
|
||||
create_service,
|
||||
create_template,
|
||||
create_reply_to_email
|
||||
)
|
||||
create_reply_to_email,
|
||||
create_service_sms_sender)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("reference", [None, "reference_from_client"])
|
||||
@@ -93,6 +93,34 @@ def test_post_sms_notification_uses_inbound_number_as_sender(client, notify_db_s
|
||||
mocked.assert_called_once_with([str(notification_id)], queue='send-sms-tasks')
|
||||
|
||||
|
||||
def test_post_sms_notification_returns_201_with_sms_sender_id(
|
||||
client, sample_template_with_placeholders, mocker
|
||||
):
|
||||
|
||||
sms_sender = create_service_sms_sender(service=sample_template_with_placeholders.service, sms_sender='123456')
|
||||
mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
|
||||
data = {
|
||||
'phone_number': '+447700900855',
|
||||
'template_id': str(sample_template_with_placeholders.id),
|
||||
'personalisation': {' Name': 'Jo'},
|
||||
'sms_sender_id': str(sms_sender.id)
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=sample_template_with_placeholders.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/sms',
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
assert response.status_code == 201
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
assert validate(resp_json, post_sms_response) == resp_json
|
||||
notification_to_sms_sender = NotificationSmsSender.query.all()
|
||||
assert len(notification_to_sms_sender) == 1
|
||||
assert str(notification_to_sms_sender[0].notification_id) == resp_json['id']
|
||||
assert notification_to_sms_sender[0].service_sms_sender_id == sms_sender.id
|
||||
mocked.assert_called_once_with([resp_json['id']], queue='send-sms-tasks')
|
||||
|
||||
|
||||
@pytest.mark.parametrize("notification_type, key_send_to, send_to",
|
||||
[("sms", "phone_number", "+447700900855"),
|
||||
("email", "email_address", "sample@email.com")])
|
||||
@@ -501,30 +529,40 @@ def test_post_notification_raises_bad_request_if_not_valid_notification_type(cli
|
||||
assert 'The requested URL was not found on the server.' in error_json['message']
|
||||
|
||||
|
||||
@pytest.mark.parametrize("reference", [None, "reference_from_client"])
|
||||
def test_post_sms_notification_with_invalid_reply_to_email_id(
|
||||
@pytest.mark.parametrize("notification_type",
|
||||
['sms', 'email'])
|
||||
def test_post_notification_with_wrong_type_of_sender(
|
||||
client,
|
||||
sample_template_with_placeholders,
|
||||
reference,
|
||||
sample_template,
|
||||
sample_email_template,
|
||||
notification_type,
|
||||
fake_uuid):
|
||||
data = {
|
||||
'phone_number': '+447700900855',
|
||||
'template_id': str(sample_template_with_placeholders.id),
|
||||
'personalisation': {' Name': 'Jo'},
|
||||
'email_reply_to_id': fake_uuid
|
||||
}
|
||||
if reference:
|
||||
data.update({"reference": reference})
|
||||
auth_header = create_authorization_header(service_id=sample_template_with_placeholders.service_id)
|
||||
if notification_type == EMAIL_TYPE:
|
||||
template = sample_email_template
|
||||
form_label = 'sms_sender_id'
|
||||
data = {
|
||||
'email_address': 'test@test.com',
|
||||
'template_id': str(sample_email_template.id),
|
||||
form_label: fake_uuid
|
||||
}
|
||||
elif notification_type == SMS_TYPE:
|
||||
template = sample_template
|
||||
form_label = 'email_reply_to_id'
|
||||
data = {
|
||||
'phone_number': '+447700900855',
|
||||
'template_id': str(template.id),
|
||||
form_label: fake_uuid
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=template.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/sms',
|
||||
path='/v2/notifications/{}'.format(notification_type),
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
assert response.status_code == 400
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
assert 'email_reply_to_id {} does not exist in database for service id {}'.\
|
||||
format(fake_uuid, sample_template_with_placeholders.service_id) in resp_json['errors'][0]['message']
|
||||
assert 'You sent a {} for a {} notification type'.\
|
||||
format(form_label, notification_type) in resp_json['errors'][0]['message']
|
||||
assert 'BadRequestError' in resp_json['errors'][0]['error']
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user