mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-13 06:01:42 -05:00
[WIP]
This commit is contained in:
@@ -3,14 +3,14 @@ import uuid
|
||||
import pytest
|
||||
from freezegun import freeze_time
|
||||
|
||||
from app.dao.service_sms_sender_dao import update_existing_sms_sender_with_inbound_number
|
||||
from app.dao.service_sms_sender_dao import dao_update_service_sms_sender
|
||||
from app.models import (
|
||||
NotificationEmailReplyTo,
|
||||
ScheduledNotification,
|
||||
SCHEDULE_NOTIFICATIONS,
|
||||
EMAIL_TYPE,
|
||||
SMS_TYPE,
|
||||
NotificationSmsSender, ServiceSmsSender
|
||||
NotificationSmsSender
|
||||
)
|
||||
from flask import json, current_app
|
||||
|
||||
@@ -31,7 +31,7 @@ from tests.app.db import (
|
||||
create_service,
|
||||
create_template,
|
||||
create_reply_to_email,
|
||||
create_service_sms_sender, create_notification, create_inbound_number,
|
||||
create_service_sms_sender, create_notification,
|
||||
create_service_with_inbound_number
|
||||
)
|
||||
|
||||
@@ -96,13 +96,13 @@ def test_post_sms_notification_uses_inbound_number_as_sender(client, notify_db_s
|
||||
notification_id = notifications[0].id
|
||||
assert resp_json['id'] == str(notification_id)
|
||||
assert resp_json['content']['from_number'] == '1'
|
||||
assert notifications[0].reply_to_text == '1'
|
||||
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 = {
|
||||
@@ -125,9 +125,40 @@ def test_post_sms_notification_returns_201_with_sms_sender_id(
|
||||
assert str(notification_to_sms_sender[0].notification_id) == resp_json['id']
|
||||
assert resp_json['content']['from_number'] == sms_sender.sms_sender
|
||||
assert notification_to_sms_sender[0].service_sms_sender_id == sms_sender.id
|
||||
notifications = Notification.query.all()
|
||||
assert len(notifications) == 1
|
||||
assert notifications[0].reply_to_text == sms_sender.sms_sender
|
||||
mocked.assert_called_once_with([resp_json['id']], queue='send-sms-tasks')
|
||||
|
||||
|
||||
def test_notification_reply_to_text_is_original_value_if_sender_is_changed_after_post_notification(
|
||||
client, sample_template, mocker
|
||||
):
|
||||
sms_sender = create_service_sms_sender(service=sample_template.service, sms_sender='123456', is_default=False)
|
||||
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
|
||||
data = {
|
||||
'phone_number': '+447700900855',
|
||||
'template_id': str(sample_template.id),
|
||||
'sms_sender_id': str(sms_sender.id)
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=sample_template.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/sms',
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
|
||||
dao_update_service_sms_sender(service_id=sample_template.service_id,
|
||||
service_sms_sender_id=sms_sender.id,
|
||||
is_default=sms_sender.is_default,
|
||||
sms_sender='updated')
|
||||
|
||||
assert response.status_code == 201
|
||||
notifications = Notification.query.all()
|
||||
assert len(notifications) == 1
|
||||
assert notifications[0].reply_to_text == '123456'
|
||||
|
||||
|
||||
@pytest.mark.parametrize("notification_type, key_send_to, send_to",
|
||||
[("sms", "phone_number", "+447700900855"),
|
||||
("email", "email_address", "sample@email.com")])
|
||||
@@ -637,6 +668,7 @@ def test_post_email_notification_with_valid_reply_to_id_returns_201(client, samp
|
||||
|
||||
assert email_reply_to.notification_id == notification.id
|
||||
assert email_reply_to.service_email_reply_to_id == reply_to_email.id
|
||||
assert notification.reply_to_text == reply_to_email.email_address
|
||||
|
||||
|
||||
def test_persist_sender_to_notification_mapping_for_email(notify_db_session):
|
||||
|
||||
Reference in New Issue
Block a user