mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
Add notification status for returned letters
We need to update letter notifications with a new status when DVLA gives us a list of references for returned letters. This adds the new status to the models and the DB. DVLA call this 'returned mail', so I'm using it as the status name since it seems less ambiguous than 'returned'.
This commit is contained in:
@@ -1050,12 +1050,14 @@ NOTIFICATION_TEMPORARY_FAILURE = 'temporary-failure'
|
||||
NOTIFICATION_PERMANENT_FAILURE = 'permanent-failure'
|
||||
NOTIFICATION_PENDING_VIRUS_CHECK = 'pending-virus-check'
|
||||
NOTIFICATION_VIRUS_SCAN_FAILED = 'virus-scan-failed'
|
||||
NOTIFICATION_RETURNED_LETTER = 'returned-letter'
|
||||
|
||||
NOTIFICATION_STATUS_TYPES_FAILED = [
|
||||
NOTIFICATION_TECHNICAL_FAILURE,
|
||||
NOTIFICATION_TEMPORARY_FAILURE,
|
||||
NOTIFICATION_PERMANENT_FAILURE,
|
||||
NOTIFICATION_VIRUS_SCAN_FAILED,
|
||||
NOTIFICATION_RETURNED_LETTER,
|
||||
]
|
||||
|
||||
NOTIFICATION_STATUS_TYPES_COMPLETED = [
|
||||
@@ -1065,6 +1067,7 @@ NOTIFICATION_STATUS_TYPES_COMPLETED = [
|
||||
NOTIFICATION_TECHNICAL_FAILURE,
|
||||
NOTIFICATION_TEMPORARY_FAILURE,
|
||||
NOTIFICATION_PERMANENT_FAILURE,
|
||||
NOTIFICATION_RETURNED_LETTER,
|
||||
]
|
||||
|
||||
NOTIFICATION_STATUS_SUCCESS = [
|
||||
@@ -1079,6 +1082,7 @@ NOTIFICATION_STATUS_TYPES_BILLABLE = [
|
||||
NOTIFICATION_FAILED,
|
||||
NOTIFICATION_TEMPORARY_FAILURE,
|
||||
NOTIFICATION_PERMANENT_FAILURE,
|
||||
NOTIFICATION_RETURNED_LETTER,
|
||||
]
|
||||
|
||||
NOTIFICATION_STATUS_TYPES = [
|
||||
@@ -1094,6 +1098,7 @@ NOTIFICATION_STATUS_TYPES = [
|
||||
NOTIFICATION_PERMANENT_FAILURE,
|
||||
NOTIFICATION_PENDING_VIRUS_CHECK,
|
||||
NOTIFICATION_VIRUS_SCAN_FAILED,
|
||||
NOTIFICATION_RETURNED_LETTER,
|
||||
]
|
||||
|
||||
NOTIFICATION_STATUS_TYPES_NON_BILLABLE = list(set(NOTIFICATION_STATUS_TYPES) - set(NOTIFICATION_STATUS_TYPES_BILLABLE))
|
||||
@@ -1286,7 +1291,8 @@ class Notification(db.Model):
|
||||
'technical-failure': 'Technical failure',
|
||||
'sending': 'Accepted',
|
||||
'created': 'Accepted',
|
||||
'delivered': 'Received'
|
||||
'delivered': 'Received',
|
||||
'returned-letter': 'Returned',
|
||||
}
|
||||
}[self.template.template_type].get(self.status, self.status)
|
||||
|
||||
|
||||
20
migrations/versions/0224_returned_letter_status.py
Normal file
20
migrations/versions/0224_returned_letter_status.py
Normal file
@@ -0,0 +1,20 @@
|
||||
"""
|
||||
|
||||
Revision ID: 0224_returned_letter_status
|
||||
Revises: 0223_add_domain_constraint
|
||||
Create Date: 2018-08-21 14:44:04.203480
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = '0224_returned_letter_status'
|
||||
down_revision = '0223_add_domain_constraint'
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.execute("INSERT INTO notification_status_types (name) VALUES ('returned-letter')")
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.execute("DELETE FROM notification_status_types WHERE name='returned-letter'")
|
||||
@@ -1683,6 +1683,18 @@ def test_dao_update_notifications_by_reference_returns_zero_when_no_notification
|
||||
assert updated_count == 0
|
||||
|
||||
|
||||
def test_dao_update_notifications_by_reference_set_returned_letter_status(sample_letter_template):
|
||||
notification = create_notification(template=sample_letter_template, reference='ref')
|
||||
|
||||
updated_count = dao_update_notifications_by_reference(
|
||||
references=['ref'],
|
||||
update_dict={"status": "returned-letter"}
|
||||
)
|
||||
|
||||
assert updated_count == 1
|
||||
assert Notification.query.get(notification.id).status == 'returned-letter'
|
||||
|
||||
|
||||
def test_dao_get_notification_by_reference_with_one_match_returns_notification(sample_letter_template, notify_db):
|
||||
create_notification(template=sample_letter_template, reference='REF1')
|
||||
notification = dao_get_notification_by_reference('REF1')
|
||||
|
||||
@@ -443,7 +443,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, " \
|
||||
"pending-virus-check, virus-scan-failed, accepted, received]"
|
||||
"pending-virus-check, virus-scan-failed, returned-letter, accepted, received]"
|
||||
|
||||
|
||||
def test_get_all_notifications_filter_by_multiple_statuses(client, sample_template):
|
||||
|
||||
@@ -44,7 +44,7 @@ def test_get_notifications_request_invalid_statuses(
|
||||
partial_error_status = "is not one of " \
|
||||
"[cancelled, created, sending, sent, delivered, pending, failed, " \
|
||||
"technical-failure, temporary-failure, permanent-failure, pending-virus-check, " \
|
||||
"virus-scan-failed, accepted, received]"
|
||||
"virus-scan-failed, returned-letter, accepted, received]"
|
||||
|
||||
with pytest.raises(ValidationError) as e:
|
||||
validate({'status': invalid_statuses + valid_statuses}, get_notifications_request)
|
||||
@@ -92,7 +92,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-virus-check, virus-scan-failed, accepted, received]".format(
|
||||
"pending-virus-check, virus-scan-failed, returned-letter, accepted, received]".format(
|
||||
invalid_status
|
||||
) in error_messages
|
||||
|
||||
|
||||
Reference in New Issue
Block a user