@@ -1110,12 +1110,12 @@ class ExamplePagination(pagination.CursorPagination):
1110
1110
get_pages = TestCursorPagination .get_pages
1111
1111
1112
1112
def test_ascending (self ):
1113
+ """Test paginating one row at a time, current should go 1, 2, 3, 4, 3, 2, 1."""
1113
1114
(previous , current , next , previous_url , next_url ) = self .get_pages ('/' )
1114
1115
1115
1116
assert previous is None
1116
1117
assert current == [None ]
1117
1118
assert next == [None ]
1118
- assert previous_url is None
1119
1119
1120
1120
(previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
1121
1121
@@ -1153,7 +1153,56 @@ def test_ascending(self):
1153
1153
assert previous is None
1154
1154
assert current == [None ]
1155
1155
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 ]
1157
1206
1158
1207
1159
1208
def test_get_displayed_page_numbers ():
0 commit comments