def test_should_get_a_group(): session = get_user_session() with cassette("fixtures/resources/groups/get_group/get_group.yaml"): group = session.groups.get("bcb12b97-db8a-3c1d-b696-d99ed4371175") assert group.id == "bcb12b97-db8a-3c1d-b696-d99ed4371175" assert group.name == "Python SDK Test Group" assert group.description == "Test group for the Mendeley Python SDK" assert group.disciplines == ["Computer and Information Science", "Humanities"] assert group.tags == ["python", "sdk"] assert group.webpage == "http://dev.mendeley.com" assert group.created == arrow.get(2014, 8, 27, 9, 40, 41) assert group.link == "http://www.mendeley.com/groups/4779311/python-sdk-test-group/" assert group.access_level == "public" assert group.role == "owner" assert ( group.photo.original == "http://s3.amazonaws.com/mendeley-photos/a0/20/a020f9fd30af0029c059c45535ad231d3d0d055a.png" ) assert ( group.photo.standard == "http://s3.amazonaws.com/mendeley-photos/a0/20/a020f9fd30af0029c059c45535ad231d3d0d055a-standard.jpg" ) assert ( group.photo.square == "http://s3.amazonaws.com/mendeley-photos/a0/20/a020f9fd30af0029c059c45535ad231d3d0d055a-square.jpg" ) assert group.owner.id == "9930207c-c19f-3de0-b531-86bd4388fa94" assert group.owner.display_name == "Jenny Johnson"
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_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_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_a_group(): session = get_user_session() with cassette('fixtures/resources/groups/get_group/get_group.yaml'): group = session.groups.get('bcb12b97-db8a-3c1d-b696-d99ed4371175') assert group.id == 'bcb12b97-db8a-3c1d-b696-d99ed4371175' assert group.name == 'Python SDK Test Group' assert group.description == 'Test group for the Mendeley Python SDK' assert group.disciplines == [ 'Computer and Information Science', 'Humanities' ] assert group.tags == ['python', 'sdk'] assert group.webpage == 'http://dev.mendeley.com' assert group.created == arrow.get(2014, 8, 27, 9, 40, 41) assert group.link == 'http://www.mendeley.com/groups/4779311/python-sdk-test-group/' assert group.access_level == 'public' assert group.role == 'owner' assert group.photo.original == \ 'http://s3.amazonaws.com/mendeley-photos/a0/20/a020f9fd30af0029c059c45535ad231d3d0d055a.png' assert group.photo.standard == \ 'http://s3.amazonaws.com/mendeley-photos/a0/20/a020f9fd30af0029c059c45535ad231d3d0d055a-standard.jpg' assert group.photo.square == \ 'http://s3.amazonaws.com/mendeley-photos/a0/20/a020f9fd30af0029c059c45535ad231d3d0d055a-square.jpg' assert group.owner.id == '9930207c-c19f-3de0-b531-86bd4388fa94' assert group.owner.display_name == 'Jenny Johnson'
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_page_through_group_documents(): session = get_user_session() delete_all_group_documents() with cassette('fixtures/resources/documents/list_group_documents/page_through_documents.yaml'): create_group_document(session, 'title 1') create_group_document(session, 'title 2') create_group_document(session, 'title 3') first_page = session.groups.get('164d48fb-2343-332d-b566-1a4884a992e4').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[0].group.name == 'Basket weaving' assert first_page.items[1].title == 'title 2' assert first_page.items[1].group.name == 'Basket weaving' 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' assert second_page.items[0].group.name == 'Basket weaving'
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_iterate_through_documents(): session = get_user_session() delete_all_group_documents() with cassette('fixtures/resources/trash/iter_group_trash/iterate_through_documents.yaml'): doc1 = create_group_document(session, 'title 1') doc1.move_to_trash() doc2 = create_group_document(session, 'title 2') doc2.move_to_trash() doc3 = create_group_document(session, 'title 3') doc3.move_to_trash() docs = list(islice(session.groups.get('164d48fb-2343-332d-b566-1a4884a992e4').trash.iter(page_size=2), 3)) assert len(docs) == 3 assert docs[0].title == 'title 1' assert docs[0].group.name == 'Basket weaving' assert docs[1].title == 'title 2' assert docs[1].group.name == 'Basket weaving' assert docs[2].title == 'title 3' assert docs[2].group.name == 'Basket weaving'
def test_should_iterate_through_documents(): session = get_user_session() delete_all_group_documents() with cassette( 'fixtures/resources/trash/iter_group_trash/iterate_through_documents.yaml' ): doc1 = create_group_document(session, 'title 1') doc1.move_to_trash() doc2 = create_group_document(session, 'title 2') doc2.move_to_trash() doc3 = create_group_document(session, 'title 3') doc3.move_to_trash() docs = list( islice( session.groups.get('164d48fb-2343-332d-b566-1a4884a992e4'). trash.iter(page_size=2), 3)) assert len(docs) == 3 assert docs[0].title == 'title 1' assert docs[0].group.name == 'Basket weaving' assert docs[1].title == 'title 2' assert docs[1].group.name == 'Basket weaving' assert docs[2].title == 'title 3' assert docs[2].group.name == 'Basket weaving'
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_get_a_profile(): session = get_user_session() with cassette('fixtures/resources/profiles/get_profile/get_profile.yaml'): profile = session.profiles.get('9930207c-c19f-3de0-b531-86bd4388fa94') assert profile.id == '9930207c-c19f-3de0-b531-86bd4388fa94' assert profile.first_name == 'Jenny' assert profile.last_name == 'Johnson' assert profile.display_name == 'Jenny Johnson' assert not profile.email assert profile.link == 'http://www.mendeley.com/profiles/jenny-johnson4/' assert not profile.research_interests assert profile.academic_status == 'Librarian' assert not profile.verified assert profile.user_type == 'normal' assert profile.created == arrow.get(2014, 8, 26, 15, 24, 45) assert profile.discipline.name == 'Humanities' assert not profile.discipline.subdisciplines assert not profile.photo.original assert profile.photo.standard == 'http://s3.amazonaws.com/mendeley-photos/awaiting.png' assert profile.photo.square == 'http://s3.amazonaws.com/mendeley-photos/awaiting_square.png' assert not profile.location assert not profile.education assert not profile.employment
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_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_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 delete_all_group_documents(): config = load_config() if config['recordMode'] != 'none': session = get_user_session() group = session.groups.get('164d48fb-2343-332d-b566-1a4884a992e4') __delete_all(group.documents) __delete_all(group.trash)
def test_should_be_able_to_get_owner_id_without_getting_profile(): session = get_user_session() with cassette("fixtures/resources/groups/get_group/get_owner_id_without_getting_profile.yaml") as cass: group = session.groups.get("bcb12b97-db8a-3c1d-b696-d99ed4371175") owner = group.owner assert owner.id == "9930207c-c19f-3de0-b531-86bd4388fa94" assert len(cass.requests) == 1
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_raise_if_group_not_found(): session = get_user_session() with cassette('fixtures/resources/groups/get_group/group_not_found.yaml'), \ pytest.raises(MendeleyApiException) as ex_info: session.groups.get('00000000-0000-0001-0000-000000000002') ex = ex_info.value assert ex.status == 404 assert ex.message == 'Group [00000000-0000-0001-0000-000000000002] does not exist'
def test_should_raise_if_profile_not_found(): session = get_user_session() with cassette('fixtures/resources/profiles/get_profile/profile_not_found.yaml'), \ pytest.raises(MendeleyApiException) as ex_info: session.profiles.get('00000000-0000-0001-0000-000000000002') ex = ex_info.value assert ex.status == 404 assert ex.message == 'profile not found'
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_only_get_owner_profile_once(): session = get_user_session() with cassette("fixtures/resources/groups/get_group/only_get_profile_once.yaml") as cass: group = session.groups.get("bcb12b97-db8a-3c1d-b696-d99ed4371175") owner = group.owner assert owner.first_name == "Jenny" assert owner.last_name == "Johnson" assert len(cass.requests) == 2
def test_should_raise_if_group_not_found(): session = get_user_session() with cassette("fixtures/resources/groups/get_group/group_not_found.yaml"), pytest.raises( MendeleyApiException ) as ex_info: session.groups.get("00000000-0000-0001-0000-000000000002") ex = ex_info.value assert ex.status == 404 assert ex.message == "Group [00000000-0000-0001-0000-000000000002] does not exist"
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_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_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_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_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_be_able_to_get_owner_id_without_getting_profile(): session = get_user_session() with cassette( 'fixtures/resources/groups/get_group/get_owner_id_without_getting_profile.yaml' ) as cass: group = session.groups.get('bcb12b97-db8a-3c1d-b696-d99ed4371175') owner = group.owner assert owner.id == '9930207c-c19f-3de0-b531-86bd4388fa94' assert len(cass.requests) == 1
def test_should_only_get_owner_profile_once(): session = get_user_session() with cassette( 'fixtures/resources/groups/get_group/only_get_profile_once.yaml' ) as cass: group = session.groups.get('bcb12b97-db8a-3c1d-b696-d99ed4371175') owner = group.owner assert owner.first_name == 'Jenny' assert owner.last_name == 'Johnson' assert len(cass.requests) == 2
def test_should_list_profiles_for_members(): session = get_user_session() with cassette('fixtures/resources/groups/list_group_members/list_profiles_for_members.yaml'): page = session.groups.get('bcb12b97-db8a-3c1d-b696-d99ed4371175').members.list() assert len(page.items) == 2 assert page.count == 2 assert page.items[0].display_name == 'Jimmy Jones, PhD' assert page.items[0].created == arrow.get(2014, 4, 9, 10, 10, 41) assert page.items[1].display_name == 'Jenny Johnson' assert page.items[1].created == arrow.get(2014, 8, 26, 15, 24, 45)
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_get_groups(): session = get_user_session() with cassette('fixtures/resources/groups/list_groups/list_groups.yaml'): page = session.groups.list() assert len(page.items) == 2 assert page.count == 2 assert page.items[0].id == '164d48fb-2343-332d-b566-1a4884a992e4' assert page.items[0].name == 'Basket weaving' assert page.items[0].description == 'All of the best papers about weaving baskets' assert page.items[0].disciplines == ['Arts and Literature'] assert page.items[0].tags == ['baskets', 'weaving'] assert page.items[0].webpage == 'http://example.com/baskets' assert page.items[0].created == arrow.get(2014, 5, 20, 11, 40, 22) assert page.items[0].link == 'http://www.mendeley.com/groups/4499471/basket-weaving/' assert page.items[0].access_level == 'public' assert page.items[0].role == 'member' assert page.items[0].photo.original == \ 'http://s3.amazonaws.com/mendeley-photos/73/e3/73e38a6a2cad3d760c04c1f7ef8a35ecf3f2d110.png' assert page.items[0].photo.standard == \ 'http://s3.amazonaws.com/mendeley-photos/73/e3/73e38a6a2cad3d760c04c1f7ef8a35ecf3f2d110-standard.jpg' assert page.items[0].photo.square == \ 'http://s3.amazonaws.com/mendeley-photos/73/e3/73e38a6a2cad3d760c04c1f7ef8a35ecf3f2d110-square.jpg' assert page.items[0].owner.id == '3e71f6e3-e2b4-3f20-a873-da62554c5c38' assert page.items[0].owner.display_name == 'Jimmy Jones, PhD' assert page.items[1].id == 'bcb12b97-db8a-3c1d-b696-d99ed4371175' assert page.items[1].name == 'Python SDK Test Group' assert page.items[1].description == 'Test group for the Mendeley Python SDK' assert page.items[1].disciplines == ['Computer and Information Science', 'Humanities'] assert page.items[1].tags == ['python', 'sdk'] assert page.items[1].webpage == 'http://dev.mendeley.com' assert page.items[1].created == arrow.get(2014, 8, 27, 9, 40, 41) assert page.items[1].link == 'http://www.mendeley.com/groups/4779311/python-sdk-test-group/' assert page.items[1].access_level == 'public' assert page.items[1].role == 'owner' assert page.items[1].photo.original == \ 'http://s3.amazonaws.com/mendeley-photos/a0/20/a020f9fd30af0029c059c45535ad231d3d0d055a.png' assert page.items[1].photo.standard == \ 'http://s3.amazonaws.com/mendeley-photos/a0/20/a020f9fd30af0029c059c45535ad231d3d0d055a-standard.jpg' assert page.items[1].photo.square == \ 'http://s3.amazonaws.com/mendeley-photos/a0/20/a020f9fd30af0029c059c45535ad231d3d0d055a-square.jpg' assert page.items[1].owner.id == '9930207c-c19f-3de0-b531-86bd4388fa94' assert page.items[1].owner.display_name == 'Jenny Johnson'
def test_should_list_a_groups_members(): session = get_user_session() with cassette('fixtures/resources/groups/list_group_members/list_group_members.yaml'): page = session.groups.get('bcb12b97-db8a-3c1d-b696-d99ed4371175').members.list() assert len(page.items) == 2 assert page.count == 2 assert page.items[0].id == '3e71f6e3-e2b4-3f20-a873-da62554c5c38' assert page.items[0].role == 'member' assert page.items[0].joined == arrow.get(2014, 8, 27, 9, 41, 23) assert page.items[1].id == '9930207c-c19f-3de0-b531-86bd4388fa94' assert page.items[1].role == 'owner' assert page.items[1].joined == arrow.get(2014, 8, 27, 9, 40, 41)
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_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_my_profile(): session = get_user_session() with cassette('fixtures/resources/profiles/get_my_profile/get_my_profile.yaml'): profile = session.profiles.me assert profile.id == '3e71f6e3-e2b4-3f20-a873-da62554c5c38' assert profile.first_name == 'Jimmy' assert profile.last_name == 'Jones' assert profile.display_name == 'Jimmy Jones, PhD' assert profile.email == '*****@*****.**' assert profile.link == 'http://www.mendeley.com/profiles/jimmy-jones5/' assert profile.research_interests == 'Underwater basket weaving' assert profile.academic_status == 'Post Doc' assert profile.verified assert profile.user_type == 'normal' assert profile.created == arrow.get(2014, 4, 9, 10, 10, 41) assert profile.discipline.name == 'Arts and Literature' assert profile.discipline.subdisciplines == ['Culture Heritage'] assert profile.photo.original == \ 'http://s3.amazonaws.com/mendeley-photos/ea/4c/ea4c185e63d3ced8a3c555b397c65869b716f13a.png' assert profile.photo.standard == \ 'http://s3.amazonaws.com/mendeley-photos/ea/4c/ea4c185e63d3ced8a3c555b397c65869b716f13a-standard.jpg' assert profile.photo.square == \ 'http://s3.amazonaws.com/mendeley-photos/ea/4c/ea4c185e63d3ced8a3c555b397c65869b716f13a-square.jpg' assert profile.location.latitude == 3.16 assert profile.location.longitude == 101.71 assert profile.location.name == 'Kuala Lumpur, Malaysia' assert len(profile.education) == 2 assert profile.education[0].institution == 'Universiti Kuala Lumpur' assert profile.education[0].degree == 'PhD' assert profile.education[0].start_date == arrow.get(2009, 9, 1) assert profile.education[0].end_date == arrow.get(2012, 8, 1) assert profile.education[0].website == 'http://www.unikl.edu.my/' assert len(profile.employment) == 2 assert profile.employment[1].institution == 'Universiti Kuala Lumpur' assert profile.employment[1].position == 'Professor of Submarine Bambrology' assert profile.employment[1].start_date == arrow.get(2012, 9, 1) assert profile.employment[1].end_date == arrow.get(2013, 12, 1) assert profile.employment[1].website == 'http://www.unikl.edu.my/' assert profile.employment[1].classes == ['Underwater Basket Weaving I', 'Underwater Basket Weaving II']
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"