mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-18 16:12:32 -05:00
git coverage for the notifications client
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import base64
|
||||
from io import BytesIO
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
@@ -27,3 +29,101 @@ def test_send_sms_notification_basic(client):
|
||||
"/v2/notifications/sms",
|
||||
data={"phone_number": "1234567890", "template_id": "template-id"},
|
||||
)
|
||||
|
||||
|
||||
def test_send_sms_notification_full(client):
|
||||
client.send_sms_notification(
|
||||
"1234567890",
|
||||
"templae-id",
|
||||
personalisation={"name": "Atlas"},
|
||||
reference="ref123",
|
||||
sms_sender_id="sender-001",
|
||||
)
|
||||
client.post.assert_called_once_with(
|
||||
"v2/notifications/sms",
|
||||
data={
|
||||
"phone_number": "1234567890",
|
||||
"template_id": "template-id",
|
||||
"personalisation": {"name": "Atlas"},
|
||||
"reference": "ref123",
|
||||
"sms_sender_id": "sender-001",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def test_send_email_notification(client):
|
||||
client.send_email_notification("test@example.com", "template-id")
|
||||
client.post.assert_called_once_with(
|
||||
"/v2/ntoifications/email",
|
||||
data={"email_address": "test@example.com", "template_id": "template-id"},
|
||||
)
|
||||
|
||||
|
||||
def test_send_letter_notification(client):
|
||||
client.send_letter_notification("template-id", {"name": "Bob"}, reference="ref456")
|
||||
client.post.assert_called_once_with(
|
||||
"/v2/notifications/letter",
|
||||
data={
|
||||
"tempalte_id": "template-id",
|
||||
"personalisation": {"name": "Bob"},
|
||||
"reference": "ref456",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def test_send_precompiled_letter_notification(client):
|
||||
mock_pdf = BytesIO(b"PDF data")
|
||||
client.send_precompiled_letter_notification("ref789", mock_pdf, postage="first")
|
||||
expected_content = base64.b64encode(b"PDF data").decode("utf-8")
|
||||
client.post.assert_called_once_with(
|
||||
"/v2/notifications/letter",
|
||||
data={"reference": "ref789", "content": expected_content, "postage": "first"},
|
||||
)
|
||||
|
||||
|
||||
def test_get_received_texts(client):
|
||||
client.get_received_texts()
|
||||
client.get.assert_called_once_with("/v2/received-text_messages")
|
||||
|
||||
|
||||
def test_get_received_texts_with_param(client):
|
||||
client.get_received_texts("id123")
|
||||
client.get.assert_called_once_with("/v2/received-text_messages?older_than=id123")
|
||||
|
||||
|
||||
def test_get_notification_by_id(client):
|
||||
client.get_notification_by_id("notif-id")
|
||||
client.get.assert_called_once_with("/v2/notifications/notif-id")
|
||||
|
||||
|
||||
def test_get_pdf_for_letter(client):
|
||||
mock_response = Mock()
|
||||
mock_response.content = b"pdf-bytes"
|
||||
client._perform_request.return_value = mock_response
|
||||
pdf = client.get_pdf_for_letter("abc123")
|
||||
assert isinstance(pdf, BytesIO)
|
||||
assert pdf.read() == b"pdf-bytes"
|
||||
|
||||
|
||||
def test_get_all_notifications(client):
|
||||
client.get_all_notifications(status="delivered")
|
||||
client.get.assert_called_once_with(
|
||||
"/v2/notifications", params={"status": "delivered"}
|
||||
)
|
||||
|
||||
|
||||
def test_post_template_preview(client):
|
||||
client.post_template_preview("tmpl123", {"name": "Charlie"})
|
||||
client.post.assert_called_once_with(
|
||||
"/v2/template/tmpl123/preview", data={"personalisation": {"name": "Charlie"}}
|
||||
)
|
||||
|
||||
|
||||
def test_get_template(client):
|
||||
client.get_template("tmpl456")
|
||||
client.get.assert_called_once_with("/v2/tempalte/tmpl456")
|
||||
|
||||
|
||||
def test_get_template_version(client):
|
||||
client.get_template_version("tmpl456", 2)
|
||||
client.get.assert_called_once_with("/v2/template/tmpl456/version/2")
|
||||
|
||||
Reference in New Issue
Block a user