Save reply_to_text for one off notiications and csv notificaitons.

This commit is contained in:
Rebecca Law
2017-11-25 11:31:36 +00:00
parent d779751bae
commit 049daa0cb8
7 changed files with 140 additions and 43 deletions

View File

@@ -2348,16 +2348,18 @@ def test_fetch_service_inbound_api(client, sample_service):
assert json.loads(response.get_data(as_text=True))["data"] == service_inbound_api.serialize()
def test_send_one_off_notification(admin_request, sample_template, mocker):
def test_send_one_off_notification(admin_request, mocker):
service = create_service()
template = create_template(service=service)
mocker.patch('app.service.send_notification.send_notification_to_queue')
response = admin_request.post(
'service.create_one_off_notification',
service_id=sample_template.service_id,
service_id=service.id,
_data={
'template_id': str(sample_template.id),
'template_id': str(template.id),
'to': '07700900001',
'created_by': str(sample_template.service.created_by_id)
'created_by': str(service.created_by_id)
},
_expected_status=201
)

View File

@@ -17,7 +17,13 @@ from app.models import (
NotificationSmsSender
)
from tests.app.db import create_user, create_reply_to_email, create_service_sms_sender
from tests.app.db import (
create_user,
create_reply_to_email,
create_service_sms_sender,
create_service,
create_template
)
@pytest.fixture
@@ -31,11 +37,14 @@ def celery_mock(mocker):
return mocker.patch('app.service.send_notification.send_notification_to_queue')
def test_send_one_off_notification_calls_celery_correctly(persist_mock, celery_mock, sample_template):
service = sample_template.service
def test_send_one_off_notification_calls_celery_correctly(persist_mock, celery_mock, notify_db_session):
service = create_service()
template = create_template(service=service)
service = template.service
post_data = {
'template_id': str(sample_template.id),
'template_id': str(template.id),
'to': '07700 900 001',
'created_by': str(service.created_by_id)
}
@@ -56,10 +65,10 @@ def test_send_one_off_notification_calls_celery_correctly(persist_mock, celery_m
def test_send_one_off_notification_calls_persist_correctly(
persist_mock,
celery_mock,
sample_template_with_placeholders
notify_db_session
):
template = sample_template_with_placeholders
service = template.service
service = create_service()
template = create_template(service=service, content="Hello (( Name))\nYour thing is due soon")
post_data = {
'template_id': str(template.id),
@@ -79,16 +88,17 @@ def test_send_one_off_notification_calls_persist_correctly(
notification_type=SMS_TYPE,
api_key_id=None,
key_type=KEY_TYPE_NORMAL,
created_by_id=str(service.created_by_id)
created_by_id=str(service.created_by_id),
reply_to_text='testing'
)
def test_send_one_off_notification_honors_research_mode(persist_mock, celery_mock, sample_template):
service = sample_template.service
service.research_mode = True
def test_send_one_off_notification_honors_research_mode(notify_db_session, persist_mock, celery_mock):
service = create_service(research_mode=True)
template = create_template(service=service)
post_data = {
'template_id': str(sample_template.id),
'template_id': str(template.id),
'to': '07700 900 001',
'created_by': str(service.created_by_id)
}
@@ -98,12 +108,13 @@ def test_send_one_off_notification_honors_research_mode(persist_mock, celery_moc
assert celery_mock.call_args[1]['research_mode'] is True
def test_send_one_off_notification_honors_priority(persist_mock, celery_mock, sample_template):
service = sample_template.service
sample_template.process_type = PRIORITY
def test_send_one_off_notification_honors_priority(notify_db_session, persist_mock, celery_mock):
service = create_service()
template = create_template(service=service)
template.process_type = PRIORITY
post_data = {
'template_id': str(sample_template.id),
'template_id': str(template.id),
'to': '07700 900 001',
'created_by': str(service.created_by_id)
}
@@ -113,11 +124,12 @@ def test_send_one_off_notification_honors_priority(persist_mock, celery_mock, sa
assert celery_mock.call_args[1]['queue'] == QueueNames.PRIORITY
def test_send_one_off_notification_raises_if_invalid_recipient(sample_template):
service = sample_template.service
def test_send_one_off_notification_raises_if_invalid_recipient(notify_db_session):
service = create_service()
template = create_template(service=service)
post_data = {
'template_id': str(sample_template.id),
'template_id': str(template.id),
'to': 'not a phone number',
'created_by': str(service.created_by_id)
}
@@ -126,12 +138,12 @@ def test_send_one_off_notification_raises_if_invalid_recipient(sample_template):
send_one_off_notification(service.id, post_data)
def test_send_one_off_notification_raises_if_cant_send_to_recipient(sample_template):
service = sample_template.service
service.restricted = True
def test_send_one_off_notification_raises_if_cant_send_to_recipient(notify_db_session):
service = create_service(restricted=True)
template = create_template(service=service)
post_data = {
'template_id': str(sample_template.id),
'template_id': str(template.id),
'to': '07700 900 001',
'created_by': str(service.created_by_id)
}
@@ -142,12 +154,12 @@ def test_send_one_off_notification_raises_if_cant_send_to_recipient(sample_templ
assert 'service is in trial mode' in e.value.message
def test_send_one_off_notification_raises_if_over_limit(sample_template):
service = sample_template.service
service.message_limit = 0
def test_send_one_off_notification_raises_if_over_limit(notify_db_session):
service = create_service(message_limit=0)
template = create_template(service=service)
post_data = {
'template_id': str(sample_template.id),
'template_id': str(template.id),
'to': '07700 900 001',
'created_by': str(service.created_by_id)
}
@@ -156,9 +168,9 @@ def test_send_one_off_notification_raises_if_over_limit(sample_template):
send_one_off_notification(service.id, post_data)
def test_send_one_off_notification_raises_if_message_too_long(persist_mock, sample_template_with_placeholders):
template = sample_template_with_placeholders
service = template.service
def test_send_one_off_notification_raises_if_message_too_long(persist_mock, notify_db_session):
service = create_service()
template = create_template(service=service, content="Hello (( Name))\nYour thing is due soon")
post_data = {
'template_id': str(template.id),