Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions integration_test/integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def send_email_notification_test_response(python_client, reply_to=None):
personalisation=personalisation,
one_click_unsubscribe_url=one_click_unsubscribe_url,
email_reply_to_id=email_reply_to_id,
sanitise_content_for=["name"],
)
validate(response, post_email_response)
assert unique_name in response["content"]["body"] # check placeholders are replaced
Expand Down
8 changes: 6 additions & 2 deletions integration_test/schemas/v2/notification_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
},
"required": ["id", "content", "uri", "template"],
}

# TODO: this doesn't seem to be used anywhere, do we still need it?
post_email_request = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "POST email notification schema",
Expand All @@ -128,6 +128,7 @@
"email_reply_to_id": uuid,
"personalisation": personalisation,
"one_click_unsubscribe_url": https_url,
"sanitise_content_for": {"type": "array", "items": {"type": "string"}},
},
"required": ["email_address", "template_id"],
}
Expand Down Expand Up @@ -156,8 +157,9 @@
"content": email_content,
"uri": {"type": "string"},
"template": template,
"sanitised_content": {"type": "object"},
},
"required": ["id", "content", "uri", "template"],
"required": ["id", "content", "uri", "template", "sanitised_content"],
}

post_letter_request = {
Expand Down Expand Up @@ -217,13 +219,15 @@ def create_post_sms_response_from_notification(notification, body, from_number,
}


# TODO: we don't seem to be using this, is it needed?
def create_post_email_response_from_notification(notification, content, subject, email_from, url_root):
return {
"id": notification.id,
"reference": notification.client_reference,
"content": {"from_email": email_from, "body": content, "subject": subject},
"uri": f"{url_root}/v2/notifications/{str(notification.id)}",
"template": __create_template_from_notification(notification=notification, url_root=url_root),
"sanitised_content": {},
}


Expand Down
3 changes: 3 additions & 0 deletions notifications_python_client/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def send_email_notification(
reference=None,
email_reply_to_id=None,
one_click_unsubscribe_url=None,
sanitise_content_for=None,
):
notification = {"email_address": email_address, "template_id": template_id}
if personalisation:
Expand All @@ -39,6 +40,8 @@ def send_email_notification(
notification.update({"email_reply_to_id": email_reply_to_id})
if one_click_unsubscribe_url:
notification.update({"one_click_unsubscribe_url": one_click_unsubscribe_url})
if sanitise_content_for:
notification.update({"sanitise_content_for": sanitise_content_for})

return self.post("/v2/notifications/email", data=notification)

Expand Down
19 changes: 19 additions & 0 deletions tests/notifications_python_client/test_notifications_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,25 @@ def test_create_email_notification_with_personalisation(notifications_client, rm
}


def test_create_email_notification_with_sanitise_content_for(notifications_client, rmock):
endpoint = f"{TEST_HOST}/v2/notifications/email"
rmock.request("POST", endpoint, json={"status": "success"}, status_code=200)

notifications_client.send_email_notification(
email_address="to@example.com",
template_id="456",
personalisation={"name": "chris", "link": "https://www.safe-link.gov.uk"},
sanitise_content_for=["name"],
)

assert rmock.last_request.json() == {
"template_id": "456",
"email_address": "to@example.com",
"personalisation": {"name": "chris", "link": "https://www.safe-link.gov.uk"},
"sanitise_content_for": ["name"],
}


def test_create_email_notification_with_one_click_unsubscribe_url(notifications_client, rmock):
endpoint = f"{TEST_HOST}/v2/notifications/email"
rmock.request("POST", endpoint, json={"status": "success"}, status_code=200)
Expand Down
Loading