Renamed some tests.

Fix some imports.
Added test for a function
This commit is contained in:
Rebecca Law
2017-11-01 11:01:20 +00:00
parent d671adc1eb
commit 830619194e
5 changed files with 86 additions and 39 deletions

View File

@@ -16,6 +16,7 @@ from app.models import Notification
from app.schema_validation import validate
from app.v2.errors import RateLimitError
from app.v2.notifications.notification_schemas import post_sms_response, post_email_response
from app.v2.notifications.post_notifications import persist_sender_to_notification_mapping
from tests import create_authorization_header
from tests.app.conftest import (
sample_template as create_sample_template,
@@ -28,7 +29,7 @@ from tests.app.db import (
create_service,
create_template,
create_reply_to_email,
create_service_sms_sender)
create_service_sms_sender, create_notification)
@pytest.mark.parametrize("reference", [None, "reference_from_client"])
@@ -561,7 +562,7 @@ def test_post_notification_with_wrong_type_of_sender(
headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 400
resp_json = json.loads(response.get_data(as_text=True))
assert 'You sent a {} for a {} notification type'.\
assert '{} is not a valid option for {} notification'.\
format(form_label, notification_type) in resp_json['errors'][0]['message']
assert 'BadRequestError' in resp_json['errors'][0]['error']
@@ -630,3 +631,37 @@ 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
def test_persist_sender_to_notification_mapping_for_email(notify_db_session):
service = create_service()
template = create_template(service=service, template_type=EMAIL_TYPE)
sender = create_reply_to_email(service=service, email_address='reply@test.com', is_default=False)
form = {
"email_address": "recipient@test.com",
"template_id": str(template.id),
'email_reply_to_id': str(sender.id)
}
notification = create_notification(template=template)
persist_sender_to_notification_mapping(form=form, notification=notification)
notification_to_email_reply_to = NotificationEmailReplyTo.query.all()
assert len(notification_to_email_reply_to) == 1
assert notification_to_email_reply_to[0].notification_id == notification.id
assert notification_to_email_reply_to[0].service_email_reply_to_id == sender.id
def test_persist_sender_to_notification_mapping_for_sms(notify_db_session):
service = create_service()
template = create_template(service=service, template_type=SMS_TYPE)
sender = create_service_sms_sender(service=service, sms_sender='12345', is_default=False)
form = {
'phone_number': '+447700900855',
'template_id': str(template.id),
'sms_sender_id': str(sender.id)
}
notification = create_notification(template=template)
persist_sender_to_notification_mapping(form=form, notification=notification)
notification_to_sms_sender = NotificationSmsSender.query.all()
assert len(notification_to_sms_sender) == 1
assert notification_to_sms_sender[0].notification_id == notification.id
assert notification_to_sms_sender[0].service_sms_sender_id == sender.id