mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Merge pull request #2293 from alphagov/choose_postage_for_precompiled
Choose postage on POST request for precompiled letters
This commit is contained in:
@@ -504,6 +504,7 @@ def test_persist_letter_notification_finds_correct_postage(
|
||||
persist_notification(
|
||||
template_id=template.id,
|
||||
template_version=template.version,
|
||||
template_postage=template.postage,
|
||||
recipient="Jane Doe, 10 Downing Street, London",
|
||||
service=service,
|
||||
personalisation=None,
|
||||
|
||||
@@ -90,6 +90,7 @@ def test_send_one_off_notification_calls_persist_correctly_for_sms(
|
||||
persist_mock.assert_called_once_with(
|
||||
template_id=template.id,
|
||||
template_version=template.version,
|
||||
template_postage=None,
|
||||
recipient=post_data['to'],
|
||||
service=template.service,
|
||||
personalisation={'name': 'foo'},
|
||||
@@ -127,6 +128,7 @@ def test_send_one_off_notification_calls_persist_correctly_for_email(
|
||||
persist_mock.assert_called_once_with(
|
||||
template_id=template.id,
|
||||
template_version=template.version,
|
||||
template_postage=None,
|
||||
recipient=post_data['to'],
|
||||
service=template.service,
|
||||
personalisation={'name': 'foo'},
|
||||
@@ -153,6 +155,7 @@ def test_send_one_off_notification_calls_persist_correctly_for_letter(
|
||||
template = create_template(
|
||||
service=service,
|
||||
template_type=LETTER_TYPE,
|
||||
postage='first',
|
||||
subject="Test subject",
|
||||
content="Hello (( Name))\nYour thing is due soon",
|
||||
)
|
||||
@@ -174,6 +177,7 @@ def test_send_one_off_notification_calls_persist_correctly_for_letter(
|
||||
persist_mock.assert_called_once_with(
|
||||
template_id=template.id,
|
||||
template_version=template.version,
|
||||
template_postage='first',
|
||||
recipient=post_data['to'],
|
||||
service=template.service,
|
||||
personalisation=post_data['personalisation'],
|
||||
|
||||
@@ -469,16 +469,27 @@ def test_post_precompiled_letter_with_invalid_base64(client, notify_user, mocker
|
||||
assert not Notification.query.first()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('postage', ['first', 'second'])
|
||||
def test_post_precompiled_letter_notification_returns_201(client, notify_user, mocker, postage):
|
||||
@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'),
|
||||
])
|
||||
def test_post_precompiled_letter_notification_returns_201(
|
||||
client, notify_user, mocker, service_postage, notification_postage, expected_postage
|
||||
):
|
||||
sample_service = create_service(service_permissions=['letter', 'precompiled_letter'])
|
||||
sample_service.postage = postage
|
||||
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 = {
|
||||
"reference": "letter-reference",
|
||||
"content": "bGV0dGVyLWNvbnRlbnQ="
|
||||
}
|
||||
if notification_postage:
|
||||
data["postage"] = notification_postage
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
response = client.post(
|
||||
path="v2/notifications/letter",
|
||||
@@ -493,10 +504,30 @@ def test_post_precompiled_letter_notification_returns_201(client, notify_user, m
|
||||
|
||||
assert notification.billable_units == 0
|
||||
assert notification.status == NOTIFICATION_PENDING_VIRUS_CHECK
|
||||
assert notification.postage == postage
|
||||
assert notification.postage == expected_postage
|
||||
|
||||
notification_history = NotificationHistory.query.one()
|
||||
assert notification_history.postage == postage
|
||||
assert notification_history.postage == expected_postage
|
||||
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
assert resp_json == {'id': str(notification.id), 'reference': 'letter-reference'}
|
||||
|
||||
|
||||
def test_post_letter_notification_throws_error_for_invalid_postage(client, notify_user, mocker):
|
||||
sample_service = create_service(service_permissions=['letter', 'precompiled_letter'])
|
||||
data = {
|
||||
"reference": "letter-reference",
|
||||
"content": "bGV0dGVyLWNvbnRlbnQ=",
|
||||
"postage": "space unicorn"
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
response = client.post(
|
||||
path="v2/notifications/letter",
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
|
||||
assert response.status_code == 400, response.get_data(as_text=True)
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
assert resp_json['errors'][0]['message'] == "postage invalid. It must be either first or second."
|
||||
|
||||
assert not Notification.query.first()
|
||||
|
||||
Reference in New Issue
Block a user