@@ -972,24 +972,17 @@ class MockQuerySet:
972972 def __init__ (self , items ):
973973 self .items = items
974974
975- def filter (self , q ):
976- q_args = dict (q .deconstruct ()[1 ])
977- if not q_args :
978- # django 3.0.x artifact
979- q_args = dict (q .deconstruct ()[2 ])
980- created__gt = q_args .get ('created__gt' )
981- created__lt = q_args .get ('created__lt' )
982-
975+ def filter (self , created__gt = None , created__lt = None ):
983976 if created__gt is not None :
984977 return MockQuerySet ([
985978 item for item in self .items
986- if item .created is None or item . created > int (created__gt )
979+ if item .created > int (created__gt )
987980 ])
988981
989982 assert created__lt is not None
990983 return MockQuerySet ([
991984 item for item in self .items
992- if item .created is None or item . created < int (created__lt )
985+ if item .created < int (created__lt )
993986 ])
994987
995988 def order_by (self , * ordering ):
@@ -1108,127 +1101,6 @@ def get_pages(self, url):
11081101 return (previous , current , next , previous_url , next_url )
11091102
11101103
1111- class NullableCursorPaginationModel (models .Model ):
1112- created = models .IntegerField (null = True )
1113-
1114-
1115- class TestCursorPaginationWithNulls (TestCase ):
1116- """
1117- Unit tests for `pagination.CursorPagination` with ordering on a nullable field.
1118- """
1119-
1120- def setUp (self ):
1121- class ExamplePagination (pagination .CursorPagination ):
1122- page_size = 1
1123- ordering = 'created'
1124-
1125- self .pagination = ExamplePagination ()
1126- data = [
1127- None , None , 3 , 4
1128- ]
1129- for idx in data :
1130- NullableCursorPaginationModel .objects .create (created = idx )
1131-
1132- self .queryset = NullableCursorPaginationModel .objects .all ()
1133-
1134- get_pages = TestCursorPagination .get_pages
1135-
1136- def test_ascending (self ):
1137- """Test paginating one row at a time, current should go 1, 2, 3, 4, 3, 2, 1."""
1138- (previous , current , next , previous_url , next_url ) = self .get_pages ('/' )
1139-
1140- assert previous is None
1141- assert current == [None ]
1142- assert next == [None ]
1143-
1144- (previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
1145-
1146- assert previous == [None ]
1147- assert current == [None ]
1148- assert next == [3 ]
1149-
1150- (previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
1151-
1152- assert previous == [3 ] # [None] paging artifact documented at https://github.com/ddelange/django-rest-framework/blob/3.14.0/rest_framework/pagination.py#L789
1153- assert current == [3 ]
1154- assert next == [4 ]
1155-
1156- (previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
1157-
1158- assert previous == [3 ]
1159- assert current == [4 ]
1160- assert next is None
1161- assert next_url is None
1162-
1163- (previous , current , next , previous_url , next_url ) = self .get_pages (previous_url )
1164-
1165- assert previous == [None ]
1166- assert current == [3 ]
1167- assert next == [4 ]
1168-
1169- (previous , current , next , previous_url , next_url ) = self .get_pages (previous_url )
1170-
1171- assert previous == [None ]
1172- assert current == [None ]
1173- assert next == [None ] # [3] paging artifact documented at https://github.com/ddelange/django-rest-framework/blob/3.14.0/rest_framework/pagination.py#L731
1174-
1175- (previous , current , next , previous_url , next_url ) = self .get_pages (previous_url )
1176-
1177- assert previous is None
1178- assert current == [None ]
1179- assert next == [None ]
1180-
1181- def test_descending (self ):
1182- """Test paginating one row at a time, current should go 4, 3, 2, 1, 2, 3, 4."""
1183- self .pagination .ordering = ('-created' ,)
1184- (previous , current , next , previous_url , next_url ) = self .get_pages ('/' )
1185-
1186- assert previous is None
1187- assert current == [4 ]
1188- assert next == [3 ]
1189-
1190- (previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
1191-
1192- assert previous == [None ] # [4] paging artifact
1193- assert current == [3 ]
1194- assert next == [None ]
1195-
1196- (previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
1197-
1198- assert previous == [None ] # [3] paging artifact
1199- assert current == [None ]
1200- assert next == [None ]
1201-
1202- (previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
1203-
1204- assert previous == [None ]
1205- assert current == [None ]
1206- assert next is None
1207- assert next_url is None
1208-
1209- (previous , current , next , previous_url , next_url ) = self .get_pages (previous_url )
1210-
1211- assert previous == [3 ]
1212- assert current == [None ]
1213- assert next == [None ]
1214-
1215- (previous , current , next , previous_url , next_url ) = self .get_pages (previous_url )
1216-
1217- assert previous == [None ]
1218- assert current == [3 ]
1219- assert next == [3 ] # [4] paging artifact documented at https://github.com/ddelange/django-rest-framework/blob/3.14.0/rest_framework/pagination.py#L731
1220-
1221- # skip back artifact
1222- (previous , current , next , previous_url , next_url ) = self .get_pages (previous_url )
1223- (previous , current , next , previous_url , next_url ) = self .get_pages (previous_url )
1224-
1225- (previous , current , next , previous_url , next_url ) = self .get_pages (previous_url )
1226-
1227- assert previous is None
1228- assert current == [4 ]
1229- assert next == [3 ]
1230-
1231-
12321104def test_get_displayed_page_numbers ():
12331105 """
12341106 Test our contextual page display function.
0 commit comments