mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 15:15:38 -05:00
Add letter status received to data model
- in order to reduce the number of statuses in the database the letter status `received` will be mapped to `delivered` internally
This commit is contained in:
@@ -876,6 +876,9 @@ NOTIFICATION_STATUS_TYPES_ENUM = db.Enum(*NOTIFICATION_STATUS_TYPES, name='notif
|
|||||||
|
|
||||||
NOTIFICATION_STATUS_LETTER_ACCEPTED = 'accepted'
|
NOTIFICATION_STATUS_LETTER_ACCEPTED = 'accepted'
|
||||||
NOTIFICATION_STATUS_LETTER_ACCEPTED_PRETTY = 'Accepted'
|
NOTIFICATION_STATUS_LETTER_ACCEPTED_PRETTY = 'Accepted'
|
||||||
|
NOTIFICATION_STATUS_LETTER_RECEIVED = 'received'
|
||||||
|
|
||||||
|
DVLA_STATUS_SENT = 'Sent'
|
||||||
|
|
||||||
|
|
||||||
class NotificationStatusTypes(db.Model):
|
class NotificationStatusTypes(db.Model):
|
||||||
@@ -986,6 +989,14 @@ class Notification(db.Model):
|
|||||||
['technical-failure', 'temporary-failure', 'permanent-failure', 'created', 'sending']
|
['technical-failure', 'temporary-failure', 'permanent-failure', 'created', 'sending']
|
||||||
|
|
||||||
|
|
||||||
|
-
|
||||||
|
|
||||||
|
> IN
|
||||||
|
'delivered'
|
||||||
|
|
||||||
|
< OUT
|
||||||
|
['received']
|
||||||
|
|
||||||
:param status_or_statuses: a single status or list of statuses
|
:param status_or_statuses: a single status or list of statuses
|
||||||
:return: a single status or list with the current failure statuses substituted for 'failure'
|
:return: a single status or list with the current failure statuses substituted for 'failure'
|
||||||
"""
|
"""
|
||||||
@@ -994,6 +1005,7 @@ class Notification(db.Model):
|
|||||||
return (
|
return (
|
||||||
NOTIFICATION_STATUS_TYPES_FAILED if _status == NOTIFICATION_FAILED else
|
NOTIFICATION_STATUS_TYPES_FAILED if _status == NOTIFICATION_FAILED else
|
||||||
[NOTIFICATION_CREATED, NOTIFICATION_SENDING] if _status == NOTIFICATION_STATUS_LETTER_ACCEPTED else
|
[NOTIFICATION_CREATED, NOTIFICATION_SENDING] if _status == NOTIFICATION_STATUS_LETTER_ACCEPTED else
|
||||||
|
NOTIFICATION_DELIVERED if _status == NOTIFICATION_STATUS_LETTER_RECEIVED else
|
||||||
[_status]
|
[_status]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1044,6 +1056,7 @@ class Notification(db.Model):
|
|||||||
'technical-failure': 'Technical failure',
|
'technical-failure': 'Technical failure',
|
||||||
'sending': NOTIFICATION_STATUS_LETTER_ACCEPTED_PRETTY,
|
'sending': NOTIFICATION_STATUS_LETTER_ACCEPTED_PRETTY,
|
||||||
'created': NOTIFICATION_STATUS_LETTER_ACCEPTED_PRETTY,
|
'created': NOTIFICATION_STATUS_LETTER_ACCEPTED_PRETTY,
|
||||||
|
'delivered': 'Received'
|
||||||
}
|
}
|
||||||
}[self.template.template_type].get(self.status, self.status)
|
}[self.template.template_type].get(self.status, self.status)
|
||||||
|
|
||||||
@@ -1058,8 +1071,10 @@ class Notification(db.Model):
|
|||||||
# get the two code flows mixed up at all
|
# get the two code flows mixed up at all
|
||||||
assert self.notification_type == LETTER_TYPE
|
assert self.notification_type == LETTER_TYPE
|
||||||
|
|
||||||
if self.status == NOTIFICATION_CREATED or NOTIFICATION_SENDING:
|
if self.status in [NOTIFICATION_CREATED, NOTIFICATION_SENDING]:
|
||||||
return NOTIFICATION_STATUS_LETTER_ACCEPTED
|
return NOTIFICATION_STATUS_LETTER_ACCEPTED
|
||||||
|
elif self.status == NOTIFICATION_DELIVERED:
|
||||||
|
return NOTIFICATION_STATUS_LETTER_RECEIVED
|
||||||
else:
|
else:
|
||||||
# Currently can only be technical-failure
|
# Currently can only be technical-failure
|
||||||
return self.status
|
return self.status
|
||||||
|
|||||||
@@ -10,12 +10,14 @@ from app.models import (
|
|||||||
MOBILE_TYPE,
|
MOBILE_TYPE,
|
||||||
EMAIL_TYPE,
|
EMAIL_TYPE,
|
||||||
NOTIFICATION_CREATED,
|
NOTIFICATION_CREATED,
|
||||||
|
NOTIFICATION_DELIVERED,
|
||||||
NOTIFICATION_SENDING,
|
NOTIFICATION_SENDING,
|
||||||
NOTIFICATION_PENDING,
|
NOTIFICATION_PENDING,
|
||||||
NOTIFICATION_FAILED,
|
NOTIFICATION_FAILED,
|
||||||
NOTIFICATION_TECHNICAL_FAILURE,
|
NOTIFICATION_STATUS_LETTER_ACCEPTED,
|
||||||
|
NOTIFICATION_STATUS_LETTER_RECEIVED,
|
||||||
NOTIFICATION_STATUS_TYPES_FAILED,
|
NOTIFICATION_STATUS_TYPES_FAILED,
|
||||||
NOTIFICATION_STATUS_LETTER_ACCEPTED
|
NOTIFICATION_TECHNICAL_FAILURE
|
||||||
)
|
)
|
||||||
from tests.app.conftest import (
|
from tests.app.conftest import (
|
||||||
sample_template as create_sample_template,
|
sample_template as create_sample_template,
|
||||||
@@ -71,6 +73,7 @@ def test_should_not_build_service_whitelist_from_invalid_contact(recipient_type,
|
|||||||
([NOTIFICATION_FAILED], NOTIFICATION_STATUS_TYPES_FAILED),
|
([NOTIFICATION_FAILED], NOTIFICATION_STATUS_TYPES_FAILED),
|
||||||
([NOTIFICATION_CREATED], [NOTIFICATION_CREATED]),
|
([NOTIFICATION_CREATED], [NOTIFICATION_CREATED]),
|
||||||
([NOTIFICATION_TECHNICAL_FAILURE], [NOTIFICATION_TECHNICAL_FAILURE]),
|
([NOTIFICATION_TECHNICAL_FAILURE], [NOTIFICATION_TECHNICAL_FAILURE]),
|
||||||
|
(NOTIFICATION_STATUS_LETTER_RECEIVED, NOTIFICATION_DELIVERED),
|
||||||
# passing in lists containing multiple statuses
|
# passing in lists containing multiple statuses
|
||||||
([NOTIFICATION_FAILED, NOTIFICATION_CREATED], NOTIFICATION_STATUS_TYPES_FAILED + [NOTIFICATION_CREATED]),
|
([NOTIFICATION_FAILED, NOTIFICATION_CREATED], NOTIFICATION_STATUS_TYPES_FAILED + [NOTIFICATION_CREATED]),
|
||||||
([NOTIFICATION_CREATED, NOTIFICATION_PENDING], [NOTIFICATION_CREATED, NOTIFICATION_PENDING]),
|
([NOTIFICATION_CREATED, NOTIFICATION_PENDING], [NOTIFICATION_CREATED, NOTIFICATION_PENDING]),
|
||||||
@@ -132,7 +135,8 @@ def test_notification_for_csv_returns_correct_job_row_number(notify_db, notify_d
|
|||||||
('sms', 'sent', 'Sent internationally'),
|
('sms', 'sent', 'Sent internationally'),
|
||||||
('letter', 'created', 'Accepted'),
|
('letter', 'created', 'Accepted'),
|
||||||
('letter', 'sending', 'Accepted'),
|
('letter', 'sending', 'Accepted'),
|
||||||
('letter', 'technical-failure', 'Technical failure')
|
('letter', 'technical-failure', 'Technical failure'),
|
||||||
|
('letter', 'delivered', 'Received')
|
||||||
])
|
])
|
||||||
def test_notification_for_csv_returns_formatted_status(
|
def test_notification_for_csv_returns_formatted_status(
|
||||||
notify_db,
|
notify_db,
|
||||||
|
|||||||
Reference in New Issue
Block a user