Exemplo n.º 1
0
def test_paginator__get_page_info(kw, total, previous, next, start, end):
    paginator = Paginator(**kw)
    page_info = paginator.get_page_info(total)
    assert page_info.has_previous_page is previous
    assert page_info.has_next_page is next
    assert page_info.start_cursor == start if start is None else encode_cursor(
        start)
    assert page_info.end_cursor == end if end is None else encode_cursor(end)
Exemplo n.º 2
0
def test_encode_and_decode_cursor():
    assert decode_cursor(encode_cursor(42)) == 42
Exemplo n.º 3
0
def test_encode_cursor(num, cursor):
    assert encode_cursor(num) == cursor
Exemplo n.º 4
0
def test_paginator__custom_per_page():
    paginator = Paginator(per_page=5)
    assert paginator.per_page == 5
    assert paginator.slice_from == 0
    assert paginator.slice_to == 5


@pytest.mark.parametrize(
    "kw, slice_from, slice_to",
    [
        ({
            "first": 15
        }, 0, 15),
        ({
            "first": 5,
            "after": encode_cursor(3)
        }, 3, 8),
        ({
            "last": 8,
            "before": encode_cursor(20)
        }, 11, 19),
        # overflow of slice_from
        ({
            "last": 100,
            "before": encode_cursor(42)
        }, 0, 41),
        # preffer first before last if both provided
        ({
            "first": 20,
            "last": 4
        }, 0, 20),