Set postage on basis of postage argument or template postage

This commit is contained in:
Pea Tyczynska
2019-02-05 12:48:40 +00:00
parent f6d3e87de5
commit 5b9e6c2086
9 changed files with 63 additions and 69 deletions

View File

@@ -19,8 +19,7 @@ from app.models import (
NOTIFICATION_SENDING,
NOTIFICATION_DELIVERED,
NOTIFICATION_PENDING_VIRUS_CHECK,
SMS_TYPE,
CHOOSE_POSTAGE
SMS_TYPE
)
from app.schema_validation import validate
from app.v2.errors import RateLimitError
@@ -96,20 +95,11 @@ 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('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
client, notify_db_session, mocker
):
service = create_service(service_permissions=service_permissions, postage=service_postage)
template = create_template(service, template_type="letter", postage=template_postage)
service = create_service(service_permissions=[LETTER_TYPE])
template = create_template(service, template_type="letter", postage="first")
mocker.patch('app.celery.tasks.letters_pdf_tasks.create_letters_pdf.apply_async')
data = {
'template_id': str(template.id),
@@ -126,7 +116,7 @@ def test_post_letter_notification_sets_postage(
assert validate(resp_json, post_letter_response) == resp_json
notification = Notification.query.one()
assert notification.postage == expected_postage
assert notification.postage == "first"
@pytest.mark.parametrize('env', [
@@ -469,19 +459,15 @@ def test_post_precompiled_letter_with_invalid_base64(client, notify_user, mocker
assert not Notification.query.first()
@pytest.mark.parametrize('service_postage, notification_postage, expected_postage', [
('second', 'second', 'second'),
('second', 'first', 'first'),
('second', None, 'second'),
('first', 'first', 'first'),
('first', 'second', 'second'),
('first', None, 'first'),
@pytest.mark.parametrize('notification_postage, expected_postage', [
('second', 'second'),
('first', 'first'),
(None, 'second')
])
def test_post_precompiled_letter_notification_returns_201(
client, notify_user, mocker, service_postage, notification_postage, expected_postage
client, notify_user, mocker, notification_postage, expected_postage
):
sample_service = create_service(service_permissions=['letter', 'precompiled_letter'])
sample_service.postage = service_postage
s3mock = mocker.patch('app.v2.notifications.post_notifications.upload_letter_pdf')
mocker.patch('app.celery.letters_pdf_tasks.notify_celery.send_task')
data = {

View File

@@ -10,13 +10,15 @@ from tests.app.db import create_template
valid_version_params = [None, 1]
@pytest.mark.parametrize("tmp_type, expected_name, expected_subject", [
(SMS_TYPE, 'sms Template Name', None),
(EMAIL_TYPE, 'email Template Name', 'Template subject'),
(LETTER_TYPE, 'letter Template Name', 'Template subject')
@pytest.mark.parametrize("tmp_type, expected_name, expected_subject,postage", [
(SMS_TYPE, 'sms Template Name', None, None),
(EMAIL_TYPE, 'email Template Name', 'Template subject', None),
(LETTER_TYPE, 'letter Template Name', 'Template subject', "second")
])
@pytest.mark.parametrize("version", valid_version_params)
def test_get_template_by_id_returns_200(client, sample_service, tmp_type, expected_name, expected_subject, version):
def test_get_template_by_id_returns_200(
client, sample_service, tmp_type, expected_name, expected_subject, version, postage
):
template = create_template(sample_service, template_type=tmp_type)
auth_header = create_authorization_header(service_id=sample_service.id)
@@ -41,7 +43,7 @@ def test_get_template_by_id_returns_200(client, sample_service, tmp_type, expect
"subject": expected_subject,
'name': expected_name,
'personalisation': {},
'postage': None,
'postage': postage,
}
assert json_response == expected_response