Include the notification sender name when serializing notifications

The `serialize` method of the Notification model now includes the
`created_by_name`. If a notification was sent as a one-off message this
value will now be the name of the person who sent the notification. If
a notification was sent through the API or by a CSV upload we don't
record the id of the sender, so `created_by_name` will be `None`.

This change affects the data that gets returned from these endpoints:
* /v2/notifications/<notification_id>
* /v2/notifications
This commit is contained in:
Katie Smith
2018-07-16 13:12:17 +01:00
parent ff3a71a9ea
commit af5c4d2872
3 changed files with 38 additions and 0 deletions

View File

@@ -225,6 +225,17 @@ def test_letter_notification_serializes_with_address(client, sample_letter_notif
assert res['postcode'] == 'SW1 1AA'
def test_notification_serializes_created_by_name_with_no_created_by_id(client, sample_notification):
res = sample_notification.serialize()
assert res['created_by_name'] is None
def test_notification_serializes_created_by_name_with_created_by_id(client, sample_notification, sample_user):
sample_notification.created_by_id = sample_user.id
res = sample_notification.serialize()
assert res['created_by_name'] == sample_user.name
def test_sms_notification_serializes_without_subject(client, sample_template):
res = sample_template.serialize()
assert res['subject'] is None