mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
add tests
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
|
||||||
@@ -91,3 +93,61 @@ def test_extract_account_number_gov_staging():
|
|||||||
|
|
||||||
def test_check_delivery_receipts():
|
def test_check_delivery_receipts():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def test_aws_value_or_default():
|
||||||
|
event = {
|
||||||
|
"delivery": {"phoneCarrier": "AT&T"},
|
||||||
|
"notification": {"timestamp": "2024-01-01T:12:00:00Z"},
|
||||||
|
}
|
||||||
|
assert (
|
||||||
|
aws_cloudwatch_client._aws_value_or_default(event, "delivery", "phoneCarrier")
|
||||||
|
== "AT&T"
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
aws_cloudwatch_client._aws_value_or_default(
|
||||||
|
event, "delivery", "providerResponse"
|
||||||
|
)
|
||||||
|
== ""
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
aws_cloudwatch_client._aws_value_or_default(event, "notification", "timestamp")
|
||||||
|
== "2024-01-01T:12:00:00Z"
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
aws_cloudwatch_client._aws_value_or_default(event, "nonexistent", "field") == ""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_event_to_db_format_with_missing_fields():
|
||||||
|
event = {
|
||||||
|
"notification": {"messageId": "12345"},
|
||||||
|
"status": "UNKNOWN",
|
||||||
|
"delivery": {},
|
||||||
|
}
|
||||||
|
result = aws_cloudwatch_client.event_to_db_format(event)
|
||||||
|
assert result == {
|
||||||
|
"notification.messageId": "12345",
|
||||||
|
"status": "UNKNOWN",
|
||||||
|
"delivery.phoneCarrier": "",
|
||||||
|
"delivery.providerResponse": "",
|
||||||
|
"@timestamp": "",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_event_to_db_format_with_string_input():
|
||||||
|
event = json.dumps(
|
||||||
|
{
|
||||||
|
"notification": {"messageId": "67890", "timestamp": "2024-01-01T14:00:00Z"},
|
||||||
|
"status": "FAILED",
|
||||||
|
"delivery": {"phoneCarrier": "Verizon", "providerResponse": "Error"},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
result = aws_cloudwatch_client.event_to_db_format(event)
|
||||||
|
assert result == {
|
||||||
|
"notification.messageId": "67890",
|
||||||
|
"status": "FAILED",
|
||||||
|
"delivery.phoneCarrier": "Verizon",
|
||||||
|
"delivery.providerResponse": "Error",
|
||||||
|
"@timestamp": "2024-01-01T14:00:00Z",
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user