Skip to content

Commit 844ad39

Browse files
authored
Don't put fake cost data in our db
For SMS sends with a "test" api key, sends to the internal test number, and for research mode services, we have been adding fake AWS cost data using a mock: notification-api/app/aws/mocks.py The intention with this is to allow our users to simulate a real send, but this is bad because we want the sms_total_carrier_fee and sms_total_message_price columns to be a source of truth. This PR doesn't change the mock (it is used in various tests) but sets those values to null so that we don't get bad cost data in our db.
1 parent e7ecaac commit 844ad39

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

app/celery/research_mode_tasks.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import random
23
from datetime import datetime, timedelta
34

@@ -81,7 +82,7 @@ def aws_pinpoint_callback(notification_id, to):
8182
using_test_temp_fail_number = to.strip().endswith(temp_fail)
8283

8384
if using_test_perm_fail_number or using_test_temp_fail_number:
84-
return pinpoint_failed_callback(
85+
body = pinpoint_failed_callback(
8586
"Phone is currently unreachable/unavailable"
8687
if using_test_perm_fail_number
8788
else "Phone carrier is currently unreachable/unavailable",
@@ -90,7 +91,14 @@ def aws_pinpoint_callback(notification_id, to):
9091
timestamp=timestamp,
9192
)
9293
else:
93-
return pinpoint_delivered_callback(notification_id, destination=to, timestamp=timestamp)
94+
body = pinpoint_delivered_callback(notification_id, destination=to, timestamp=timestamp)
95+
96+
# Strip cost fields — research mode / test sends should not record cost data
97+
message = json.loads(body["Message"])
98+
message.pop("totalMessagePrice", None)
99+
message.pop("totalCarrierFee", None)
100+
body["Message"] = json.dumps(message)
101+
return body
94102

95103

96104
@notify_celery.task(

tests/app/celery/test_research_mode_tasks.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
sns_success_callback,
1717
)
1818
from app.celery.research_mode_tasks import (
19+
aws_pinpoint_callback,
1920
create_fake_letter_response_file,
2021
send_email_response,
2122
send_sms_response,
@@ -73,7 +74,28 @@ def test_make_pinpoint_success_callback(notify_api, mocker, phone_number, pinpoi
7374
mock_task.apply_async.assert_called_once_with(ANY, queue=QueueNames.RESEARCH_MODE)
7475
message_celery = mock_task.apply_async.call_args[0][0][0]
7576
pinpoint_callback_args.update({"reference": some_ref, "destination": phone_number, "timestamp": timestamp})
76-
assert message_celery == pinpoint_callback(**pinpoint_callback_args)
77+
78+
# Build expected body without cost fields (research mode strips them)
79+
expected = pinpoint_callback(**pinpoint_callback_args)
80+
expected_message = json.loads(expected["Message"])
81+
expected_message.pop("totalMessagePrice", None)
82+
expected_message.pop("totalCarrierFee", None)
83+
expected["Message"] = json.dumps(expected_message)
84+
85+
assert message_celery == expected
86+
87+
88+
@pytest.mark.parametrize(
89+
"phone_number",
90+
["+15149301630", "+15149301632", "+15149301633"],
91+
)
92+
@freeze_time("2018-01-25 14:00:30")
93+
def test_aws_pinpoint_callback_strips_cost_data(notify_api, phone_number):
94+
some_ref = str(uuid.uuid4())
95+
result = aws_pinpoint_callback(some_ref, phone_number)
96+
message = json.loads(result["Message"])
97+
assert "totalMessagePrice" not in message
98+
assert "totalCarrierFee" not in message
7799

78100

79101
def test_make_ses_callback(notify_api, mocker):

0 commit comments

Comments
 (0)