mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 07:51:13 -05:00
code review feedback
This commit is contained in:
@@ -261,8 +261,6 @@ def _filter_query(query, filter_dict=None):
|
|||||||
statuses = multidict.getlist('status')
|
statuses = multidict.getlist('status')
|
||||||
|
|
||||||
if statuses:
|
if statuses:
|
||||||
if statuses == ['pending']:
|
|
||||||
statuses = ['sending']
|
|
||||||
query = query.filter(Notification.status.in_(statuses))
|
query = query.filter(Notification.status.in_(statuses))
|
||||||
|
|
||||||
# filter by template
|
# filter by template
|
||||||
|
|||||||
@@ -432,10 +432,10 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio
|
|||||||
create_notification(template=second_template, status='failed')
|
create_notification(template=second_template, status='failed')
|
||||||
|
|
||||||
# team API key notifications are included
|
# team API key notifications are included
|
||||||
create_notification(template=second_template, status='pending', key_type=KEY_TYPE_TEAM)
|
create_notification(template=second_template, status='sending', key_type=KEY_TYPE_TEAM)
|
||||||
|
|
||||||
# test notifications are ignored
|
# test notifications are ignored
|
||||||
create_notification(template=second_template, status='pending', key_type=KEY_TYPE_TEST)
|
create_notification(template=second_template, status='sending', key_type=KEY_TYPE_TEST)
|
||||||
|
|
||||||
# historical notifications are included
|
# historical notifications are included
|
||||||
create_notification_history(template=second_template, status='delivered')
|
create_notification_history(template=second_template, status='delivered')
|
||||||
@@ -479,7 +479,7 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio
|
|||||||
assert email_failure_row.service_id == second_service.id
|
assert email_failure_row.service_id == second_service.id
|
||||||
assert email_failure_row.job_id == UUID('00000000-0000-0000-0000-000000000000')
|
assert email_failure_row.job_id == UUID('00000000-0000-0000-0000-000000000000')
|
||||||
assert email_failure_row.notification_type == 'email'
|
assert email_failure_row.notification_type == 'email'
|
||||||
assert email_failure_row.notification_status == 'pending'
|
assert email_failure_row.notification_status == 'sending'
|
||||||
assert email_failure_row.notification_count == 1
|
assert email_failure_row.notification_count == 1
|
||||||
assert email_failure_row.key_type == KEY_TYPE_TEAM
|
assert email_failure_row.key_type == KEY_TYPE_TEAM
|
||||||
|
|
||||||
|
|||||||
@@ -347,25 +347,24 @@ def test_get_all_notifications_filter_by_template_type_invalid_template_type(cli
|
|||||||
|
|
||||||
|
|
||||||
def test_get_all_notifications_filter_by_single_status(client, sample_template):
|
def test_get_all_notifications_filter_by_single_status(client, sample_template):
|
||||||
# TODO had to change all the pendings to sendings. Is that correct?
|
notification = create_notification(template=sample_template, status="pending")
|
||||||
notification = create_notification(template=sample_template, status="sending")
|
|
||||||
create_notification(template=sample_template)
|
create_notification(template=sample_template)
|
||||||
|
|
||||||
auth_header = create_service_authorization_header(service_id=notification.service_id)
|
auth_header = create_service_authorization_header(service_id=notification.service_id)
|
||||||
response = client.get(
|
response = client.get(
|
||||||
path='/v2/notifications?status=sending',
|
path='/v2/notifications?status=pending',
|
||||||
headers=[('Content-Type', 'application/json'), auth_header])
|
headers=[('Content-Type', 'application/json'), auth_header])
|
||||||
|
|
||||||
json_response = json.loads(response.get_data(as_text=True))
|
json_response = json.loads(response.get_data(as_text=True))
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.headers['Content-type'] == "application/json"
|
assert response.headers['Content-type'] == "application/json"
|
||||||
assert json_response['links']['current'].endswith("/v2/notifications?status=sending")
|
assert json_response['links']['current'].endswith("/v2/notifications?status=pending")
|
||||||
assert 'next' in json_response['links'].keys()
|
assert 'next' in json_response['links'].keys()
|
||||||
assert len(json_response['notifications']) == 1
|
assert len(json_response['notifications']) == 1
|
||||||
|
|
||||||
assert json_response['notifications'][0]['id'] == str(notification.id)
|
assert json_response['notifications'][0]['id'] == str(notification.id)
|
||||||
assert json_response['notifications'][0]['status'] == "sending"
|
assert json_response['notifications'][0]['status'] == "pending"
|
||||||
|
|
||||||
|
|
||||||
def test_get_all_notifications_filter_by_status_invalid_status(client, sample_notification):
|
def test_get_all_notifications_filter_by_status_invalid_status(client, sample_notification):
|
||||||
@@ -414,11 +413,10 @@ def test_get_all_notifications_filter_by_multiple_statuses(client, sample_templa
|
|||||||
|
|
||||||
|
|
||||||
def test_get_all_notifications_filter_by_failed_status(client, sample_template):
|
def test_get_all_notifications_filter_by_failed_status(client, sample_template):
|
||||||
# TODO had to change temporary-failure, permanent-failure, technical-failure to failed
|
|
||||||
created_notification = create_notification(template=sample_template, status="created")
|
created_notification = create_notification(template=sample_template, status="created")
|
||||||
failed_notifications = [
|
failed_notifications = [
|
||||||
create_notification(template=sample_template, status=_status)
|
create_notification(template=sample_template, status=_status)
|
||||||
for _status in ["failed", "failed", "failed"]
|
for _status in ["failed"]
|
||||||
]
|
]
|
||||||
|
|
||||||
auth_header = create_service_authorization_header(service_id=created_notification.service_id)
|
auth_header = create_service_authorization_header(service_id=created_notification.service_id)
|
||||||
@@ -432,7 +430,7 @@ def test_get_all_notifications_filter_by_failed_status(client, sample_template):
|
|||||||
assert response.headers['Content-type'] == "application/json"
|
assert response.headers['Content-type'] == "application/json"
|
||||||
assert json_response['links']['current'].endswith("/v2/notifications?status=failed")
|
assert json_response['links']['current'].endswith("/v2/notifications?status=failed")
|
||||||
assert 'next' in json_response['links'].keys()
|
assert 'next' in json_response['links'].keys()
|
||||||
assert len(json_response['notifications']) == 3
|
assert len(json_response['notifications']) == 1
|
||||||
|
|
||||||
returned_notification_ids = [n['id'] for n in json_response['notifications']]
|
returned_notification_ids = [n['id'] for n in json_response['notifications']]
|
||||||
for _id in [_notification.id for _notification in failed_notifications]:
|
for _id in [_notification.id for _notification in failed_notifications]:
|
||||||
|
|||||||
Reference in New Issue
Block a user