def test_queryset_where_clauses(self): queryset = CursorQueryset(model=ExampleModel).all() cursor1 = queryset[:self.PAGE_SIZE].cursor() queryset1 = queryset.from_cursor(cursor1) cursor2 = queryset1[self.PAGE_SIZE:2 * self.PAGE_SIZE].cursor() queryset2 = queryset.from_cursor(cursor2) self.assertEqual( len(queryset1.query.where.children), len(queryset2.query.where.children), "Cursor generated querysets had different where clause lengths" )
def test_queryset_consistent_with_data_insert(self): """ Ensures that a cursor returned from a queryset stays fixed when new items are inserted. """ queryset = CursorQueryset(model=ExampleModel).order_by('count_field') cursor = queryset[:self.PAGE_SIZE].cursor() assert cursor.token expected = set([ x.pk for x in queryset[:self.PAGE_SIZE] ]) first = queryset[0] # Now add some instances that would change the indexing for i in range(10): ExampleModelFactory.create(count_field=first.count_field - 1) queryset2 = queryset.from_cursor(cursor) actual = set([x.pk for x in queryset2[:self.PAGE_SIZE]]) self.assertSetEqual(expected, actual)