From c14663d84aeadb349e61beae4d981b3e94bee064 Mon Sep 17 00:00:00 2001 From: Ken Tsang Date: Mon, 26 Feb 2018 13:53:06 +0000 Subject: [PATCH] Fix serialization on precompiled letter Postcodes are required for created letters, but not for precompiled, this fix allows postcodes to be None in the model. As postcodes are still required for created letter they should be caught by validation schemas in the POST handler --- app/models.py | 2 +- tests/app/test_model.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models.py b/app/models.py index f8594bc50..b9e65b58c 100644 --- a/app/models.py +++ b/app/models.py @@ -1313,7 +1313,7 @@ class Notification(db.Model): serialized['line_4'] = col.get('address_line_4') serialized['line_5'] = col.get('address_line_5') serialized['line_6'] = col.get('address_line_6') - serialized['postcode'] = self.personalisation['postcode'] + serialized['postcode'] = col.get('postcode') serialized['estimated_delivery'] = \ get_letter_timings(serialized['created_at'])\ .earliest_delivery\ diff --git a/tests/app/test_model.py b/tests/app/test_model.py index af73e1460..a0b8d4804 100644 --- a/tests/app/test_model.py +++ b/tests/app/test_model.py @@ -307,3 +307,15 @@ def test_letter_notification_serializes_correctly(client, sample_letter_notifica assert json['line_1'] == 'test' assert json['line_2'] == 'London' assert json['postcode'] == 'N1' + + +def test_letter_notification_postcode_can_be_null_for_precompiled_letters(client, sample_letter_notification): + sample_letter_notification.personalisation = { + 'address_line_1': 'test', + 'address_line_2': 'London', + } + + json = sample_letter_notification.serialize() + assert json['line_1'] == 'test' + assert json['line_2'] == 'London' + assert json['postcode'] is None