add tests

This commit is contained in:
Kenneth Kehl
2024-12-26 09:23:00 -08:00
parent 8579efccbc
commit 9f3aec755f

View File

@@ -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",
}