Skip to content

Commit

Permalink
add test for missing sms data
Browse files Browse the repository at this point in the history
  • Loading branch information
sastels committed Oct 15, 2024
1 parent 46ec67f commit 5eb0117
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
25 changes: 24 additions & 1 deletion app/aws/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def pinpoint_delivered_callback(reference=None, timestamp=1467074434, destinatio
"isoCountryCode": "CA",
"mcc": "302",
"mnc": "610",
"carrierName": "Bell Cellular Inc. / Aliant Telecom",
"carrierName": "Bell",
"messageId": reference,
"messageRequestTimestamp": timestamp,
"messageEncoding": "GSM",
Expand All @@ -254,6 +254,7 @@ def pinpoint_shortcode_delivered_callback(reference=None, timestamp=1467074434,
"originationPhoneNumber": "555555",
"destinationPhoneNumber": destination,
"isoCountryCode": "CA",
"carrierName": "Bell",
"messageId": reference,
"messageRequestTimestamp": timestamp,
"messageEncoding": "GSM",
Expand All @@ -268,6 +269,28 @@ def pinpoint_shortcode_delivered_callback(reference=None, timestamp=1467074434,
return _pinpoint_callback(body)


def pinpoint_delivered_callback_missing_sms_data(reference=None, timestamp=1467074434, destination="+1XXX5550100"):
body = {
"eventType": "TEXT_DELIVERED",
"eventVersion": "1.0",
"eventTimestamp": timestamp,
"isFinal": True,
"originationPhoneNumber": "+13655550100",
"destinationPhoneNumber": destination,
"messageId": reference,
"messageRequestTimestamp": timestamp,
"messageEncoding": "GSM",
"messageType": "TRANSACTIONAL",
"messageStatus": "DELIVERED",
"messageStatusDescription": "Message has been accepted by phone",
"totalMessageParts": 1,
"totalMessagePrice": 0.00581,
"totalCarrierFee": 0.006,
}

return _pinpoint_callback(body)


# Note that 1467074434 = 2016-06-28 00:40:34.558 UTC
def pinpoint_failed_callback(provider_response, reference=None, timestamp=1467074434, destination="+1XXX5550100"):
body = {
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/0461_add_pinpoint_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

revision = "0461_add_pinpoint_fields"
down_revision = "0460_new_service_columns"
Expand Down
28 changes: 27 additions & 1 deletion tests/app/celery/test_process_pinpoint_receipts_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from app import statsd_client
from app.aws.mocks import (
pinpoint_delivered_callback,
pinpoint_delivered_callback_missing_sms_data,
pinpoint_failed_callback,
pinpoint_shortcode_delivered_callback,
pinpoint_successful_callback,
Expand All @@ -30,7 +31,7 @@


@pytest.mark.parametrize(
"callback,expected_response,origination_phone_number",
"callback, expected_response, origination_phone_number",
[
(pinpoint_delivered_callback, "Message has been accepted by phone", "+13655550100"),
(pinpoint_shortcode_delivered_callback, "Message has been accepted by phone carrier", "555555"),
Expand Down Expand Up @@ -61,6 +62,7 @@ def test_process_pinpoint_results_delivered(
assert float(get_notification_by_id(notification.id).sms_total_message_price) == 0.00581
assert float(get_notification_by_id(notification.id).sms_total_carrier_fee) == 0.006
assert get_notification_by_id(notification.id).sms_iso_country_code == "CA"
assert get_notification_by_id(notification.id).sms_carrier_name == "Bell"
assert get_notification_by_id(notification.id).sms_message_encoding == "GSM"
assert get_notification_by_id(notification.id).sms_origination_phone_number == origination_phone_number

Expand Down Expand Up @@ -88,6 +90,30 @@ def test_process_pinpoint_results_succeeded(sample_template, notify_db, notify_d
assert get_notification_by_id(notification.id).provider_response is None


def test_process_pinpoint_results_missing_sms_data(sample_template, notify_db, notify_db_session, mocker):
mock_callback_task = mocker.patch("app.notifications.callbacks._check_and_queue_callback_task")

notification = create_sample_notification(
notify_db,
notify_db_session,
template=sample_template,
reference="ref",
status=NOTIFICATION_SENT,
sent_by="pinpoint",
sent_at=datetime.utcnow(),
)
assert get_notification_by_id(notification.id).status == NOTIFICATION_SENT

process_pinpoint_results(pinpoint_delivered_callback_missing_sms_data(reference="ref"))

assert mock_callback_task.called_once_with(get_notification_by_id(notification.id))
assert get_notification_by_id(notification.id).status == NOTIFICATION_DELIVERED
assert float(get_notification_by_id(notification.id).sms_total_message_price) == 0.00581
assert float(get_notification_by_id(notification.id).sms_total_carrier_fee) == 0.006
assert get_notification_by_id(notification.id).sms_iso_country_code is None
assert get_notification_by_id(notification.id).sms_carrier_name is None


@pytest.mark.parametrize(
"provider_response, expected_status, should_log_warning, should_save_provider_response",
[
Expand Down

0 comments on commit 5eb0117

Please sign in to comment.