allow 'accepted' as a proxy for created + sending as well as 'failed' for the three failure types when querying the api

This commit is contained in:
Leo Hemsted
2017-09-20 15:21:05 +01:00
parent c8ff45be2d
commit 4174c72f21
5 changed files with 25 additions and 18 deletions

View File

@@ -1,3 +1,4 @@
import itertools
import time
import uuid
import datetime
@@ -903,10 +904,10 @@ class Notification(db.Model):
-
> IN
['failed', 'created']
['failed', 'created', 'accepted']
< OUT
['technical-failure', 'temporary-failure', 'permanent-failure', 'created']
['technical-failure', 'temporary-failure', 'permanent-failure', 'created', 'sending']
:param status_or_statuses: a single status or list of statuses
@@ -914,18 +915,17 @@ class Notification(db.Model):
"""
def _substitute_status_str(_status):
return NOTIFICATION_STATUS_TYPES_FAILED if _status == NOTIFICATION_FAILED else _status
return (
NOTIFICATION_STATUS_TYPES_FAILED if _status == NOTIFICATION_FAILED else
[NOTIFICATION_CREATED, NOTIFICATION_SENDING] if _status == NOTIFICATION_STATUS_LETTER_ACCEPTED else
[_status]
)
def _substitute_status_seq(_statuses):
if NOTIFICATION_FAILED in _statuses:
_statuses = list(set(
NOTIFICATION_STATUS_TYPES_FAILED + [_s for _s in _statuses if _s != NOTIFICATION_FAILED]
))
return _statuses
return list(set(itertools.chain.from_iterable(_substitute_status_str(status) for status in _statuses)))
if isinstance(status_or_statuses, str):
return _substitute_status_str(status_or_statuses)
return _substitute_status_seq(status_or_statuses)
@property

View File

@@ -1,4 +1,4 @@
from app.models import NOTIFICATION_STATUS_TYPES, TEMPLATE_TYPES
from app.models import NOTIFICATION_STATUS_TYPES, NOTIFICATION_STATUS_LETTER_ACCEPTED, TEMPLATE_TYPES
from app.schema_validation.definitions import (uuid, personalisation, letter_personalisation)
@@ -59,7 +59,7 @@ get_notifications_request = {
"status": {
"type": "array",
"items": {
"enum": NOTIFICATION_STATUS_TYPES
"enum": NOTIFICATION_STATUS_TYPES + [NOTIFICATION_STATUS_LETTER_ACCEPTED]
}
},
"template_type": {