Example #1
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)
Example #2
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)