diff --git a/tests/app/conftest.py b/tests/app/conftest.py index 15f76846f..6b04e83fe 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -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: diff --git a/tests/app/v2/notifications/test_post_letter_notifications.py b/tests/app/v2/notifications/test_post_letter_notifications.py index 4b42af6dc..734928088 100644 --- a/tests/app/v2/notifications/test_post_letter_notifications.py +++ b/tests/app/v2/notifications/test_post_letter_notifications.py @@ -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', [