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)
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]
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]
def test_query_reports_sort_date(query, expected_ids): prepare_reports() paginator = Paginator() response = query_reports(query, paginator, sort=REPORT_SORT_DATE_ID) assert expected_ids == [int(r.meta.id) for r in response] response = query_reports(query, paginator, sort=REPORT_SORT_DATE_ID, reversed=False) assert expected_ids == [int(r.meta.id) for r in response] # reversing expected_ids, notice ...reversed(response) response = query_reports(query, paginator, sort=REPORT_SORT_DATE_ID, reversed=True) assert expected_ids == [int(r.meta.id) for r in reversed(response)]
def test_query_reports_sort_published(query, expected_ids): prepare_reports() author4 = User.objects.create(**authors[3]) Report.objects.create(author=author4, **reports[5]) paginator = Paginator() response = query_reports(query, paginator, sort=REPORT_SORT_PUBLISHED_ID) assert expected_ids == [int(r.meta.id) for r in response] response = query_reports(query, paginator, sort=REPORT_SORT_PUBLISHED_ID, reversed=False) assert expected_ids == [int(r.meta.id) for r in response] # reversing expected_ids, notice ...reversed(response) response = query_reports(query, paginator, sort=REPORT_SORT_PUBLISHED_ID, reversed=True) assert expected_ids == [int(r.meta.id) for r in reversed(response)]
def test_paginator__get_edge_cursor(kw, num, cursor): paginator = Paginator(**kw) assert paginator.get_edge_cursor(num) == cursor
def test_reports_by_author__pagination(first, after, expected_ids): prepare_reports() author_id = 1 paginator = Paginator(first=first, after=after) response = reports_by_author(author_id, paginator) assert expected_ids == [int(r.meta.id) for r in response]
def test_paginator__input_combinations(kw, slice_from, slice_to): paginator = Paginator(**kw) assert paginator.slice_from == slice_from assert paginator.slice_to == slice_to
def test_search_reports__sort(query, sort, reversed, expected_ids): prepare_reports() paginator = Paginator() response = search_reports(paginator, query=query, sort=sort, reversed=reversed) assert expected_ids == [int(r.meta.id) for r in response]
def test_query_reports(query, expected_ids): prepare_reports() paginator = Paginator() response = query_reports(query, paginator) assert expected_ids == [int(r.meta.id) for r in response]
def test_search_reports__sort__default(): prepare_reports() paginator = Paginator() response = search_reports(paginator) assert [3, 2, 1] == [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]
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_paginator__defaults(): paginator = Paginator() assert paginator.slice_from == 0 assert paginator.slice_to == PER_PAGE
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_paginator__custom_per_page(): paginator = Paginator(per_page=5) assert paginator.per_page == 5 assert paginator.slice_from == 0 assert paginator.slice_to == 5
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]
def test_paginator__last_without_before(): with pytest.raises(MissingBeforeValueError): Paginator(last=1)
def test_search_reports__query(query, expected_ids): prepare_reports() paginator = Paginator() response = search_reports(paginator, query=query) assert expected_ids == [int(r.meta.id) for r in response]