Beispiel #1
0
 def test_fetch_metadata_from_dois_no_paper(self, monkeypatch):
     """
     If no paper created, expect None
     """
     monkeypatch.setattr(Paper, 'create_by_doi', lambda x: None)
     monkeypatch.setattr(CrossRef, 'fetch_batch', lambda x: [None])
     o = OrcidPaperSource()
     papers = list(o.fetch_metadata_from_dois('spam', 'ham', ['any_doi']))
     assert len(papers) == 1
     assert papers[0] is None
Beispiel #2
0
def fetch_crossref_profile(request, django_db_setup, django_db_blocker, get_researcher_by_name):
    with django_db_blocker.unblock():
        call_command('loaddata', 'test_dump.json')
        self = request.cls
        self.i = Institution.objects.get(name='ENS')
        self.d = Department.objects.get(name='Chemistry dept')
        self.r2 = get_researcher_by_name('Ludovic', 'Jullien')
        self.r3 = get_researcher_by_name('Antoine', 'Amarilli')

        cr_api = OrcidPaperSource()
        cr_api.fetch_and_save(request.cls.r3)
Beispiel #3
0
def fetch_crossref_profile(request, django_db_setup, django_db_blocker):
    with django_db_blocker.unblock():
        call_command('loaddata', 'test_dump.json')
        self = request.cls
        self.i = Institution.objects.get(name='ENS')
        self.d = Department.objects.get(name='Chemistry dept')
        self.r2 = get_researcher_by_name('Ludovic', 'Jullien')
        self.r3 = get_researcher_by_name('Antoine', 'Amarilli')

        cr_api = OrcidPaperSource()
        cr_api.fetch_and_save(request.cls.r3)
Beispiel #4
0
 def test_enhance_paper_orcid_oai_exists(self, researcher_lesot):
     """
     If source exists, nothing must happen
     """
     doi = '10.1016/j.ijar.2017.06.011'
     p = Paper.create_by_doi(doi)
     o = OrcidPaperSource()
     ref_name = (researcher_lesot.name.first, researcher_lesot.name.last)
     p = o._enhance_paper(p, ref_name, researcher_lesot.orcid)
     # Lesot is now a researcher of the paper
     assert p.authors_list[1]['researcher_id'] == researcher_lesot.pk
     # There must be a second OaiRecord
     p.cache_oairecords()  # Cache is not up to date
     assert len(p.oairecords) == 2
Beispiel #5
0
    def test_unmerge_orcid_nones(self):
        # First, fetch a few DOIs
        dois = [
            "10.1075/aicr.90.09ngo",
            "10.1075/aicr.90.04wad",
        ]
        for doi in dois:
            Paper.create_by_doi(doi)

        # Then, fetch an ORCID profile with a buggy version of the ORCID interface, which incorrectly merges papers together
        with patch.object(OrcidPaperSource,
                          '_oai_id_for_doi') as mock_identifier:
            mock_identifier.return_value = "https://pub.orcid.org/v2.1/0000-0002-1909-134X/work/None"
            profile = OrcidProfileStub('0000-0002-1909-134X',
                                       instance='orcid.org')
            trung = Researcher.get_or_create_by_orcid('0000-0002-1909-134X',
                                                      profile=profile)
            OrcidPaperSource().fetch_and_save(trung, profile=profile)

        # The two papers are incorrectly merged!
        papers = [Paper.get_by_doi(doi) for doi in dois]
        self.assertEqual(papers[0], papers[1])

        # We unmerge them
        unmerge_orcid_nones()

        # The two papers are now distinct
        papers = [Paper.get_by_doi(doi) for doi in dois]
        self.assertTrue(papers[0] != papers[1])
