from itertools import islice

from test import get_user_session, cassette
from test.resources.documents import delete_all_documents, create_document


def test_should_iterate_through_documents():
    session = get_user_session()
    delete_all_documents()

    with cassette('fixtures/resources/documents/iter_documents/iterate_through_documents.yaml'):
        create_document(session, 'title 1')
        create_document(session, 'title 2')
        create_document(session, 'title 3')

        docs = list(islice(session.documents.iter(page_size=2), 3))

        assert len(docs) == 3
        assert docs[0].title == 'title 1'
        assert docs[1].title == 'title 2'
        assert docs[2].title == 'title 3'

[((8, 14, 8, 32), 'test.get_user_session', 'get_user_session', ({}, {}), '()', False, 'from test import get_user_session, cassette\n'), ((9, 4, 9, 26), 'test.resources.documents.delete_all_documents', 'delete_all_documents', ({}, {}), '()', False, 'from test.resources.documents import delete_all_documents, create_document\n'), ((11, 9, 11, 95), 'test.cassette', 'cassette', ({(11, 18, 11, 94): '"""fixtures/resources/documents/iter_documents/iterate_through_documents.yaml"""'}, {}), "(\n    'fixtures/resources/documents/iter_documents/iterate_through_documents.yaml'\n    )", False, 'from test import get_user_session, cassette\n'), ((12, 8, 12, 43), 'test.resources.documents.create_document', 'create_document', ({(12, 24, 12, 31): 'session', (12, 33, 12, 42): '"""title 1"""'}, {}), "(session, 'title 1')", False, 'from test.resources.documents import delete_all_documents, create_document\n'), ((13, 8, 13, 43), 'test.resources.documents.create_document', 'create_document', ({(13, 24, 13, 31): 'session', (13, 33, 13, 42): '"""title 2"""'}, {}), "(session, 'title 2')", False, 'from test.resources.documents import delete_all_documents, create_document\n'), ((14, 8, 14, 43), 'test.resources.documents.create_document', 'create_document', ({(14, 24, 14, 31): 'session', (14, 33, 14, 42): '"""title 3"""'}, {}), "(session, 'title 3')", False, 'from test.resources.documents import delete_all_documents, create_document\n')]