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

    with cassette(
            'fixtures/resources/documents/list_search/page_through_search_results.yaml'
    ):
        session.documents.create('Underwater basket weaving', 'journal')
        session.documents.create('Underwater bucket weaving', 'journal')
        session.documents.create('Overground basket weaving', 'journal')
        session.documents.create('Underwater basket knitting', 'journal')

        sleep(3)

        first_page = session.documents.search('basket').list(page_size=2)

        assert len(first_page.items) == 2
        assert first_page.count == 3

        second_page = first_page.next_page
        assert len(second_page.items) == 1
        assert second_page.count == 3

        titles = set(
            [doc.title for doc in first_page.items + second_page.items])
        assert titles == {
            'Underwater basket weaving', 'Overground basket weaving',
            'Underwater basket knitting'
        }
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_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_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_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_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_throw_exception_on_incorrect_credentials():
    mendeley = configure_mendeley()
    mendeley.client_secret += '-invalid'
    auth = mendeley.start_client_credentials_flow()

    with cassette('fixtures/auth/client_credentials/incorrect_credentials.yaml'), pytest.raises(InvalidClientError):
        auth.authenticate()
Ejemplo n.º 8
0
def test_should_get_core_view():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/get_catalog_by_id/get_core_view.yaml'):
        doc = session.catalog.get('5cd8328e-febe-3299-8e26-cf6ab2c07f0f')

        assert_core_view(doc)
Ejemplo n.º 9
0
def test_should_page_through_search_results():
    session = get_client_credentials_session()

    with cassette(
            'fixtures/resources/catalog/list_advanced_search/page_through_search_results.yaml'
    ):
        search = session.catalog.advanced_search(title='mapreduce',
                                                 author='Jeffrey Dean')
        first_page = search.list(page_size=2)

        assert len(first_page.items) == 2
        assert first_page.count == 173631

        assert first_page.items[
            0].title == 'Experiences with MapReduce, an abstraction for large-scale computation'
        assert first_page.items[1].title == 'MapReduce'

        second_page = first_page.next_page

        assert len(second_page.items) == 2
        assert second_page.count == 173631

        assert second_page.items[
            0].title == 'MapReduce map & reduce function for large datasets'
        assert second_page.items[
            1].title == 'MapReduce: SimplifiedDataProcessing onLargeClusters'
Ejemplo n.º 10
0
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'
Ejemplo n.º 11
0
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_get_by_doi():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/get_catalog_by_identifier/get_by_doi.yaml'):
        doc = session.catalog.by_identifier(doi='10.1371/journal.pone.0000908')

        assert_core_view(doc)
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'
Ejemplo n.º 14
0
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
Ejemplo n.º 15
0
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_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_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_get_core_view():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/get_catalog_by_id/get_core_view.yaml'):
        doc = session.catalog.get('5cd8328e-febe-3299-8e26-cf6ab2c07f0f')

        assert_core_view(doc)
def test_should_get_by_scopus():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/get_catalog_by_identifier/get_by_scopus.yaml'):
        doc = session.catalog.by_identifier(scopus='2-s2.0-41249100408')

        assert_core_view(doc)
