summaryrefslogtreecommitdiff
path: root/patchwork
diff options
context:
space:
mode:
authorJeremy Cline <jcline@redhat.com>2019-10-15 17:30:11 -0400
committerStephen Finucane <stephen@that.guru>2019-11-30 17:00:39 +0000
commite0f3220b3698fa3f9383b8c536a01f57cad8df15 (patch)
tree8e3d3c17047254213851d02801ebe2f59e91cccf /patchwork
parente53d7985a15a90617d653645d1bb0c2693b73ff6 (diff)
downloadpatchwork-e0f3220b3698fa3f9383b8c536a01f57cad8df15.tar
patchwork-e0f3220b3698fa3f9383b8c536a01f57cad8df15.tar.gz
Allow ordering events by date
By default, the events API orders events by date in descending order (newest first). However, it's useful to be able to order the events by oldest events first. For example, when a client is polling the events API for new events since a given date and wishes to process them in chronological order. Signed-off-by: Jeremy Cline <jcline@redhat.com> Reviewed-by: Stephen Finucane <stephen@that.guru>
Diffstat (limited to 'patchwork')
-rw-r--r--patchwork/api/event.py2
-rw-r--r--patchwork/tests/api/test_event.py18
2 files changed, 19 insertions, 1 deletions
diff --git a/patchwork/api/event.py b/patchwork/api/event.py
index c0d973d..e6d467d 100644
--- a/patchwork/api/event.py
+++ b/patchwork/api/event.py
@@ -77,7 +77,7 @@ class EventList(ListAPIView):
serializer_class = EventSerializer
filter_class = filterset_class = EventFilterSet
page_size_query_param = None # fixed page size
- ordering_fields = ()
+ ordering_fields = ('date',)
ordering = '-date'
def get_queryset(self):
diff --git a/patchwork/tests/api/test_event.py b/patchwork/tests/api/test_event.py
index 8816538..bff8f40 100644
--- a/patchwork/tests/api/test_event.py
+++ b/patchwork/tests/api/test_event.py
@@ -149,6 +149,24 @@ class TestEventAPI(utils.APITestCase):
resp = self.client.get(self.api_url(), {'series': 999999})
self.assertEqual(0, len(resp.data))
+ def test_order_by_date_default(self):
+ """Assert the default ordering is by date descending."""
+ self._create_events()
+
+ resp = self.client.get(self.api_url())
+ events = Event.objects.order_by("-date").all()
+ for api_event, event in zip(resp.data, events):
+ self.assertEqual(api_event["id"], event.id)
+
+ def test_order_by_date_ascending(self):
+ """Assert the default ordering is by date descending."""
+ self._create_events()
+
+ resp = self.client.get(self.api_url(), {'order': 'date'})
+ events = Event.objects.order_by("date").all()
+ for api_event, event in zip(resp.data, events):
+ self.assertEqual(api_event["id"], event.id)
+
def test_create(self):
"""Ensure creates aren't allowed"""
user = create_maintainer()