-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pinpoint fields to notifications #2326
Conversation
3b248e6
to
5eb0117
Compare
@@ -254,15 +254,38 @@ def pinpoint_shortcode_delivered_callback(reference=None, timestamp=1467074434, | |||
"originationPhoneNumber": "555555", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pinpoint_shortcode_delivered_callback
function signature should be updated to include the new carrierName
parameter to ensure it is passed correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, we don't want to ever pass it.
"messageId": reference, | ||
"messageRequestTimestamp": timestamp, | ||
"messageEncoding": "GSM", | ||
"messageType": "TRANSACTIONAL", | ||
"messageStatus": "SUCCESSFUL", | ||
"messageStatusDescription": "Message has been accepted by phone carrier", | ||
"totalMessageParts": 1, | ||
"totalMessagePrice": 0.02183, | ||
"totalCarrierFee": 0.005, | ||
"totalMessagePrice": 0.00581, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change in totalMessagePrice
and totalCarrierFee
values should be verified to ensure they are correct and consistent with the new Pinpoint delivery receipts.
"messageType": "TRANSACTIONAL", | ||
"messageStatus": "DELIVERED", | ||
"messageStatusDescription": "Message has been accepted by phone", | ||
"totalMessageParts": 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The messageStatusDescription
value 'Message has been accepted by phone' seems slightly ambiguous. Ensure this is the correct and intended description for the 'DELIVERED' status.
@@ -53,6 +53,14 @@ def process_pinpoint_results(self, response): | |||
provider_response = receipt["messageStatusDescription"] | |||
isFinal = receipt["isFinal"] | |||
|
|||
# some of these fields might be missing in the receipt | |||
total_message_price = receipt.get("totalMessagePrice") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a default value for total_message_price
in case the key is missing in the receipt. This will ensure that the variable is always initialized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, want it to be None
if it's missing.
@@ -53,6 +53,14 @@ def process_pinpoint_results(self, response): | |||
provider_response = receipt["messageStatusDescription"] | |||
isFinal = receipt["isFinal"] | |||
|
|||
# some of these fields might be missing in the receipt | |||
total_message_price = receipt.get("totalMessagePrice") | |||
total_carrier_fee = receipt.get("totalCarrierFee") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a default value for total_carrier_fee
in case the key is missing in the receipt. This will ensure that the variable is always initialized.
sms_carrier_name = db.Column(db.String(), nullable=True) | ||
sms_message_encoding = db.Column(db.String(), nullable=True) | ||
sms_origination_phone_number = db.Column(db.String(), nullable=True) | ||
|
||
CheckConstraint( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CheckConstraint
should be updated to include the new SMS columns if there are any constraints that should apply to them. Currently, it only appears to handle 'letter' type notifications.
def test_process_pinpoint_results_delivered(sample_template, notify_db, notify_db_session, callback, expected_response, mocker): | ||
def test_process_pinpoint_results_delivered( | ||
sample_template, notify_db, notify_db_session, callback, expected_response, origination_phone_number, mocker | ||
): | ||
mock_logger = mocker.patch("app.celery.process_pinpoint_receipts_tasks.current_app.logger.info") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mock_logger
variable is defined but not used in the test function. Consider removing it if it's not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is being used later in the method...
@@ -56,6 +59,12 @@ def test_process_pinpoint_results_delivered(sample_template, notify_db, notify_d | |||
assert mock_callback_task.called_once_with(get_notification_by_id(notification.id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mock_callback_task.called_once_with
assertion should be mock_callback_task.assert_called_once_with
to correctly use the unittest.mock
library's assertion method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh.... yeah fixing this led me to realize that the mock wasn't actually mocking the right thing... so good on ya, ai reviewer.
@@ -56,6 +59,12 @@ def test_process_pinpoint_results_delivered(sample_template, notify_db, notify_d | |||
assert mock_callback_task.called_once_with(get_notification_by_id(notification.id)) | |||
assert get_notification_by_id(notification.id).status == NOTIFICATION_DELIVERED | |||
assert get_notification_by_id(notification.id).provider_response == expected_response | |||
assert float(get_notification_by_id(notification.id).sms_total_message_price) == 0.00581 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider storing the result of get_notification_by_id(notification.id)
in a variable to avoid multiple database calls and improve readability.
|
||
process_pinpoint_results(pinpoint_delivered_callback_missing_sms_data(reference="ref")) | ||
|
||
assert mock_callback_task.called_once_with(get_notification_by_id(notification.id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method called_once_with
should be assert_called_once_with
to properly assert that the mock was called exactly once with the specified arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
✅ Migration works
✅ New values are passed to the front end from API
✅ Sending and whatnot still works fine locally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I had a few questions.
iso_country_code = receipt.get("isoCountryCode") | ||
carrier_name = receipt.get("carrierName") | ||
message_encoding = receipt.get("messageEncoding") | ||
origination_phone_number = receipt.get("originationPhoneNumber") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So many informative fields that we'll be able to get new insights from. 🥳
app/dao/notifications_dao.py
Outdated
@@ -208,6 +219,19 @@ def _update_notification_status(notification, status, provider_response=None, bo | |||
notification.feedback_subtype = bounce_response.get("feedback_subtype") | |||
notification.ses_feedback_id = bounce_response.get("ses_feedback_id") | |||
notification.ses_feedback_date = bounce_response.get("ses_feedback_date") | |||
if sms_total_message_price: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I was wondering if we need these conditionals too, if a notification
field is already None
and we assign None
again, that should be ok. But there might be a reason of doing it that way? 👀
op.add_column("notification_history", sa.Column("sms_iso_country_code", sa.VARCHAR(), nullable=True)) | ||
op.add_column("notification_history", sa.Column("sms_carrier_name", sa.VARCHAR(), nullable=True)) | ||
op.add_column("notification_history", sa.Column("sms_message_encoding", sa.VARCHAR(), nullable=True)) | ||
op.add_column("notification_history", sa.Column("sms_origination_phone_number", sa.VARCHAR(), nullable=True)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should update the batch process too. I wonder if we can do it in a different PR or if that will have unintended side-effects when the archival jobs will run. Definitely something to test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at that but as far as I can tell it should pull all the fields that we've added to the history table automatically
We should definitely test it though. I'll see if I can test it locally at least. On staging I see we have a minimum 3 days for a retention period.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested locally
- sent an SMS,
- edited the database to give those fields values since we don't process the AWS receipts locally
- also set the dates for the sms in the database to be a month ago
- edited the schedule for the archiving task
delete-sms-notifications
so it would be scheduled in a couple minutes - reran celery locally and waited for it to run
- checked the database - sms with correct fields now in history table, and removed from notifications table 🎉
Approved. Related to these items:
Steve will run performance tests in staging to test the changes and report back on it.
We should regenerate the db doc hosted at Hence these two items are not checks for this PR but we will take actions to address these. |
Summary | Résumé
Add a few useful fields from the Pinpoint delivery receipts to the
notification
andnotification_history
tables.Related Issues | Cartes liées
Test instructions | Instructions pour tester la modification
Kinda hard to test locally :/ Figure the real test is to test in staging after we merge.
Release Instructions | Instructions pour le déploiement
None.
Reviewer checklist | Liste de vérification du réviseur