Ejemplo n.º 20
0
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'
Ejemplo n.º 21
0
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
Ejemplo n.º 22
0
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_page_through_documents():
    session = get_user_session()
    delete_all_group_documents()

    with cassette(
            'fixtures/resources/trash/list_group_trash/page_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()

        first_page = session.groups.get(
            '164d48fb-2343-332d-b566-1a4884a992e4').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[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'
Ejemplo n.º 24
0
def test_should_iterate_through_groups():
    session = get_user_session()

    with cassette(
            'fixtures/resources/groups/iter_groups/iterate_through_groups.yaml'
    ):
        groups = session.groups.iter(page_size=1)

        first_group = next(groups)
        assert first_group.id == '164d48fb-2343-332d-b566-1a4884a992e4'
        assert first_group.name == 'Basket weaving'

        assert first_group.owner.id == '3e71f6e3-e2b4-3f20-a873-da62554c5c38'
        assert first_group.owner.display_name == 'Jimmy Jones, PhD'

        second_group = next(groups)

        assert second_group.id == 'bcb12b97-db8a-3c1d-b696-d99ed4371175'
        assert second_group.name == 'Python SDK Test Group'

        assert second_group.owner.id == '9930207c-c19f-3de0-b531-86bd4388fa94'
        assert second_group.owner.display_name == 'Jenny Johnson'

        with pytest.raises(StopIteration):
            _ = next(groups)
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_throw_exception_on_incorrect_credentials():
    mendeley = configure_mendeley()
    mendeley.client_secret += '-invalid'
    auth = mendeley.start_client_credentials_flow()

    with cassette('fixtures/auth/client_credentials/incorrect_credentials.yaml'
                  ), pytest.raises(InvalidClientError):
        auth.authenticate()
def test_should_lookup_by_filehash():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/lookup/lookup_by_filehash.yaml'):
        doc = session.catalog.lookup(filehash='f9d3777596893362bbf49618e758d6b8a5271d04')

        assert doc.score == 100
        assert_core_view(doc)
Ejemplo n.º 28
0
def test_should_lookup_by_doi():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/lookup/lookup_by_doi.yaml'):
        doc = session.catalog.lookup(doi='10.1371/journal.pone.0000908')

        assert doc.score == 100
        assert_core_view(doc)
def test_should_lookup_by_doi():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/lookup/lookup_by_doi.yaml'):
        doc = session.catalog.lookup(doi='10.1371/journal.pone.0000908')

        assert doc.score == 100
        assert_core_view(doc)
def test_should_get_group_details():
    session = get_user_session()
    delete_all_documents()

    with cassette('fixtures/resources/documents/create_group_document/get_group_details.yaml'):
        doc = create_group_document(session)

        assert doc.group.name == 'Basket weaving'
Ejemplo n.º 31
0
def test_should_create_minimal_document():
    session = get_user_session()
    delete_all_documents()

    with cassette('fixtures/resources/documents/create_document/create_minimal_document.yaml'):
        doc = session.documents.create('Underwater basket weaving', 'journal')

        assert doc.title == 'Underwater basket weaving'
        assert doc.type == 'journal'
def test_should_get_authenticated_session():
    mendeley = configure_mendeley()
    auth = mendeley.start_client_credentials_flow()

    with cassette('fixtures/auth/client_credentials/get_authenticated_session.yaml'):
        session = auth.authenticate()

        assert session.token['access_token']
        assert session.host == 'https://api.mendeley.com'
def test_should_throw_exception_on_incorrect_credentials():
    mendeley = configure_mendeley()
    mendeley.client_secret += '-invalid'
    auth = mendeley.start_client_credentials_flow()
    
    # We should never get an access token back
    # and the OAuth library should be unhappy about that
    with cassette('fixtures/auth/client_credentials/incorrect_credentials.yaml'), pytest.raises(MissingTokenError):
        auth.authenticate()
Ejemplo n.º 34
0
def test_should_get_by_scopus():
    session = get_client_credentials_session()

    with cassette(
            'fixtures/resources/catalog/get_catalog_by_identifier/get_by_scopus.yaml'
    ):
        doc = session.catalog.by_identifier(scopus='2-s2.0-41249100408')

        assert_core_view(doc)
Ejemplo n.º 35
0
def test_should_raise_if_not_found():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/get_catalog_by_identifier/not_found.yaml'), \
            pytest.raises(MendeleyException) as ex_info:
        _ = session.catalog.by_identifier(doi='dodgy-doi')

    ex = ex_info.value
    assert str(ex) == 'Catalog document not found'
Ejemplo n.º 36
0
def test_should_get_by_doi():
    session = get_client_credentials_session()

    with cassette(
            'fixtures/resources/catalog/get_catalog_by_identifier/get_by_doi.yaml'
    ):
        doc = session.catalog.by_identifier(doi='10.1371/journal.pone.0000908')

        assert_core_view(doc)
Ejemplo n.º 37
0
def test_should_lookup_by_filehash():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/lookup/lookup_by_filehash.yaml'):
        doc = session.catalog.lookup(
            filehash='f9d3777596893362bbf49618e758d6b8a5271d04')

        assert doc.score == 100
        assert_core_view(doc)
def test_should_iterate_through_search_results():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/iter_search/iterate_through_search_results.yaml'):
        docs = list(islice(session.catalog.search('mapreduce').iter(page_size=2), 3))

        assert docs[0].title == 'Rapid parallel genome indexing with MapReduce'
        assert docs[1].title == 'MapReduce'
        assert docs[2].title == 'Mumak: Map-Reduce Simulator'
def test_should_get_document_all_view():
    session = get_user_session()
    delete_all_documents()

    with cassette("fixtures/resources/documents/get_document/get_document_all_view.yaml"):
        created_doc = create_document(session)

        doc = session.documents.get(created_doc.id, view="all")
        assert_all_document(doc)
def test_should_not_be_able_to_search_group_documents():
    session = get_user_session()

    with cassette('fixtures/resources/documents/list_advanced_search/group.yaml'), \
            pytest.raises(MendeleyException) as ex_info:
        _ = session.groups.get('164d48fb-2343-332d-b566-1a4884a992e4').documents.advanced_search(title='basket')

    ex = ex_info.value
    assert str(ex) == 'Search is not available for group documents'
def test_should_get_authenticated_session():
    mendeley = configure_mendeley()
    auth = mendeley.start_authorization_code_flow()

    with cassette('fixtures/auth/authorization_code/get_authenticated_session.yaml'):
        session = auth.authenticate('https://example.com?state=state1234&code=VE1PtGf81OnTA97S545_9a7GWCA')

        assert session.token['access_token']
        assert session.host == 'https://api.mendeley.com'
def test_should_raise_if_not_found():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/get_catalog_by_identifier/not_found.yaml'), \
            pytest.raises(MendeleyException) as ex_info:
        _ = session.catalog.by_identifier(doi='dodgy-doi')

    ex = ex_info.value
    assert str(ex) == 'Catalog document not found'
def test_should_get_download_url_for_file():
    session = get_user_session()
    delete_all_documents()

    with cassette('fixtures/resources/files/list_files/get_download_url.yaml'):
        doc = create_document(session)
        doc.attach_file('fixtures/resources/files/basket.txt')

        url = session.files.list().items[0].download_url
        assert '92c7a71b371eb439579be559b5eac9c09a743c42' in url
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_update_document():
    session = get_user_session()
    delete_all_documents()

    with cassette("fixtures/resources/documents/update_document/update_document.yaml"):
        doc = create_document(session)
        patched_doc = doc.update(title="Overground bucket sawing")

        assert patched_doc.title == "Overground bucket sawing"
        assert session.documents.get(doc.id).title == "Overground bucket sawing"
def test_should_not_change_on_empty_update():
    session = get_user_session()
    delete_all_documents()

    with cassette("fixtures/resources/documents/update_document/empty_update.yaml"):
        doc = create_document(session)
        patched_doc = doc.update()

        assert_all_document(patched_doc)
        assert_all_document(session.documents.get(doc.id, view="all"))
Ejemplo n.º 47
0
def test_should_get_authenticated_session():
    mendeley = configure_mendeley()
    auth = mendeley.start_client_credentials_flow()

    with cassette(
            'fixtures/auth/client_credentials/get_authenticated_session.yaml'):
        session = auth.authenticate()

        assert session.token['access_token']
        assert session.host == 'https://api.mendeley.com'
Ejemplo n.º 48
0
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'
Ejemplo n.º 49
0
def test_should_create_document_with_string_accessed():
    session = get_user_session()
    delete_all_documents()

    with cassette('fixtures/resources/documents/create_document/create_document_string_accessed.yaml'):
        doc = session.documents.create('Underwater basket weaving', 'journal', accessed='2014-09-03')

        assert doc.title == 'Underwater basket weaving'
        assert doc.type == 'journal'
        assert doc.accessed == arrow.get(2014, 9, 3)
def test_should_raise_if_multiple_identifiers():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/get_catalog_by_identifier/multiple_identifiers.yaml'), \
            pytest.raises(MendeleyException) as ex_info:
        _ = session.catalog.by_identifier(doi='10.1371/journal.pone.0000908', scopus='2-s2.0-41249100408')

    ex = ex_info.value
    assert ex.status == 400
    assert ex.message == 'Conflicting filters specified'
def test_should_raise_if_no_identifier():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/get_catalog_by_identifier/no_identifier.yaml'), \
            pytest.raises(MendeleyException) as ex_info:
        _ = session.catalog.by_identifier(view='all')

    ex = ex_info.value
    assert ex.status == 400
    assert ex.message == 'No filter specified'
Ejemplo n.º 52
0
def test_should_raise_if_no_identifier():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/get_catalog_by_identifier/no_identifier.yaml'), \
            pytest.raises(MendeleyException) as ex_info:
        _ = session.catalog.by_identifier(view='all')

    ex = ex_info.value
    assert ex.status == 400
    assert ex.message == 'No filter specified'
Ejemplo n.º 53
0
def test_should_throw_exception_on_incorrect_credentials():
    mendeley = configure_mendeley()
    mendeley.client_secret += '-invalid'
    auth = mendeley.start_client_credentials_flow()

    # We should never get an access token back
    # and the OAuth library should be unhappy about that
    with cassette('fixtures/auth/client_credentials/incorrect_credentials.yaml'
                  ), pytest.raises(MissingTokenError):
        auth.authenticate()
def test_should_delete_file():
    session = get_user_session()
    delete_all_documents()

    with cassette('fixtures/resources/files/delete_file/delete_file.yaml'):
        doc = create_document(session)
        file = doc.attach_file('fixtures/resources/files/basket.txt')
        file.delete()

        assert doc.files.list().count == 0
Ejemplo n.º 55
0
def test_raise_exception_if_client_credentials():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/profiles/get_my_profile/client_credentials.yaml'), \
            pytest.raises(MendeleyApiException) as ex_info:
        _ = session.profiles.me

    ex = ex_info.value
    assert ex.status == 400
    assert ex.message == 'No userid found in auth token'
def test_should_throw_on_bad_view():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/get_catalog_by_id/get_bad_view.yaml'), \
         pytest.raises(MendeleyApiException) as ex_info:
        _ = session.catalog.get('5cd8328e-febe-3299-8e26-cf6ab2c07f0f', view='bad')

    ex = ex_info.value
    assert ex.status == 400
    assert ex.message == 'Invalid view'