mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-19 00:51:54 -05:00
Test post letter request sets notification postage correctly
This commit is contained in:
@@ -158,6 +158,7 @@ def sample_service(
|
||||
email_from=None,
|
||||
permissions=None,
|
||||
research_mode=None,
|
||||
postage="second",
|
||||
):
|
||||
if user is None:
|
||||
user = create_user()
|
||||
@@ -170,6 +171,7 @@ def sample_service(
|
||||
'restricted': restricted,
|
||||
'email_from': email_from,
|
||||
'created_by': user,
|
||||
"postage": postage,
|
||||
}
|
||||
service = Service.query.filter_by(name=service_name).first()
|
||||
if not service:
|
||||
|
||||
@@ -20,6 +20,7 @@ from app.models import (
|
||||
NOTIFICATION_DELIVERED,
|
||||
NOTIFICATION_PENDING_VIRUS_CHECK,
|
||||
SMS_TYPE,
|
||||
CHOOSE_POSTAGE
|
||||
)
|
||||
from app.schema_validation import validate
|
||||
from app.v2.errors import RateLimitError
|
||||
@@ -95,12 +96,23 @@ def test_post_letter_notification_returns_201(client, sample_letter_template, mo
|
||||
mock.assert_called_once_with([str(notification.id)], queue=QueueNames.CREATE_LETTERS_PDF)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('postage', ['first', 'second'])
|
||||
def test_post_letter_notification_sets_postage(client, sample_letter_template, mocker, postage):
|
||||
sample_letter_template.service.postage = postage
|
||||
@pytest.mark.parametrize('service_permissions, service_postage, template_postage, expected_postage', [
|
||||
([LETTER_TYPE], "second", "first", "second"),
|
||||
([LETTER_TYPE], "first", "second", "first"),
|
||||
([LETTER_TYPE], "first", None, "first"),
|
||||
([LETTER_TYPE, CHOOSE_POSTAGE], "second", "first", "first"),
|
||||
([LETTER_TYPE, CHOOSE_POSTAGE], "second", None, "second"),
|
||||
([LETTER_TYPE, CHOOSE_POSTAGE], "second", "second", "second"),
|
||||
([LETTER_TYPE, CHOOSE_POSTAGE], "first", "second", "second"),
|
||||
])
|
||||
def test_post_letter_notification_sets_postage(
|
||||
client, notify_db_session, mocker, service_permissions, service_postage, template_postage, expected_postage
|
||||
):
|
||||
service = create_service(service_permissions=service_permissions, postage=service_postage)
|
||||
template = create_template(service, template_type="letter", postage=template_postage)
|
||||
mocker.patch('app.celery.tasks.letters_pdf_tasks.create_letters_pdf.apply_async')
|
||||
data = {
|
||||
'template_id': str(sample_letter_template.id),
|
||||
'template_id': str(template.id),
|
||||
'personalisation': {
|
||||
'address_line_1': 'Her Royal Highness Queen Elizabeth II',
|
||||
'address_line_2': 'Buckingham Palace',
|
||||
@@ -110,11 +122,11 @@ def test_post_letter_notification_sets_postage(client, sample_letter_template, m
|
||||
}
|
||||
}
|
||||
|
||||
resp_json = letter_request(client, data, service_id=sample_letter_template.service_id)
|
||||
resp_json = letter_request(client, data, service_id=service.id)
|
||||
|
||||
assert validate(resp_json, post_letter_response) == resp_json
|
||||
notification = Notification.query.one()
|
||||
assert notification.postage == postage
|
||||
assert notification.postage == expected_postage
|
||||
|
||||
|
||||
@pytest.mark.parametrize('env', [
|
||||
|
||||
Reference in New Issue
Block a user