Skip to content

Commit

Permalink
Merge pull request #1503 from GSA/fix_test_coverage
Browse files Browse the repository at this point in the history
more tests
  • Loading branch information
terrazoon authored Dec 26, 2024
2 parents 1ff2923 + 9f3aec7 commit 45a1492
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/app/clients/test_aws_cloudwatch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

import pytest
from flask import current_app

Expand Down Expand Up @@ -87,3 +89,65 @@ def test_extract_account_number_gov_staging():
assert len(actual_account_number) == 6
expected_account_number = "12345"
assert actual_account_number[4] == expected_account_number


def test_check_delivery_receipts():
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",
}

0 comments on commit 45a1492

Please sign in to comment.