Remove the template_postage parameter for persist_notification

It was confusing to have 2 differnt postage parameters.
This commit is contained in:
Rebecca Law
2020-08-04 15:41:42 +01:00
parent 10fe7d9fe8
commit 4a9f9e4b17
7 changed files with 11 additions and 20 deletions

View File

@@ -354,7 +354,7 @@ def save_letter(
saved_notification = persist_notification(
template_id=notification['template'],
template_version=notification['template_version'],
template_postage=template.postage,
postage=template.postage,
recipient=recipient,
service=service,
personalisation=notification['personalisation'],

View File

@@ -19,7 +19,6 @@ def create_letter_notification(
notification = persist_notification(
template_id=template.id,
template_version=template.version,
template_postage=template.postage,
# we only accept addresses_with_underscores from the API (from CSV we also accept dashes, spaces etc)
recipient=PostalAddress.from_personalisation(letter_data['personalisation']).normalised,
service=service,
@@ -34,9 +33,9 @@ def create_letter_notification(
status=status,
reply_to_text=reply_to_text,
billable_units=billable_units,
# letter_data.get('postage') is only set for precompiled letters
# letter_data.get('postage') is only set for precompiled letters (if international it is set after sanitise)
# letters from a template will pass in 'europe' or 'rest-of-world' if None then use postage from template
postage=postage or letter_data.get('postage'),
postage=postage or letter_data.get('postage') or template.postage,
updated_at=updated_at
)
return notification

View File

@@ -107,7 +107,6 @@ def persist_notification(
reply_to_text=None,
billable_units=None,
postage=None,
template_postage=None,
document_download_count=None,
updated_at=None
):
@@ -147,8 +146,8 @@ def persist_notification(
elif notification_type == EMAIL_TYPE:
notification.normalised_to = format_email_address(notification.to)
elif notification_type == LETTER_TYPE:
notification.postage = postage or template_postage
notification.international = True if postage in INTERNATIONAL_POSTAGE_TYPES else False
notification.postage = postage
notification.international = postage in INTERNATIONAL_POSTAGE_TYPES
notification.normalised_to = ''.join(notification.to.split()).lower()
# if simulated create a Notification model to return but do not persist the Notification to the dB

View File

@@ -120,7 +120,7 @@ def send_notification(notification_type):
simulated = simulated_recipient(notification_form['to'], notification_type)
notification_model = persist_notification(template_id=template.id,
template_version=template.version,
template_postage=template.postage,
postage=template.postage,
recipient=request.get_json()['to'],
service=authenticated_service,
personalisation=notification_form.get('personalisation', None),

View File

@@ -80,6 +80,8 @@ def send_one_off_notification(service_id, post_data):
# Validate address and set postage to europe|rest-of-world if international letter,
# otherwise persist_notification with use template postage
postage = validate_address(service, personalisation)
if not postage:
postage = template.postage
validate_created_by(service, post_data['created_by'])
sender_id = post_data.get('sender_id', None)
@@ -92,7 +94,6 @@ def send_one_off_notification(service_id, post_data):
notification = persist_notification(
template_id=template.id,
template_version=template.version,
template_postage=template.postage,
recipient=post_data['to'],
service=service,
personalisation=personalisation,
@@ -178,7 +179,6 @@ def send_pdf_letter_notification(service_id, post_data):
notification_id=post_data['file_id'],
template_id=template.id,
template_version=template.version,
template_postage=template.postage,
recipient=urllib.parse.unquote(post_data['recipient_address']),
service=service,
personalisation=personalisation,
@@ -189,7 +189,7 @@ def send_pdf_letter_notification(service_id, post_data):
client_reference=post_data['filename'],
created_by_id=post_data['created_by'],
billable_units=billable_units,
postage=post_data['postage'],
postage=post_data['postage'] or template.postage,
)
upload_filename = get_letter_pdf_filename(

View File

@@ -489,8 +489,7 @@ def test_persist_email_notification_stores_normalised_email(
[
("second", "first", "second"),
("first", "first", "first"),
("first", "second", "first"),
(None, "second", "second")
("first", "second", "first")
]
)
def test_persist_letter_notification_finds_correct_postage(
@@ -506,7 +505,6 @@ 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=sample_service_full_permissions,
personalisation=None,
@@ -536,7 +534,6 @@ def test_persist_notification_with_billable_units_stores_correct_info(
api_key_id=None,
key_type="normal",
billable_units=3,
template_postage=template.postage
)
persisted_notification = Notification.query.all()[0]
@@ -556,7 +553,6 @@ def test_persist_notification_for_international_letter(sample_letter_template, p
key_type="normal",
billable_units=3,
postage=postage,
template_postage='second'
)
persisted_notification = Notification.query.get(notification.id)
assert persisted_notification.postage == postage

View File

@@ -90,7 +90,6 @@ 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'},
@@ -152,7 +151,6 @@ 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'},
@@ -202,7 +200,6 @@ 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'],
@@ -212,7 +209,7 @@ def test_send_one_off_notification_calls_persist_correctly_for_letter(
created_by_id=str(service.created_by_id),
reply_to_text=None,
reference='this-is-random-in-real-life',
postage=None
postage='first'
)