Skip to content

Commit

Permalink
Add feedback_reason column to the notification table (#2443)
Browse files Browse the repository at this point in the history
* Add feedback_reason column to the notification table

- Added new notification_status: pinpoint-failure
- Added pinpoint-failure to various enum-like variables

* Fix tests
  • Loading branch information
whabanks authored Feb 10, 2025
1 parent c636d81 commit 72f596d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,7 @@ def check_code(self, cde):
NOTIFICATION_TECHNICAL_FAILURE = "technical-failure"
NOTIFICATION_TEMPORARY_FAILURE = "temporary-failure"
NOTIFICATION_PERMANENT_FAILURE = "permanent-failure"
NOTIFICATION_PINPOINT_FAILURE = "pinpoint-failure"
NOTIFICATION_PENDING_VIRUS_CHECK = "pending-virus-check"
NOTIFICATION_VALIDATION_FAILED = "validation-failed"
NOTIFICATION_VIRUS_SCAN_FAILED = "virus-scan-failed"
Expand All @@ -1558,6 +1559,7 @@ def check_code(self, cde):
NOTIFICATION_TECHNICAL_FAILURE,
NOTIFICATION_TEMPORARY_FAILURE,
NOTIFICATION_PERMANENT_FAILURE,
NOTIFICATION_PINPOINT_FAILURE,
NOTIFICATION_VALIDATION_FAILED,
NOTIFICATION_VIRUS_SCAN_FAILED,
NOTIFICATION_RETURNED_LETTER,
Expand Down Expand Up @@ -1605,6 +1607,7 @@ def check_code(self, cde):
NOTIFICATION_TECHNICAL_FAILURE,
NOTIFICATION_TEMPORARY_FAILURE,
NOTIFICATION_PERMANENT_FAILURE,
NOTIFICATION_PINPOINT_FAILURE,
NOTIFICATION_PENDING_VIRUS_CHECK,
NOTIFICATION_VALIDATION_FAILED,
NOTIFICATION_VIRUS_SCAN_FAILED,
Expand Down Expand Up @@ -1739,6 +1742,7 @@ class Notification(BaseModel):
feedback_subtype = db.Column(db.String, nullable=True)
ses_feedback_id = db.Column(db.String, nullable=True)
ses_feedback_date = db.Column(db.DateTime, nullable=True)
feedback_reason = db.Column(db.String, nullable=True)

# SMS columns
sms_total_message_price = db.Column(db.Numeric(), nullable=True)
Expand Down
1 change: 1 addition & 0 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"temporary-failure",
"permanent-failure",
"technical-failure",
"pinpoint-failure",
"virus-scan-failed",
"validation-failed",
]
Expand Down
41 changes: 41 additions & 0 deletions migrations/versions/0474_add_feedback_reason_column.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Revision ID: 0474_add_feedback_reason_column
Revises: 0473_change_pt_support_email
Create Date: 2025-02-05 14:40:00 EST
"""

import sqlalchemy as sa
from alembic import op

revision = "0474_add_feedback_reason_column"
down_revision = "0473_change_pt_support_email"

new_notification_status = "pinpoint-failure"


def upgrade():
op.add_column("notifications", sa.Column("feedback_reason", sa.String(length=255), nullable=True))
op.add_column("notification_history", sa.Column("feedback_reason", sa.String(length=255), nullable=True))

op.create_index(
op.f("ix_notifications_feedback_reason"),
"notifications",
["feedback_reason"],
)
op.create_index(
op.f("ix_notification_history_feedback_reason"),
"notification_history",
["feedback_reason"],
)

op.execute("INSERT INTO notification_status_types (name) VALUES ('{}')".format(new_notification_status))


def downgrade():
op.drop_index(op.f("ix_notifications_feedback_reason"), table_name="notifications")
op.drop_index(op.f("ix_notification_history_feedback_reason"), table_name="notification_history")
op.drop_column("notifications", "feedback_reason")
op.drop_column("notification_history", "feedback_reason")
op.execute("DELETE FROM notification_status_types WHERE name = '{}'".format(new_notification_status))
2 changes: 1 addition & 1 deletion tests/app/v2/notifications/test_get_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def test_get_all_notifications_filter_by_status_invalid_status(client, sample_no
assert len(json_response["errors"]) == 1
assert (
json_response["errors"][0]["message"] == "status elephant is not one of [cancelled, created, sending, "
"sent, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure, "
"sent, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure, pinpoint-failure, "
"pending-virus-check, validation-failed, virus-scan-failed, returned-letter, "
"pii-check-failed, accepted, received]"
)
Expand Down
4 changes: 2 additions & 2 deletions tests/app/v2/notifications/test_notification_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_get_notifications_request_invalid_statuses(invalid_statuses, valid_stat
partial_error_status = (
"is not one of "
"[cancelled, created, sending, sent, delivered, pending, failed, "
"technical-failure, temporary-failure, permanent-failure, pending-virus-check, "
"technical-failure, temporary-failure, permanent-failure, pinpoint-failure, pending-virus-check, "
"validation-failed, virus-scan-failed, returned-letter, pii-check-failed, accepted, received]"
)

Expand Down Expand Up @@ -103,7 +103,7 @@ def test_get_notifications_request_invalid_statuses_and_template_types():
for invalid_status in ["elephant", "giraffe"]:
assert (
"status {} is not one of [cancelled, created, sending, sent, delivered, "
"pending, failed, technical-failure, temporary-failure, permanent-failure, "
"pending, failed, technical-failure, temporary-failure, permanent-failure, pinpoint-failure, "
"pending-virus-check, validation-failed, virus-scan-failed, returned-letter, "
"pii-check-failed, accepted, received]".format(invalid_status) in error_messages
)
Expand Down

0 comments on commit 72f596d

Please sign in to comment.