def test_should_list_annotations(): session = get_user_session() delete_all_documents() with cassette( 'fixtures/resources/annotations/list_annotations/list_annotations.yaml' ): doc = create_document(session) doc.add_note("A nice annotation") page = session.annotations.list() assert len(page.items) == 1 assert page.count == 1 annotation = page.items[0] assert annotation.text == "A nice annotation" assert annotation.privacy_level == 'private' assert annotation.type == 'note' assert annotation.last_modified assert annotation.profile.id assert annotation.profile.display_name assert annotation.document().id == doc.id assert annotation.document().title == doc.title
def test_should_page_through_documents(): session = get_user_session() delete_all_documents() with cassette( 'fixtures/resources/trash/list_trash/page_through_documents.yaml'): doc1 = create_document(session, 'title 1') doc1.move_to_trash() doc2 = create_document(session, 'title 2') doc2.move_to_trash() doc3 = create_document(session, 'title 3') doc3.move_to_trash() first_page = session.trash.list(page_size=2) assert len(first_page.items) == 2 assert first_page.count == 3 assert first_page.items[0].title == 'title 1' assert first_page.items[1].title == 'title 2' second_page = first_page.next_page assert len(second_page.items) == 1 assert second_page.count == 3 assert second_page.items[0].title == 'title 3'
def test_should_page_through_annotations(): session = get_user_session() delete_all_documents() with cassette( 'fixtures/resources/annotations/list_annotations/page_through_annotations.yaml' ): doc = create_document(session) file = doc.attach_file('fixtures/resources/files/basket.txt') file.add_sticky_note("annotation 1", 100, 200, 1) file.add_sticky_note("annotation 2", 100, 200, 1) file.add_sticky_note("annotation 3", 100, 200, 1) first_page = session.annotations.list(page_size=2) assert len(first_page.items) == 2 assert first_page.count == 3 assert first_page.items[0].text == 'annotation 2' assert first_page.items[1].text == 'annotation 1' second_page = first_page.next_page assert len(second_page.items) == 1 assert second_page.count == 3 assert second_page.items[0].text == 'annotation 3'
def test_should_iterate_through_annotations(): session = get_user_session() delete_all_documents() with cassette( 'fixtures/resources/annotations/iter_annotations/iterate_through_annotations.yaml' ): doc = create_document(session) file = doc.attach_file('fixtures/resources/files/basket.txt') top_left = Position.create(100, 200) bottom_right = Position.create(400, 500) bounding_box = BoundingBox.create(top_left, bottom_right, 1) color = Color.create(255, 125, 240) file.add_sticky_note("annotation 1", 100, 200, 1) doc.add_note("annotation 2") file.add_sticky_note("annotation 3", 100, 200, 1) file.add_highlight([bounding_box], color) annotations = list(session.annotations.iter(page_size=2)) assert len(annotations) == 4 assert not annotations[0].text assert annotations[1].text == 'annotation 3' assert annotations[2].text == 'annotation 1' assert annotations[3].text == 'annotation 2'
def test_should_iterate_through_annotations(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/annotations/iter_annotations/iterate_through_annotations.yaml'): doc = create_document(session) file = doc.attach_file('fixtures/resources/files/basket.txt') top_left = Position.create(100, 200) bottom_right = Position.create(400, 500) bounding_box = BoundingBox.create(top_left, bottom_right, 1) color = Color.create(255, 125, 240) file.add_sticky_note("annotation 1", 100, 200, 1) doc.add_note("annotation 2") file.add_sticky_note("annotation 3", 100, 200, 1) file.add_highlight([bounding_box], color) annotations = list(session.annotations.iter(page_size=2)) assert len(annotations) == 4 assert not annotations[0].text assert annotations[1].text == 'annotation 3' assert annotations[2].text == 'annotation 1' assert annotations[3].text == 'annotation 2'
def test_should_add_highlight(): session = get_user_session() delete_all_documents() with cassette( 'fixtures/resources/annotations/add_annotation/add_highlight.yaml' ): doc = create_document(session) file = doc.attach_file('fixtures/resources/files/basket.txt') top_left = Position.create(100, 200) bottom_right = Position.create(400, 500) bounding_box = BoundingBox.create(top_left, bottom_right, 1) color = Color.create(255, 125, 240) annotation = file.add_highlight([bounding_box], color) assert not annotation.text assert annotation.privacy_level == 'private' assert annotation.type == 'highlight' assert annotation.last_modified assert annotation.profile.id assert annotation.profile.display_name assert annotation.document().id == doc.id assert annotation.document().title == doc.title assert annotation.positions[0].top_left.x == 100 assert annotation.positions[0].top_left.y == 200 assert annotation.positions[0].bottom_right.x == 400 assert annotation.positions[0].bottom_right.y == 500 assert annotation.positions[0].page == 1 assert annotation.color.r == 255 assert annotation.color.g == 125 assert annotation.color.b == 240
def test_should_add_sticky_note(): session = get_user_session() delete_all_documents() with cassette( 'fixtures/resources/annotations/add_annotation/add_sticky_note.yaml' ): doc = create_document(session) file = doc.attach_file('fixtures/resources/files/basket.txt') annotation = file.add_sticky_note("A nice sticky note", 100, 200, 1) assert annotation.text == "A nice sticky note" assert annotation.privacy_level == 'private' assert annotation.type == 'sticky_note' assert annotation.last_modified assert annotation.profile.id assert annotation.profile.display_name assert annotation.document().id == doc.id assert annotation.document().title == doc.title assert annotation.positions[0].top_left.x == 100 assert annotation.positions[0].top_left.y == 200 assert annotation.positions[0].bottom_right.x == 100 assert annotation.positions[0].bottom_right.y == 200 assert annotation.positions[0].page == 1
def test_should_update_highlight(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/annotations/update_annotations/update_highlight.yaml'): doc = create_document(session) file = doc.attach_file('fixtures/resources/files/basket.txt') top_left = Position.create(400, 300) bottom_right = Position.create(400, 300) bounding_box = BoundingBox.create(top_left, bottom_right, 2) color = Color.create(255, 125, 240) updated_color = Color.create(123, 456, 222) annotation = file.add_highlight([bounding_box], color) patched_annotation = annotation.update(text="New text", positions=[bounding_box], color=updated_color) assert patched_annotation.text == "New text" assert patched_annotation.positions[0].top_left.x == 400 assert patched_annotation.positions[0].top_left.y == 300 assert patched_annotation.positions[0].bottom_right.x == 400 assert patched_annotation.positions[0].bottom_right.y == 300 assert patched_annotation.positions[0].page == 2 assert patched_annotation.color.r == 123 assert patched_annotation.color.g == 456 assert patched_annotation.color.b == 222 assert annotation.id == patched_annotation.id
def test_should_add_highlight(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/annotations/add_annotation/add_highlight.yaml'): doc = create_document(session) file = doc.attach_file('fixtures/resources/files/basket.txt') top_left = Position.create(100, 200) bottom_right = Position.create(400, 500) bounding_box = BoundingBox.create(top_left, bottom_right, 1) color = Color.create(255, 125, 240) annotation = file.add_highlight([bounding_box], color) assert not annotation.text assert annotation.privacy_level == 'private' assert annotation.type == 'highlight' assert annotation.last_modified assert annotation.profile.id assert annotation.profile.display_name assert annotation.document().id == doc.id assert annotation.document().title == doc.title assert annotation.positions[0].top_left.x == 100 assert annotation.positions[0].top_left.y == 200 assert annotation.positions[0].bottom_right.x == 400 assert annotation.positions[0].bottom_right.y == 500 assert annotation.positions[0].page == 1 assert annotation.color.r == 255 assert annotation.color.g == 125 assert annotation.color.b == 240
def test_should_page_through_documents(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/trash/list_trash/page_through_documents.yaml'): doc1 = create_document(session, 'title 1') doc1.move_to_trash() doc2 = create_document(session, 'title 2') doc2.move_to_trash() doc3 = create_document(session, 'title 3') doc3.move_to_trash() first_page = session.trash.list(page_size=2) assert len(first_page.items) == 2 assert first_page.count == 3 assert first_page.items[0].title == 'title 1' assert first_page.items[1].title == 'title 2' second_page = first_page.next_page assert len(second_page.items) == 1 assert second_page.count == 3 assert second_page.items[0].title == 'title 3'
def test_should_get_document_all_view(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/trash/get_document/get_document_all_view.yaml'): created_doc = create_document(session) created_doc.move_to_trash() doc = session.trash.get(created_doc.id, view='all') assert_all_document(doc)
def test_should_delete_document(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/documents/delete_document/delete_document.yaml'): doc = create_document(session) doc.delete() page = session.documents.list() assert not page.items
def test_should_delete_document(): session = get_user_session() delete_all_documents() with cassette("fixtures/resources/trash/delete_document/delete_document.yaml"): doc = create_document(session) trashed_doc = doc.move_to_trash() trashed_doc.delete() page = session.trash.list() assert not page.items
def test_should_be_able_to_get_profile_for_document(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/trash/get_document/get_profile_for_document.yaml'): created_doc = create_document(session) created_doc.move_to_trash() doc = session.trash.get(created_doc.id) profile = session.profiles.me assert doc.profile.display_name == profile.display_name
def test_should_delete_document(): session = get_user_session() delete_all_documents() with cassette( 'fixtures/resources/documents/delete_document/delete_document.yaml' ): doc = create_document(session) doc.delete() page = session.documents.list() assert not page.items
def test_should_delete_document(): session = get_user_session() delete_all_documents() with cassette( 'fixtures/resources/trash/delete_document/delete_document.yaml'): doc = create_document(session) trashed_doc = doc.move_to_trash() trashed_doc.delete() page = session.trash.list() assert not page.items
def test_should_list_documents(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/documents/list_documents/list_documents.yaml'): create_document(session) page = session.documents.list() assert len(page.items) == 1 assert page.count == 1 assert_core_document(page.items[0])
def test_should_update_text_of_a_note(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/annotations/update_annotations/update_note.yaml'): doc = create_document(session) annotation = doc.add_note("Initial annotation") patched_annotation = annotation.update(text="New text") assert patched_annotation.text == "New text" assert annotation.id == patched_annotation.id
def test_should_delete_annotation(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/annotations/delete_annotation/delete_annotation.yaml'): doc = create_document(session) annotation = doc.add_note("A nice annotation") annotation.delete() page = session.annotations.list() assert not page.items
def test_should_delete_annotation(): session = get_user_session() delete_all_documents() with cassette( 'fixtures/resources/annotations/delete_annotation/delete_annotation.yaml' ): doc = create_document(session) annotation = doc.add_note("A nice annotation") annotation.delete() page = session.annotations.list() assert not page.items
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'
def test_should_sort_documents_desc(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/documents/list_documents/sort_documents_desc.yaml'): create_document(session, 'B title 1') create_document(session, 'A title 2') create_document(session, 'C title 3') page = session.documents.list(sort='title', order='desc') assert len(page.items) == 3 assert page.count == 3 assert page.items[0].title == 'C title 3' assert page.items[1].title == 'B title 1' assert page.items[2].title == 'A title 2'
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'
def test_should_add_note(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/annotations/add_annotation/add_note.yaml'): doc = create_document(session) annotation = doc.add_note("A nice annotation") assert annotation.text == "A nice annotation" assert annotation.privacy_level == 'private' assert annotation.type == 'note' assert annotation.last_modified assert annotation.profile.id assert annotation.profile.display_name assert annotation.document().id == doc.id assert annotation.document().title == doc.title
def test_should_list_documents_modified_since(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/documents/list_documents/modified_since.yaml'): doc1 = create_document(session, 'title 1') sleep(2) create_document(session, 'title 2') create_document(session, 'title 3') page = session.documents.list(modified_since=doc1.created.replace(seconds=+1)) assert len(page.items) == 2 assert page.count == 2 assert page.items[0].title == 'title 2' assert page.items[1].title == 'title 3'
def test_should_get_note(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/annotations/get_annotation/get_note.yaml'): doc = create_document(session) annotation = doc.add_note("Initial annotation") returned_annotation = session.annotations.get(annotation.id) assert returned_annotation.id == annotation.id assert returned_annotation.privacy_level == 'private' assert returned_annotation.type == 'note' assert returned_annotation.last_modified assert returned_annotation.profile.id assert returned_annotation.profile.display_name assert returned_annotation.document().id == doc.id assert returned_annotation.document().title == doc.title
def test_should_add_note(): session = get_user_session() delete_all_documents() with cassette( 'fixtures/resources/annotations/add_annotation/add_note.yaml'): doc = create_document(session) annotation = doc.add_note("A nice annotation") assert annotation.text == "A nice annotation" assert annotation.privacy_level == 'private' assert annotation.type == 'note' assert annotation.last_modified assert annotation.profile.id assert annotation.profile.display_name assert annotation.document().id == doc.id assert annotation.document().title == doc.title
def test_should_get_note(): session = get_user_session() delete_all_documents() with cassette( 'fixtures/resources/annotations/get_annotation/get_note.yaml'): doc = create_document(session) annotation = doc.add_note("Initial annotation") returned_annotation = session.annotations.get(annotation.id) assert returned_annotation.id == annotation.id assert returned_annotation.privacy_level == 'private' assert returned_annotation.type == 'note' assert returned_annotation.last_modified assert returned_annotation.profile.id assert returned_annotation.profile.display_name assert returned_annotation.document().id == doc.id assert returned_annotation.document().title == doc.title
def test_should_iterate_through_documents(): session = get_user_session() delete_all_documents() with cassette("fixtures/resources/trash/iter_trash/iterate_through_documents.yaml"): doc1 = create_document(session, "title 1") doc1.move_to_trash() doc2 = create_document(session, "title 2") doc2.move_to_trash() doc3 = create_document(session, "title 3") doc3.move_to_trash() docs = list(islice(session.trash.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"
def test_should_list_annotations_modified_since(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/annotations/list_annotations/modified_since.yaml'): doc = create_document(session, 'title 1') file = doc.attach_file('fixtures/resources/files/basket.txt') annotation = file.add_sticky_note("annotation 1", 100, 200, 1) sleep(2) file.add_sticky_note("annotation 2", 100, 200, 1) file.add_sticky_note("annotation 3", 100, 200, 1) page = session.annotations.list(modified_since=annotation.created.replace(seconds=+1)) assert len(page.items) == 2 assert page.count == 2 assert page.items[0].text == 'annotation 2' assert page.items[1].text == 'annotation 3'
def test_should_update_sticky_note(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/annotations/update_annotations/update_sticky_note.yaml'): doc = create_document(session) file = doc.attach_file('fixtures/resources/files/basket.txt') annotation = file.add_sticky_note("Initial annotation", 100, 200, 1) top_left = Position.create(400, 300) bottom_right = Position.create(400, 300) bounding_box = BoundingBox.create(top_left, bottom_right, 2) patched_annotation = annotation.update(text="New text", positions=[bounding_box]) assert patched_annotation.text == "New text" assert patched_annotation.positions[0].top_left.x == 400 assert patched_annotation.positions[0].top_left.y == 300 assert patched_annotation.positions[0].bottom_right.x == 400 assert patched_annotation.positions[0].bottom_right.y == 300 assert patched_annotation.positions[0].page == 2 assert annotation.id == patched_annotation.id
def test_should_list_documents_deleted_since(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/documents/list_documents/deleted_since.yaml'): doc1 = create_document(session, 'title 1') doc2 = create_document(session, 'title 2') doc3 = create_document(session, 'title 3') doc1.delete() sleep(2) doc2.delete() doc3.delete() page = session.documents.list(deleted_since=doc3.created.replace(seconds=+1)) assert len(page.items) == 2 assert page.count == 2 assert page.items[0].id == doc2.id assert page.items[1].id == doc3.id
def test_should_page_through_documents(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/documents/list_documents/page_through_documents.yaml'): create_document(session, 'title 1') create_document(session, 'title 2') create_document(session, 'title 3') first_page = session.documents.list(page_size=2) assert len(first_page.items) == 2 assert first_page.count == 3 assert first_page.items[0].title == 'title 1' assert first_page.items[1].title == 'title 2' second_page = first_page.next_page assert len(second_page.items) == 1 assert second_page.count == 3 assert second_page.items[0].title == 'title 3'
def test_should_iterate_through_documents(): session = get_user_session() delete_all_documents() with cassette( 'fixtures/resources/trash/iter_trash/iterate_through_documents.yaml' ): doc1 = create_document(session, 'title 1') doc1.move_to_trash() doc2 = create_document(session, 'title 2') doc2.move_to_trash() doc3 = create_document(session, 'title 3') doc3.move_to_trash() docs = list(islice(session.trash.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'
def test_should_list_annotations(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/annotations/list_annotations/list_annotations.yaml'): doc = create_document(session) doc.add_note("A nice annotation") page = session.annotations.list() assert len(page.items) == 1 assert page.count == 1 annotation = page.items[0] assert annotation.text == "A nice annotation" assert annotation.privacy_level == 'private' assert annotation.type == 'note' assert annotation.last_modified assert annotation.profile.id assert annotation.profile.display_name assert annotation.document().id == doc.id assert annotation.document().title == doc.title
def test_should_list_annotations_modified_since(): session = get_user_session() delete_all_documents() with cassette( 'fixtures/resources/annotations/list_annotations/modified_since.yaml' ): doc = create_document(session, 'title 1') file = doc.attach_file('fixtures/resources/files/basket.txt') annotation = file.add_sticky_note("annotation 1", 100, 200, 1) sleep(2) file.add_sticky_note("annotation 2", 100, 200, 1) file.add_sticky_note("annotation 3", 100, 200, 1) page = session.annotations.list( modified_since=annotation.created.replace(seconds=+1)) assert len(page.items) == 2 assert page.count == 2 assert page.items[0].text == 'annotation 2' assert page.items[1].text == 'annotation 3'
def test_should_add_sticky_note(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/annotations/add_annotation/add_sticky_note.yaml'): doc = create_document(session) file = doc.attach_file('fixtures/resources/files/basket.txt') annotation = file.add_sticky_note("A nice sticky note", 100, 200, 1) assert annotation.text == "A nice sticky note" assert annotation.privacy_level == 'private' assert annotation.type == 'sticky_note' assert annotation.last_modified assert annotation.profile.id assert annotation.profile.display_name assert annotation.document().id == doc.id assert annotation.document().title == doc.title assert annotation.positions[0].top_left.x == 100 assert annotation.positions[0].top_left.y == 200 assert annotation.positions[0].bottom_right.x == 100 assert annotation.positions[0].bottom_right.y == 200 assert annotation.positions[0].page == 1
def test_should_page_through_annotations(): session = get_user_session() delete_all_documents() with cassette('fixtures/resources/annotations/list_annotations/page_through_annotations.yaml'): doc = create_document(session) file = doc.attach_file('fixtures/resources/files/basket.txt') file.add_sticky_note("annotation 1", 100, 200, 1) file.add_sticky_note("annotation 2", 100, 200, 1) file.add_sticky_note("annotation 3", 100, 200, 1) first_page = session.annotations.list(page_size=2) assert len(first_page.items) == 2 assert first_page.count == 3 assert first_page.items[0].text == 'annotation 2' assert first_page.items[1].text == 'annotation 1' second_page = first_page.next_page assert len(second_page.items) == 1 assert second_page.count == 3 assert second_page.items[0].text == 'annotation 3'