mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-06-13 01:43:39 -04:00
Fix sorting of events
Events should be sorted reverse-chronologically, no matter what order they come back from the API in, or which field in the API response they’ve been extracted from.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from collections import defaultdict
|
||||
from operator import attrgetter
|
||||
|
||||
from flask import render_template, request
|
||||
|
||||
@@ -36,7 +37,7 @@ def _chunk_events_by_day(events):
|
||||
|
||||
days = defaultdict(list)
|
||||
|
||||
for event in events:
|
||||
for event in sorted(events, key=attrgetter('time'), reverse=True):
|
||||
days[format_date_numeric(event.time)].append(event)
|
||||
|
||||
return sorted(days.items(), reverse=True)
|
||||
|
||||
@@ -9,8 +9,10 @@ from tests.conftest import SERVICE_ONE_ID, normalize_spaces
|
||||
(
|
||||
'12 December',
|
||||
(
|
||||
'Test User 1:13pm '
|
||||
'Renamed this service from ‘Before lunch’ to ‘After lunch’ '
|
||||
'Test User 12:12pm '
|
||||
'Renamed this service from ‘Example service’ to ‘Real service’'
|
||||
'Renamed this service from ‘Example service’ to ‘Before lunch’'
|
||||
),
|
||||
),
|
||||
(
|
||||
@@ -32,6 +34,8 @@ from tests.conftest import SERVICE_ONE_ID, normalize_spaces
|
||||
(
|
||||
'Test User 11:10am '
|
||||
'Created an API key called ‘Good key’ '
|
||||
'Test User 10:09am '
|
||||
'Created an API key called ‘Key event returned in non-chronological order’ '
|
||||
'Unknown 2:01am '
|
||||
'Created this service and called it ‘Example service’'
|
||||
),
|
||||
@@ -56,7 +60,9 @@ from tests.conftest import SERVICE_ONE_ID, normalize_spaces
|
||||
'10 October 2010',
|
||||
(
|
||||
'Test User 11:10am '
|
||||
'Created an API key called ‘Good key’'
|
||||
'Created an API key called ‘Good key’ '
|
||||
'Test User 10:09am '
|
||||
'Created an API key called ‘Key event returned in non-chronological order’'
|
||||
),
|
||||
),
|
||||
]),
|
||||
@@ -64,8 +70,10 @@ from tests.conftest import SERVICE_ONE_ID, normalize_spaces
|
||||
(
|
||||
'12 December',
|
||||
(
|
||||
'Test User 1:13pm '
|
||||
'Renamed this service from ‘Before lunch’ to ‘After lunch’ '
|
||||
'Test User 12:12pm '
|
||||
'Renamed this service from ‘Example service’ to ‘Real service’'
|
||||
'Renamed this service from ‘Example service’ to ‘Before lunch’'
|
||||
),
|
||||
),
|
||||
(
|
||||
|
||||
@@ -3514,11 +3514,17 @@ def mock_get_service_history(mocker):
|
||||
'created_by_id': uuid4(),
|
||||
},
|
||||
{
|
||||
'name': 'Real service',
|
||||
'name': 'Before lunch',
|
||||
'created_at': '2010-10-10T01:01:01.000000Z',
|
||||
'updated_at': '2012-12-12T12:12:12.000000Z',
|
||||
'created_by_id': sample_uuid(),
|
||||
},
|
||||
{
|
||||
'name': 'After lunch',
|
||||
'created_at': '2010-10-10T01:01:01.000000Z',
|
||||
'updated_at': '2012-12-12T13:13:13.000000Z',
|
||||
'created_by_id': sample_uuid(),
|
||||
},
|
||||
],
|
||||
'api_key_history': [
|
||||
{
|
||||
@@ -3539,6 +3545,12 @@ def mock_get_service_history(mocker):
|
||||
'created_at': '2011-11-11T11:11:11.000000Z',
|
||||
'created_by_id': sample_uuid(),
|
||||
},
|
||||
{
|
||||
'name': 'Key event returned in non-chronological order',
|
||||
'updated_at': None,
|
||||
'created_at': '2010-10-10T09:09:09.000000Z',
|
||||
'created_by_id': sample_uuid(),
|
||||
},
|
||||
],
|
||||
'events': [],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user