Skip to content

Commit b089edc

Browse files
committed
Push tests for nulls
1 parent a1866b3 commit b089edc

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

tests/test_pagination.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,12 +1110,12 @@ class ExamplePagination(pagination.CursorPagination):
11101110
get_pages = TestCursorPagination.get_pages
11111111

11121112
def test_ascending(self):
1113+
"""Test paginating one row at a time, current should go 1, 2, 3, 4, 3, 2, 1."""
11131114
(previous, current, next, previous_url, next_url) = self.get_pages('/')
11141115

11151116
assert previous is None
11161117
assert current == [None]
11171118
assert next == [None]
1118-
assert previous_url is None
11191119

11201120
(previous, current, next, previous_url, next_url) = self.get_pages(next_url)
11211121

@@ -1153,7 +1153,56 @@ def test_ascending(self):
11531153
assert previous is None
11541154
assert current == [None]
11551155
assert next == [None]
1156-
assert previous_url is None
1156+
1157+
def test_decending(self):
1158+
"""Test paginating one row at a time, current should go 4, 3, 2, 1, 2, 3, 4."""
1159+
self.pagination.ordering = ('-created',)
1160+
(previous, current, next, previous_url, next_url) = self.get_pages('/')
1161+
1162+
assert previous is None
1163+
assert current == [4]
1164+
assert next == [3]
1165+
1166+
(previous, current, next, previous_url, next_url) = self.get_pages(next_url)
1167+
1168+
assert previous == [None] # [4] paging artifact
1169+
assert current == [3]
1170+
assert next == [None]
1171+
1172+
(previous, current, next, previous_url, next_url) = self.get_pages(next_url)
1173+
1174+
assert previous == [None] # [3] paging artifact
1175+
assert current == [None]
1176+
assert next == [None]
1177+
1178+
(previous, current, next, previous_url, next_url) = self.get_pages(next_url)
1179+
1180+
assert previous == [None]
1181+
assert current == [None]
1182+
assert next is None
1183+
assert next_url is None
1184+
1185+
(previous, current, next, previous_url, next_url) = self.get_pages(previous_url)
1186+
1187+
assert previous == [3]
1188+
assert current == [None]
1189+
assert next == [None]
1190+
1191+
(previous, current, next, previous_url, next_url) = self.get_pages(previous_url)
1192+
1193+
assert previous == [None]
1194+
assert current == [3]
1195+
assert next == [3] # [4] paging artifact documented at https://github.com/ddelange/django-rest-framework/blob/3.14.0/rest_framework/pagination.py#L731
1196+
1197+
# skip back artifact
1198+
(previous, current, next, previous_url, next_url) = self.get_pages(previous_url)
1199+
(previous, current, next, previous_url, next_url) = self.get_pages(previous_url)
1200+
1201+
(previous, current, next, previous_url, next_url) = self.get_pages(previous_url)
1202+
1203+
assert previous is None
1204+
assert current == [4]
1205+
assert next == [3]
11571206

11581207

11591208
def test_get_displayed_page_numbers():

0 commit comments

Comments
 (0)