Beispiel #6
0
 def test_fetch_metadata_from_dois(self, researcher_lesot):
     """
     Fetch metadata from doi
     """
     dois = ['10.1016/j.ijar.2017.06.011']
     o = OrcidPaperSource()
     ref_name = (researcher_lesot.name.first, researcher_lesot.name.last)
     papers = list(
         o.fetch_metadata_from_dois(ref_name, researcher_lesot.orcid, dois))
     assert len(papers) == 1
     p = papers[0]
     # Lesot is now a researcher of the paper
     assert p.authors_list[1]['researcher_id'] == researcher_lesot.pk
     # There must be a second OaiRecord
     p.cache_oairecords()  # Cache is not up to date
     assert len(p.oairecords) == 2
Beispiel #7
0
def fetch_everything_for_researcher(pk):
    sources = [
        ('orcid', OrcidPaperSource(max_results=1000)),
    ]
    r = Researcher.objects.get(pk=pk)

    # If it is the first time we fetch this researcher
    # if r.stats is None:
    # make sure publications already known are also considered
    update_researcher_task(r, 'clustering')
    try:
        for key, source in sources:
            update_researcher_task(r, key)
            source.fetch_and_save(r)
        update_researcher_task(r, None)

    except MetadataSourceException as e:
        raise e
    finally:
        r = Researcher.objects.get(pk=pk)
        update_researcher_task(r, 'stats')
        r.update_stats()
        r.harvester = None
        update_researcher_task(r, None)
Beispiel #8
0
def fetch_everything_for_researcher(pk):
    orcid_paper_source = OrcidPaperSource(max_results=1000)
    r = Researcher.objects.get(pk=pk)

    # If it is the first time we fetch this researcher
    # if r.stats is None:
    # make sure publications already known are also considered
    update_researcher_task(r, 'orcid')

    try:
        orcid_paper_source.link_existing_papers(r)
        orcid_paper_source.fetch_and_save(r)
        update_researcher_task(r, None)

    except MetadataSourceException as e:
        raise e
    finally:
        r = Researcher.objects.get(pk=pk)
        update_researcher_task(r, 'stats')
        r.update_stats()
        r.harvester = None
        update_researcher_task(r, None)
Beispiel #9
0
 def setUpClass(self):
     super(OrcidIntegrationTest, self).setUpClass()
     self.source = OrcidPaperSource()
Beispiel #10
0
class OrcidIntegrationTest(PaperSourceTest):
    @classmethod
    def setUpClass(self):
        super(OrcidIntegrationTest, self).setUpClass()
        self.source = OrcidPaperSource()

    def check_papers(self, papers):
        p = Paper.objects.get(
            title='From Natural Language to RDF Graphs with Pregroups')
        p.check_authors()
        author = p.authors[0]
        self.assertEqual(author.orcid, self.r4.orcid)
        p = Paper.objects.get(
            title='Complexity of Grammar Induction for Quantum Types')
        p.check_authors()
        author = p.authors[0]
        self.assertEqual(author.orcid, self.r4.orcid)

    def test_previously_present_papers_are_attributed(self):
        # Fetch papers from a researcher
        pablo = Researcher.get_or_create_by_orcid('0000-0002-6293-3231')
        self.source.fetch_and_save(pablo)

        p = Paper.objects.get(oairecord__doi='10.1007/978-3-642-25516-8_1')
        self.assertEqual(p.authors[2].orcid, pablo.orcid)

        # Now fetch a coauthor of him
        antoine = Researcher.get_or_create_by_orcid('0000-0002-7977-4441')
        self.source.fetch_and_save(antoine)

        # This paper should be attributed to both ORCID ids
        p = Paper.objects.get(oairecord__doi='10.1007/978-3-642-25516-8_1')

        self.assertEqual(p.authors[0].orcid, antoine.orcid)
        self.assertEqual(p.authors[2].orcid, pablo.orcid)

    def test_fetch_dois(self):
        pboesu = Researcher.get_or_create_by_orcid('0000-0001-6723-6833')
        self.source.fetch_and_save(pboesu)

        doi = '10.3354/meps09890'
        p = Paper.get_by_doi(doi)
        dois_in_paper = [r.doi for r in p.oairecords]
        self.assertTrue(doi in dois_in_paper)

    def test_orcid_affiliation(self):
        # this used to raise an error.
        # a more focused test might be preferable (focused on the said
        # paper)
        papers = list(self.source.fetch_orcid_records('0000-0002-9658-1473'))
        self.assertTrue(len(papers) > 30)

    def test_bibtex_fallback(self):
        papers = list(self.source.fetch_orcid_records('0000-0002-1900-3901'))
        titles = [paper.title for paper in papers]
        self.assertTrue(
            'Company-Coq: Taking Proof General one step closer to a real IDE'
            in titles)

    def test_import_with_crossref_error(self):
        stergios = Researcher.get_or_create_by_orcid('0000-0001-9232-4042')
        self.source.fetch_and_save(stergios)
        p = Paper.objects.get(oairecord__doi='10.1016/j.metabol.2017.10.007')
        # crossref claims that the ORCID should be associated to author 2
        # but it should actually be associated to author 0
        self.assertEqual(p.authors[0].orcid, '0000-0001-9232-4042')
        self.assertEqual(p.authors[2].orcid, None)
        self.assertEqual(p.authors[0].researcher_id, stergios.id)
        self.assertEqual(p.authors[2].researcher_id, None)
