mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 10:21:14 -05:00
add postage to notification + noti_history
if it's a letter notification, postage must equal "first" or "second", else it must equal null
This commit is contained in:
@@ -178,7 +178,8 @@ def create_notification(
|
||||
one_off=False,
|
||||
sms_sender_id=None,
|
||||
reply_to_text=None,
|
||||
created_by_id=None
|
||||
created_by_id=None,
|
||||
postage=None
|
||||
):
|
||||
if created_at is None:
|
||||
created_at = datetime.utcnow()
|
||||
@@ -196,6 +197,9 @@ def create_notification(
|
||||
if not api_key:
|
||||
api_key = create_api_key(template.service, key_type=key_type)
|
||||
|
||||
if template.template_type == 'letter' and postage is None:
|
||||
postage = 'second'
|
||||
|
||||
data = {
|
||||
'id': uuid.uuid4(),
|
||||
'to': to_field,
|
||||
@@ -224,7 +228,8 @@ def create_notification(
|
||||
'phone_prefix': phone_prefix,
|
||||
'normalised_to': normalised_to,
|
||||
'reply_to_text': reply_to_text,
|
||||
'created_by_id': created_by_id
|
||||
'created_by_id': created_by_id,
|
||||
'postage': postage
|
||||
}
|
||||
notification = Notification(**data)
|
||||
dao_create_notification(notification)
|
||||
|
||||
@@ -9,11 +9,6 @@ from tests.app.db import (
|
||||
create_template,
|
||||
)
|
||||
|
||||
from tests.app.conftest import (
|
||||
sample_notification,
|
||||
sample_email_notification,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('billable_units, provider', [
|
||||
(1, 'mmg'),
|
||||
@@ -75,7 +70,8 @@ def test_get_notification_by_id_returns_200(
|
||||
"subject": None,
|
||||
'sent_at': sample_notification.sent_at,
|
||||
'completed_at': sample_notification.completed_at(),
|
||||
'scheduled_for': '2017-05-12T14:15:00.000000Z'
|
||||
'scheduled_for': '2017-05-12T14:15:00.000000Z',
|
||||
'postage': None,
|
||||
}
|
||||
|
||||
assert json_response == expected_response
|
||||
@@ -126,7 +122,8 @@ def test_get_notification_by_id_with_placeholders_returns_200(
|
||||
"subject": "Bob",
|
||||
'sent_at': sample_notification.sent_at,
|
||||
'completed_at': sample_notification.completed_at(),
|
||||
'scheduled_for': None
|
||||
'scheduled_for': None,
|
||||
'postage': None,
|
||||
}
|
||||
|
||||
assert json_response == expected_response
|
||||
@@ -267,17 +264,22 @@ def test_get_notification_adds_delivery_estimate_for_letters(
|
||||
assert json_response['estimated_delivery'] == estimated_delivery
|
||||
|
||||
|
||||
@pytest.mark.parametrize('notification_mock', [
|
||||
sample_notification,
|
||||
sample_email_notification,
|
||||
])
|
||||
def test_get_notification_doesnt_have_delivery_estimate_for_non_letters(
|
||||
client,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
notification_mock,
|
||||
):
|
||||
mocked_notification = notification_mock(notify_db, notify_db_session)
|
||||
def test_get_notification_by_id_returns_postage_class_for_letters(client, sample_letter_notification):
|
||||
auth_header = create_authorization_header(service_id=sample_letter_notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications/{}'.format(sample_letter_notification.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json['postage'] == 'second'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('template_type', ['sms', 'email'])
|
||||
def test_get_notification_doesnt_have_delivery_estimate_for_non_letters(client, sample_service, template_type):
|
||||
template = create_template(service=sample_service, template_type=template_type)
|
||||
mocked_notification = create_notification(template=template)
|
||||
|
||||
auth_header = create_authorization_header(service_id=mocked_notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications/{}'.format(mocked_notification.id),
|
||||
|
||||
Reference in New Issue
Block a user