- Refactor v2 post_notification to use a single method for sms and email.

- Added the `simulate` notification logic to version 2. We have 3 email addresses and phone numbers that are used
to simulate a successful post to /notifications. This was missed out of the version 2 endpoint.
- Added a test to template_dao to check for the default value of normal for new templates
- in v2 get_notifications, casted the path param to a uuid, if not uuid abort(404)
This commit is contained in:
Rebecca Law
2017-01-17 12:08:24 +00:00
parent 31de10ae6f
commit a8cdabcecd
11 changed files with 193 additions and 104 deletions

View File

@@ -10,7 +10,9 @@ from collections import namedtuple
from app.models import Template, Notification, NotificationHistory
from app.notifications import SendNotificationToQueueError
from app.notifications.process_notifications import (create_content_for_notification,
persist_notification, send_notification_to_queue)
persist_notification,
send_notification_to_queue,
simulated_recipient)
from app.v2.errors import BadRequestError
@@ -193,3 +195,24 @@ def test_send_notification_to_queue_throws_exception_deletes_notification(sample
assert Notification.query.count() == 0
assert NotificationHistory.query.count() == 0
@pytest.mark.parametrize("to_address, notification_type, expected",
[("+447700900000", "sms", True),
("+447700900111", "sms", True),
("+447700900222", "sms", True),
("simulate-delivered@notifications.service.gov.uk", "email", True),
("simulate-delivered-2@notifications.service.gov.uk", "email", True),
("simulate-delivered-3@notifications.service.gov.uk", "email", True),
("07515896969", "sms", False),
("valid_email@test.com", "email", False)])
def test_simulated_recipient(notify_api, to_address, notification_type, expected):
# The values where the expected = 'research-mode' are listed in the config['SIMULATED_EMAIL_ADDRESSES']
# and config['SIMULATED_SMS_NUMBERS']. These values should result in using the research mode queue.
# SIMULATED_EMAIL_ADDRESSES = ('simulate-delivered@notifications.service.gov.uk',
# 'simulate-delivered-2@notifications.service.gov.uk',
# 'simulate-delivered-2@notifications.service.gov.uk')
# SIMULATED_SMS_NUMBERS = ('+447700900000', '+447700900111', '+447700900222')
actual = simulated_recipient(to_address, notification_type)
assert actual == expected