Пример #1
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'
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)
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)
Пример #5
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)
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_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)
Пример #8
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)
Пример #9
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'
Пример #11
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)
Пример #12
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)
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'
Пример #14
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'
Пример #15
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'
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'
Пример #17
0
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'
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'
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'
Пример #20
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_list_files_by_catalog_document():
    session = get_client_credentials_session()

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

        page = doc.files.list()
        assert len(page.items) == 1
        assert page.count == 1

        assert page.items[0].filehash == '933b1d7ad3793aaf5de2090b4199cab8f8c6489a'
def test_should_list_search_results_all_view():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/list_search/list_search_results_all_view.yaml'):
        first_page = session.catalog.search('mapreduce', view='all').list(page_size=2)

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

        assert first_page.items[0].title == 'Rapid parallel genome indexing with MapReduce'
        assert first_page.items[0].publisher == 'ACM Press'
Пример #23
0
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_list_search_results_all_view():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/list_advanced_search/list_search_results_all_view.yaml'):
        first_page = session.catalog.advanced_search(title='mapreduce', author='Jeffrey Dean', view='all') \
            .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[0].reader_count == 55
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))
        
        # Data in the catalog can change over time so cannot search for exact strings
        # instead search for the keywords we are really interested in
        expected_substring = u'mapreduce'
        assert expected_substring in str(docs[0].title).lower()
        assert expected_substring in str(docs[1].title).lower()
        assert expected_substring in str(docs[2].title).lower()
def test_should_list_search_results_all_view():
    session = get_client_credentials_session()

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

        assert len(first_page.items) == 2
        assert first_page.count > 0

        assert 'mapreduce' in first_page.items[0].title.lower()
        assert first_page.items[0].reader_count > 0
Пример #27
0
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_catalog_document_for_file():
    session = get_client_credentials_session()

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

        page = doc.files.list()
        assert len(page.items) == 1
        assert page.count == 1

        assert page.items[0].document().title == 'Changes in tree reproductive traits reduce functional diversity ' \
                                                 'in a fragmented Atlantic forest landscape'
def test_should_lookup_by_metadata():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/lookup/lookup_by_metadata.yaml'):
        doc = session.catalog.lookup(
            title='Changes in tree reproductive traits reduce functional diversity in a fragmented '
                  'Atlantic forest landscape',
            year=2007,
            source='PLoS ONE'
        )

        assert doc.score == 91
        assert_core_view(doc)
Пример #30
0
def test_should_raise_on_not_found():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/lookup/not_found.yaml'), \
         pytest.raises(MendeleyApiException) as ex_info:
        doc = session.catalog.lookup(title='Underwater basket weaving',
                                     authors='Piers Bursill-Hall')

        assert doc.score == 91
        assert_core_view(doc)

    ex = ex_info.value
    assert ex.status == 404
Пример #31
0
def test_should_lookup_by_metadata():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/lookup/lookup_by_metadata.yaml'):
        doc = session.catalog.lookup(
            title=
            'Changes in tree reproductive traits reduce functional diversity in a fragmented '
            'Atlantic forest landscape',
            year=2007,
            source='PLoS ONE')

        assert doc.score == 91
        assert_core_view(doc)
Пример #32
0
def test_should_list_search_results_all_view():
    session = get_client_credentials_session()

    with cassette(
            'fixtures/resources/catalog/list_search/list_search_results_all_view.yaml'
    ):
        first_page = session.catalog.search('mapreduce',
                                            view='all').list(page_size=2)

        assert len(first_page.items) == 2
        assert first_page.count > 0

        assert 'mapreduce' in first_page.items[0].title.lower()
def test_should_list_files_by_catalog_document():
    session = get_client_credentials_session()

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

        page = doc.files.list()
        assert len(page.items) == 1
        assert page.count == 1

        assert page.items[
            0].filehash == '933b1d7ad3793aaf5de2090b4199cab8f8c6489a'
Пример #34
0
def test_should_list_search_results_all_view():
    session = get_client_credentials_session()

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

        assert len(first_page.items) == 2
        assert first_page.count > 0

        assert 'mapreduce' in first_page.items[0].title.lower()
        assert first_page.items[0].reader_count > 0