Beispiel #11
0
class OrcidIntegrationTest(PaperSourceTest):
    def setUp(self):
        super(OrcidIntegrationTest, self).setUp()
        self.source = OrcidPaperSource()

    def test_fetch(self):
        profile = OrcidProfileStub('0000-0002-8612-8827', instance='orcid.org')
        papers = list(
            self.source.fetch_papers(self.researcher, profile=profile))
        for paper in papers:
            paper = Paper.from_bare(paper)
        self.assertTrue(len(papers) > 1)
        self.check_papers(papers)

    def check_papers(self, papers):
        p = Paper.objects.get(
            title='From Natural Language to RDF Graphs with Pregroups')
        p.check_authors()
        author = p.authors[0]
        self.assertEqual(author.orcid, self.r4.orcid)
        p = Paper.objects.get(
            title='Complexity of Grammar Induction for Quantum Types')
        p.check_authors()
        author = p.authors[0]
        self.assertEqual(author.orcid, self.r4.orcid)

    def test_previously_present_papers_are_attributed(self):
        # Fetch papers from a researcher
        profile_pablo = OrcidProfileStub('0000-0002-6293-3231',
                                         instance='orcid.org')
        pablo = Researcher.get_or_create_by_orcid('0000-0002-6293-3231',
                                                  profile=profile_pablo)
        self.source.fetch_and_save(pablo, profile=profile_pablo)

        p = Paper.objects.get(oairecord__doi='10.1007/978-3-642-25516-8_1')
        self.assertEqual(p.authors[2].orcid, pablo.orcid)

        # Now fetch a coauthor of him
        profile_antoine = OrcidProfileStub('0000-0002-7977-4441',
                                           instance='orcid.org')
        antoine = Researcher.get_or_create_by_orcid('0000-0002-7977-4441',
                                                    profile=profile_antoine)
        self.source.fetch_and_save(antoine, profile=profile_antoine)

        # This paper should be attributed to both ORCID ids
        p = Paper.objects.get(oairecord__doi='10.1007/978-3-642-25516-8_1')

        self.assertEqual(p.authors[0].orcid, antoine.orcid)
        self.assertEqual(p.authors[2].orcid, pablo.orcid)

    def test_fetch_dois(self):
        profile = OrcidProfileStub('0000-0001-6723-6833', instance='orcid.org')
        pboesu = Researcher.get_or_create_by_orcid('0000-0001-6723-6833',
                                                   profile=profile)
        self.source.fetch_and_save(pboesu, profile=profile)

        doi = '10.3354/meps09890'
        p = Paper.get_by_doi(doi)
        dois_in_paper = [r.doi for r in p.oairecords]
        self.assertTrue(doi in dois_in_paper)

    def test_orcid_affiliation(self):
        # this used to raise an error.
        # a more focused test might be preferable (focused on the said
        # paper)
        papers = list(
            self.source.fetch_orcid_records(
                '0000-0002-9658-1473',
                OrcidProfileStub('0000-0002-9658-1473')))
        self.assertTrue(len(papers) > 30)

    def test_bibtex_fallback(self):
        papers = list(
            self.source.fetch_orcid_records(
                '0000-0002-1900-3901',
                profile=OrcidProfileStub('0000-0002-1900-3901')))
        titles = [paper.title for paper in papers]
        self.assertTrue(
            'Company-Coq: Taking Proof General one step closer to a real IDE'
            in titles)

    def test_import_with_crossref_error(self):
        profile = OrcidProfileStub('0000-0001-9232-4042', instance='orcid.org')
        stergios = Researcher.get_or_create_by_orcid('0000-0001-9232-4042',
                                                     profile=profile)
        self.source.fetch_and_save(stergios, profile=profile)
        p = Paper.objects.get(oairecord__doi='10.1016/j.metabol.2017.10.007')
        # crossref claims that the ORCID should be associated to author 2
        # but it should actually be associated to author 0
        self.assertEqual(p.authors[0].orcid, '0000-0001-9232-4042')
        self.assertEqual(p.authors[2].orcid, None)
        self.assertEqual(p.authors[0].researcher_id, stergios.id)
        self.assertEqual(p.authors[2].researcher_id, None)

    def test_bibtex_not_ignored(self):
        profile = OrcidProfileStub('0000-0003-2888-1770', instance='orcid.org')
        adrien = Researcher.get_or_create_by_orcid('0000-0003-2888-1770',
                                                   profile=profile)
        self.source.fetch_and_save(adrien, profile=profile)
        p1 = Paper.objects.get(title='A Fuzzy Take on Graded Beliefs')
        p2 = Paper.objects.get(title='Information quality and uncertainty')
        self.assertTrue(p1 != p2)

    def test_link_existing_papers(self):
        # Fetch papers from a researcher
        profile_pablo = OrcidProfileStub('0000-0002-6293-3231',
                                         instance='orcid.org')
        pablo = Researcher.get_or_create_by_orcid('0000-0002-6293-3231',
                                                  profile=profile_pablo)
        self.source.fetch_and_save(pablo, profile=profile_pablo)
        papers = list(pablo.papers)
        nb_papers = len(papers)
        self.assertEqual(nb_papers, 9)

        # Remove the researcher_ids from the papers
        for paper in papers:
            for author in paper.authors_list:
                if author.get('researcher_id') == pablo.id:
                    del author['researcher_id']
            paper.save()

        # Now the profile has no papers anymore
        self.assertEqual(pablo.papers.count(), 0)

        # Let's fix that!
        self.source.link_existing_papers(pablo)

        # Now it's fine!!
        self.assertEqual(Researcher.objects.get(id=pablo.id).papers.count(), 9)
