コード例 #1
0
ファイル: test_paginator.py プロジェクト: yaoqi/sentry
    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
コード例 #2
0
ファイル: test_paginator.py プロジェクト: yaoqi/sentry
    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()
コード例 #3
0
    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
コード例 #4
0
    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()
コード例 #5
0
ファイル: test_paginator.py プロジェクト: yzdann/sentry
    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)
コード例 #6
0
 def fetch_rule_groups_paginated(
     self,
     rule: Rule,
     start: datetime,
     end: datetime,
     cursor: Cursor | None = None,
     per_page: int = 25,
 ) -> CursorResult:
     qs = (RuleFireHistory.objects.filter(
         rule=rule,
         date_added__gte=start,
         date_added__lt=end,
     ).select_related("group").values("group").annotate(
         count=Count("id"), last_triggered=Max("date_added")))
     return OffsetPaginator(qs,
                            order_by=("-count", "-last_triggered"),
                            on_results=convert_results).get_result(
                                per_page, cursor)
コード例 #7
0
    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
コード例 #8
0
ファイル: test_paginator.py プロジェクト: alexandrul/sentry
    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