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])
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
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)
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
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
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)
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)
def setUpClass(self): super(OrcidIntegrationTest, self).setUpClass() self.source = OrcidPaperSource()
def setUp(self): self.source = OrcidPaperSource() self.researcher = self.r4
def setUpClass(self): super(StatisticsTest, self).setUpClass() cr_api = OrcidPaperSource() cr_api.fetch_and_save(self.r3)