Beispiel #12
0
 def setUp(self):
     super(OrcidIntegrationTest, self).setUp()
     self.source = OrcidPaperSource()
Beispiel #13
0
class OrcidIntegrationTest(PaperSourceTest):

    def setUp(self):
        super(OrcidIntegrationTest, self).setUp()
        self.source = OrcidPaperSource()

    def test_fetch(self):
        profile = OrcidProfileStub('0000-0002-8612-8827', instance='orcid.org')
        papers = list(self.source.fetch_papers(self.researcher, profile=profile))
        for paper in papers:
            paper = Paper.from_bare(paper)
        self.assertTrue(len(papers) > 1)
        self.check_papers(papers)

    def check_papers(self, papers):
        p = Paper.objects.get(
            title='From Natural Language to RDF Graphs with Pregroups')
        p.check_authors()
        author = p.authors[0]
        self.assertEqual(author.orcid, self.r4.orcid)
        p = Paper.objects.get(
            title='Complexity of Grammar Induction for Quantum Types')
        p.check_authors()
        author = p.authors[0]
        self.assertEqual(author.orcid, self.r4.orcid)

    def test_previously_present_papers_are_attributed(self):
        # Fetch papers from a researcher
        profile_pablo = OrcidProfileStub('0000-0002-6293-3231', instance='orcid.org')
        pablo = Researcher.get_or_create_by_orcid('0000-0002-6293-3231',
                profile=profile_pablo)
        self.source.fetch_and_save(pablo, profile=profile_pablo)

        p = Paper.objects.get(oairecord__doi='10.1007/978-3-642-25516-8_1')
        self.assertEqual(p.authors[2].orcid, pablo.orcid)

        # Now fetch a coauthor of him
        profile_antoine = OrcidProfileStub('0000-0002-7977-4441', instance='orcid.org')
        antoine = Researcher.get_or_create_by_orcid('0000-0002-7977-4441',
                    profile=profile_antoine)
        self.source.fetch_and_save(antoine, profile=profile_antoine)

        # This paper should be attributed to both ORCID ids
        p = Paper.objects.get(oairecord__doi='10.1007/978-3-642-25516-8_1')

        self.assertEqual(p.authors[0].orcid, antoine.orcid)
        self.assertEqual(p.authors[2].orcid, pablo.orcid)

    def test_fetch_dois(self):
        profile = OrcidProfileStub('0000-0001-6723-6833', instance='orcid.org')
        pboesu = Researcher.get_or_create_by_orcid('0000-0001-6723-6833',
                    profile=profile)
        self.source.fetch_and_save(pboesu, profile=profile)

        doi = '10.3354/meps09890'
        p = Paper.get_by_doi(doi)
        dois_in_paper = [r.doi for r in p.oairecords]
        self.assertTrue(doi in dois_in_paper)

    def test_orcid_affiliation(self):
        # this used to raise an error.
        # a more focused test might be preferable (focused on the said
        # paper)
        papers = list(self.source.fetch_orcid_records('0000-0002-9658-1473',
                        OrcidProfileStub('0000-0002-9658-1473')))
        self.assertTrue(len(papers) > 30)

    def test_bibtex_fallback(self):
        papers = list(self.source.fetch_orcid_records('0000-0002-1900-3901',
                  profile=OrcidProfileStub('0000-0002-1900-3901')))
        titles = [paper.title for paper in papers]
        self.assertTrue('Company-Coq: Taking Proof General one step closer to a real IDE' in titles)

    def test_import_with_crossref_error(self):
        profile = OrcidProfileStub('0000-0001-9232-4042', instance='orcid.org')
        stergios = Researcher.get_or_create_by_orcid('0000-0001-9232-4042',
                 profile=profile)
        self.source.fetch_and_save(stergios, profile=profile)
        p = Paper.objects.get(oairecord__doi='10.1016/j.metabol.2017.10.007')
        # crossref claims that the ORCID should be associated to author 2
        # but it should actually be associated to author 0
        self.assertEqual(p.authors[0].orcid, '0000-0001-9232-4042')
        self.assertEqual(p.authors[2].orcid, None)
        self.assertEqual(p.authors[0].researcher_id, stergios.id)
        self.assertEqual(p.authors[2].researcher_id, None)

    def test_bibtex_not_ignored(self):
        profile = OrcidProfileStub('0000-0003-2888-1770', instance='orcid.org')
        adrien = Researcher.get_or_create_by_orcid('0000-0003-2888-1770', profile=profile)
        self.source.fetch_and_save(adrien, profile=profile)
        p1 = Paper.objects.get(title='A Fuzzy Take on Graded Beliefs')
        p2 = Paper.objects.get(title='Information quality and uncertainty')
        self.assertTrue(p1 != p2)
Beispiel #14
0
 def setUp(self):
     self.source = OrcidPaperSource()
     self.researcher = self.r4
Beispiel #15
0
 def setUpClass(self):
     super(StatisticsTest, self).setUpClass()
     cr_api = OrcidPaperSource()
     cr_api.fetch_and_save(self.r3)