コード例 #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)
コード例 #2
0
def test_encode_and_decode_cursor():
    assert decode_cursor(encode_cursor(42)) == 42
コード例 #3
0
def test_encode_cursor(num, cursor):
    assert encode_cursor(num) == cursor
コード例 #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),
コード例 #5
0
    assert expected_ids == [int(r.meta.id) for r in response]


def test_query_reports__highlight():
    prepare_reports()
    paginator = Paginator()
    query = 'King'
    response = query_reports(query, paginator, highlight=True)
    doc = response.hits[0]
    assert '<mark>King</mark>' in doc.meta.highlight.title[0]
    assert '<mark>King</mark>' in doc.meta.highlight.body[0]


@pytest.mark.parametrize('first, after, expected_ids', [
    (2, None, [3, 2]),
    (2, encode_cursor(1), [2, 1]),
])
def test_query_reports__pagination(first, after, expected_ids):
    prepare_reports()
    query = ''
    paginator = Paginator(first=first, after=after)
    response = query_reports(query, paginator)
    assert expected_ids == [int(r.meta.id) for r in response]


def test_reports_by_author():
    prepare_reports()
    author_id = 1
    paginator = Paginator()
    response = reports_by_author(author_id, paginator)
    assert [3, 1] == [int(r.meta.id) for r in response]
コード例 #6
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),
コード例 #7
0
    response = query_reports(query, paginator)
    assert expected_ids == [int(r.meta.id) for r in response]


def test_query_reports__highlight():
    prepare_reports()
    paginator = Paginator()
    query = "King"
    response = query_reports(query, paginator, highlight=True)
    doc = response.hits[0]
    assert "<mark>King</mark>" in doc.meta.highlight.title[0]
    assert "<mark>King</mark>" in doc.meta.highlight.body[0]


@pytest.mark.parametrize("first, after, expected_ids",
                         [(2, None, [3, 2]), (2, encode_cursor(1), [2, 1])])
def test_query_reports__pagination(first, after, expected_ids):
    prepare_reports()
    query = ""
    paginator = Paginator(first=first, after=after)
    response = query_reports(query, paginator)
    assert expected_ids == [int(r.meta.id) for r in response]


def test_reports_by_author():
    prepare_reports()
    author_id = 1
    paginator = Paginator()
    response = reports_by_author(author_id, paginator)
    assert [3, 1] == [int(r.meta.id) for r in response]
コード例 #8
0
    response = search_reports(paginator, query=query)
    assert expected_ids == [int(r.meta.id) for r in response]


def test_search_reports__highlight():
    prepare_reports()
    paginator = Paginator()
    query = "King"
    response = search_reports(paginator, query=query, highlight=True)
    doc = response.hits[0]
    assert "<mark>King</mark>" in doc.meta.highlight.title[0]
    assert "<mark>King</mark>" in doc.meta.highlight.body[0]


@pytest.mark.parametrize(
    "first, after, expected_ids", [(2, None, [3, 2]), (2, encode_cursor(1), [2, 1])]
)
def test_search_reports__pagination(first, after, expected_ids):
    prepare_reports()
    paginator = Paginator(first=first, after=after)
    response = search_reports(paginator)
    assert expected_ids == [int(r.meta.id) for r in response]


def test_search_reports__by_author():
    prepare_reports()
    author_id = 1
    paginator = Paginator()
    response = search_reports(paginator, author_id=author_id)
    assert [3, 1] == [int(r.meta.id) for r in response]