mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-22 08:21:13 -05:00
Choose postage when persisting a notification
This commit is contained in:
@@ -13,7 +13,9 @@ from app.models import (
|
||||
Notification,
|
||||
NotificationHistory,
|
||||
ScheduledNotification,
|
||||
Template
|
||||
Template,
|
||||
LETTER_TYPE,
|
||||
CHOOSE_POSTAGE
|
||||
)
|
||||
from app.notifications.process_notifications import (
|
||||
create_content_for_notification,
|
||||
@@ -27,6 +29,8 @@ from app.utils import cache_key_for_service_template_counter
|
||||
from app.v2.errors import BadRequestError
|
||||
from tests.app.conftest import sample_api_key as create_api_key
|
||||
|
||||
from tests.app.db import create_service, create_template
|
||||
|
||||
|
||||
def test_create_content_for_notification_passes(sample_email_template):
|
||||
template = Template.query.get(sample_email_template.id)
|
||||
@@ -477,6 +481,41 @@ def test_persist_email_notification_stores_normalised_email(
|
||||
assert persisted_notification.normalised_to == expected_recipient_normalised
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"service_permissions, template_postage, expected_postage",
|
||||
[
|
||||
([LETTER_TYPE], "first", "second"),
|
||||
([LETTER_TYPE, CHOOSE_POSTAGE], "first", "first"),
|
||||
([LETTER_TYPE, CHOOSE_POSTAGE], None, "second"),
|
||||
]
|
||||
)
|
||||
def test_persist_letter_notification_finds_correct_postage(
|
||||
mocker,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
service_permissions,
|
||||
template_postage,
|
||||
expected_postage
|
||||
):
|
||||
service = create_service(service_permissions=service_permissions, postage="second")
|
||||
api_key = create_api_key(notify_db, notify_db_session, service=service)
|
||||
template = create_template(service, template_type=LETTER_TYPE, postage=template_postage)
|
||||
mocker.patch('app.dao.templates_dao.dao_get_template_by_id', return_value=template)
|
||||
persist_notification(
|
||||
template_id=template.id,
|
||||
template_version=template.version,
|
||||
recipient="Jane Doe, 10 Downing Street, London",
|
||||
service=service,
|
||||
personalisation=None,
|
||||
notification_type=LETTER_TYPE,
|
||||
api_key_id=api_key.id,
|
||||
key_type=api_key.key_type,
|
||||
)
|
||||
persisted_notification = Notification.query.all()[0]
|
||||
|
||||
assert persisted_notification.postage == expected_postage
|
||||
|
||||
|
||||
@pytest.mark.parametrize('utc_time, day_in_key', [
|
||||
('2016-01-01 23:00:00', '2016-01-01'),
|
||||
('2016-06-01 22:59:00', '2016-06-01'),
|
||||
|
||||
Reference in New Issue
Block a user