def test_pagination_after_service_restart(): mocker = api_mock([second_page, first_page]) paginator = Paginator(options=options, api_adaptor=mocker) paginator.next() #fetch second page items = unwrap(paginator.fetchPageItems()) #fetch first page items = unwrap(paginator.fetchPageItems()) #persist paginator.reset() #restart opertion => new paginator mocker = api_mock([third_page + second_page, first_page]) paginator = Paginator(options=options, api_adaptor=mocker) paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == third_page #only new items from page three should appear paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == None paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == None
def test_single_page(): paginator = Paginator(options=options, api_adaptor=api_mock(single_page)) paginator.next() assert unwrap(paginator.fetchPageItems()) == first_page paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == None
def test_no_new_items(): paginator = Paginator(options=options, api_adaptor=api_mock([first_page]), state=State(last_item_id='1')) paginator.next() assert unwrap(paginator.fetchPageItems()) == None paginator.next() assert unwrap(paginator.fetchPageItems()) == None
def test_negative_max_pages(): paginator = Paginator(options={ **options, **options_negative_max_page }, api_adaptor=api_mock(two_pages), state=State(last_item_id='5')) is_available = paginator.next() assert is_available == False
def test_one_item(): paginator = Paginator(options=options, api_adaptor=api_mock([first_page]), state=State(last_item_id='2')) paginator.next() assert unwrap(paginator.fetchPageItems()) == [{'id': '1'}] paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == None
def test_two_pages(): paginator = Paginator(options=options, api_adaptor=api_mock(two_pages)) paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == first_page paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == second_page paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == None
def test_4_items(): paginator = Paginator(options=options, api_adaptor=api_mock(two_pages), state=State(last_item_id='5')) paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == first_page paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == [{'id': '4'}] paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == None
def test_state_based_pagination(): state = State() assert state.last_item_id == '' mocker = api_mock([first_page]) paginator = Paginator(options=options, api_adaptor=mocker, state=state) paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == first_page mocker.setPages([second_page, first_page]) paginator.reset() paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == second_page paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == None mocker.setPages([fourth_page, third_page, second_page, first_page]) paginator.reset() paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == fourth_page paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == third_page paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == None mocker.setPages([fourth_page]) paginator.reset() paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == None
def test_max_pages(): paginator = Paginator(options={ **options, **options_two_page }, api_adaptor=api_mock(three_pages), state=State(last_item_id='100')) paginator.next() items = unwrap(paginator.fetchPageItems()) assert items == first_page is_available = paginator.next() assert is_available == True items = unwrap(paginator.fetchPageItems()) assert items == second_page is_available = paginator.next() assert is_available == False
def test_empty_page(): paginator = Paginator(options=options, api_adaptor=api_mock()) paginator.next() assert unwrap(paginator.fetchPageItems()) == None