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_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_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_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