def test_order_by_multiple(self): res1 = self.create_user('*****@*****.**') self.create_user('*****@*****.**') res3 = self.create_user('*****@*****.**') queryset = User.objects.all() paginator = OffsetPaginator(queryset, 'id') result = paginator.get_result(limit=1, cursor=None) assert len(result) == 1, result assert result[0] == res1 assert result.next assert not result.prev res3.update(is_active=False) paginator = OffsetPaginator(queryset, ('is_active', 'id')) result = paginator.get_result(limit=1, cursor=None) assert len(result) == 1, result assert result[0] == res3 assert result.next assert not result.prev result = paginator.get_result(limit=1, cursor=result.next) assert len(result) == 1, (result, list(result)) assert result[0] == res1 assert result.next assert result.prev
def test_order_by_multiple(self): res1 = self.create_user('*****@*****.**') self.create_user('*****@*****.**') res3 = self.create_user('*****@*****.**') queryset = User.objects.all() paginator = OffsetPaginator(queryset, 'id') result = paginator.get_result(limit=1, cursor=None) assert len(result) == 1, result assert result[0] == res1 assert result.next assert not result.prev res3.update(is_active=False) paginator = OffsetPaginator(queryset, ('is_active', 'id')) result = paginator.get_result(limit=1, cursor=None) assert len(result) == 1, result assert result[0] == res3 assert result.next assert not result.prev result = paginator.get_result(limit=1, cursor=result.next) assert len(result) == 1, (result, list(result)) assert result[0] == res1 assert result.next assert result.prev
def test_negative_offset(self): self.create_user("*****@*****.**") queryset = User.objects.all() paginator = OffsetPaginator(queryset) cursor = Cursor(10, -1) with self.assertRaises(BadPaginationError): paginator.get_result(cursor=cursor) cursor = Cursor(-10, 1) with self.assertRaises(BadPaginationError): paginator.get_result(cursor=cursor)
def test_max_offset(self): self.create_user('*****@*****.**') self.create_user('*****@*****.**') self.create_user('*****@*****.**') queryset = User.objects.all() paginator = OffsetPaginator(queryset, max_offset=10) result1 = paginator.get_result(cursor=None) assert len(result1) == 3, result1 paginator = OffsetPaginator(queryset, max_offset=0) with self.assertRaises(BadPaginationError): paginator.get_result()
def test_max_offset(self): self.create_user('*****@*****.**') self.create_user('*****@*****.**') self.create_user('*****@*****.**') queryset = User.objects.all() paginator = OffsetPaginator(queryset, max_offset=10) result1 = paginator.get_result(cursor=None) assert len(result1) == 3, result1 paginator = OffsetPaginator(queryset, max_offset=0) with self.assertRaises(BadPaginationError): paginator.get_result()
def test_simple(self): res1 = self.create_user('*****@*****.**') res2 = self.create_user('*****@*****.**') res3 = self.create_user('*****@*****.**') queryset = User.objects.all() paginator = OffsetPaginator(queryset, 'id') result1 = paginator.get_result(limit=1, cursor=None) assert len(result1) == 1, result1 assert result1[0] == res1 assert result1.next assert not result1.prev result2 = paginator.get_result(limit=1, cursor=result1.next) assert len(result2) == 1, (result2, list(result2)) assert result2[0] == res2 assert result2.next assert result2.prev result3 = paginator.get_result(limit=1, cursor=result2.next) assert len(result3) == 1, result3 assert result3[0] == res3 assert not result3.next assert result3.prev result4 = paginator.get_result(limit=1, cursor=result3.next) assert len(result4) == 0, result4 assert not result4.next assert result4.prev result5 = paginator.get_result(limit=1, cursor=result4.prev) assert len(result5) == 1, result5 assert result5[0] == res3 assert not result5.next assert result5.prev
def test_simple(self): res1 = self.create_user('*****@*****.**') res2 = self.create_user('*****@*****.**') res3 = self.create_user('*****@*****.**') queryset = User.objects.all() paginator = OffsetPaginator(queryset, 'id') result1 = paginator.get_result(limit=1, cursor=None) assert len(result1) == 1, result1 assert result1[0] == res1 assert result1.next assert not result1.prev result2 = paginator.get_result(limit=1, cursor=result1.next) assert len(result2) == 1, (result2, list(result2)) assert result2[0] == res2 assert result2.next assert result2.prev result3 = paginator.get_result(limit=1, cursor=result2.next) assert len(result3) == 1, result3 assert result3[0] == res3 assert not result3.next assert result3.prev result4 = paginator.get_result(limit=1, cursor=result3.next) assert len(result4) == 0, result4 assert not result4.next assert result4.prev result5 = paginator.get_result(limit=1, cursor=result4.prev) assert len(result5) == 1, result5 assert result5[0] == res3 assert not result5.next assert result5.prev