def test_should_get_catalog_document_for_file():
    session = get_client_credentials_session()

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

        page = doc.files.list()
        assert len(page.items) == 1
        assert page.count == 1

        assert page.items[0].document().title == 'Changes in tree reproductive traits reduce functional diversity ' \
                                                 'in a fragmented Atlantic forest landscape'
Пример #36
0
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))

        # Data in the catalog can change over time so cannot search for exact strings
        # instead search for the keywords we are really interested in
        expected_substring = u'mapreduce'
        assert expected_substring in str(docs[0].title).lower()
        assert expected_substring in str(docs[1].title).lower()
        assert expected_substring in str(docs[2].title).lower()
def test_should_list_search_results_all_view():
    session = get_client_credentials_session()

    with cassette(
            'fixtures/resources/catalog/list_search/list_search_results_all_view.yaml'
    ):
        first_page = session.catalog.search('mapreduce',
                                            view='all').list(page_size=2)

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

        assert first_page.items[
            0].title == 'Rapid parallel genome indexing with MapReduce'
        assert first_page.items[0].publisher == 'ACM Press'
def test_should_raise_on_not_found():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/lookup/not_found.yaml'), \
         pytest.raises(MendeleyApiException) as ex_info:
        doc = session.catalog.lookup(
            title='Underwater basket weaving',
            authors='Piers Bursill-Hall'
        )

        assert doc.score == 91
        assert_core_view(doc)

    ex = ex_info.value
    assert ex.status == 404
Пример #39
0
def test_should_list_search_results_all_view():
    session = get_client_credentials_session()

    with cassette(
            'fixtures/resources/catalog/list_advanced_search/list_search_results_all_view.yaml'
    ):
        first_page = session.catalog.advanced_search(title='mapreduce', author='Jeffrey Dean', view='all') \
            .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[0].reader_count == 55
def test_should_page_through_search_results():
    session = get_client_credentials_session()

    with cassette('fixtures/resources/catalog/list_search/page_through_search_results.yaml'):
        first_page = session.catalog.search('mapreduce').list(page_size=2)

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

        assert first_page.items[0].title == 'Rapid parallel genome indexing with MapReduce'
        assert first_page.items[1].title == 'MapReduce'

        second_page = first_page.next_page

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

        assert second_page.items[0].title == 'Mumak: Map-Reduce Simulator'
        assert second_page.items[1].title == 'Exploring mapreduce efficiency with highly-distributed data'
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 > 0

        assert 'mapreduce' in first_page.items[0].title.lower()
        assert 'mapreduce' in first_page.items[1].title.lower()

        second_page = first_page.next_page

        assert len(second_page.items) == 2
        assert second_page.count > 0

        assert 'mapreduce' in second_page.items[0].title.lower()
        assert 'mapreduce' in second_page.items[1].title.lower()
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'
Пример #43
0
def test_should_page_through_search_results():
    session = get_client_credentials_session()

    with cassette(
            'fixtures/resources/catalog/list_search/page_through_search_results.yaml'
    ):
        first_page = session.catalog.search('mapreduce').list(page_size=2)

        assert len(first_page.items) == 2
        assert first_page.count > 0

        assert 'mapreduce' in first_page.items[0].title.lower()
        assert 'mapreduce' in first_page.items[1].title.lower()

        second_page = first_page.next_page

        assert len(second_page.items) == 2
        assert second_page.count > 0

        assert 'mapreduce' in second_page.items[0].title.lower()
        assert 'mapreduce' in second_page.items[1].title.lower()
def test_should_page_through_search_results():
    session = get_client_credentials_session()

    with cassette(
            'fixtures/resources/catalog/list_search/page_through_search_results.yaml'
    ):
        first_page = session.catalog.search('mapreduce').list(page_size=2)

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

        assert first_page.items[
            0].title == 'Rapid parallel genome indexing with MapReduce'
        assert first_page.items[1].title == 'MapReduce'

        second_page = first_page.next_page

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

        assert second_page.items[0].title == 'Mumak: Map-Reduce Simulator'
        assert second_page.items[
            1].title == 'Exploring mapreduce efficiency with highly-distributed data'