class CrossRefTest(TestCase):
    def setUp(self):
        self.api = CrossRefAPI()

    def test_empty_pubdate(self):
        # This DOI has an empty 'issued' date
        p = self.api.create_paper_by_doi('10.1007/978-1-4020-7884-2_13')
        self.assertEqual(p.pubdate.year, 2006)

    def test_affiliations(self):
        p = self.api.create_paper_by_doi('10.4204/eptcs.172.16')
        self.assertEqual(p.authors[0].affiliation,
                         'École Normale Supérieure, Paris')

    def test_dirty_metadata(self):
        # saving a paper with enough metadata to create a paper, but not
        # an OaiRecord.
        p = self.api.save_doi_metadata({
            "DOI":
            "10.1007/978-1-4020-7884-2_13",
            "subtitle": [],
            "author": [{
                "affiliation": [],
                "given": "Haowen",
                "family": "Chan"
            }, {
                "affiliation": [],
                "given": "Adrian",
                "family": "Perrig"
            }, {
                "affiliation": [],
                "given": "Dawn",
                "family": "Song"
            }],
            "created": {
                "timestamp": 1166129219000,
                "date-time": "2006-12-14T20:46:59Z",
                "date-parts": [[2006, 12, 14]]
            },
            "title": ["Key Distribution Techniques for Sensor Networks"],
            "type":
            "book-chapter"
        })
        self.assertTrue(p.is_orphan())
        self.assertFalse(p.visible)

    def test_doctype_book(self):
        # Books are ignored
        # (technically, that's because we currently require a
        # 'container-title' in the metadata)
        p = self.api.create_paper_by_doi('10.1385/1592597998')
        self.assertTrue(p.is_orphan())

    def test_doi_open(self):
        self.assertTrue(
            self.api.create_paper_by_doi('10.15200/winn.145838.88372').pdf_url)
        self.assertFalse(
            self.api.create_paper_by_doi('10.5061/dryad.b167g').pdf_url)
Beispiel #2
0
class MaintenanceTest(PrefilledTest):
    @classmethod
    def setUpClass(self):
        super(MaintenanceTest, self).setUpClass()
        self.cr_api = CrossRefAPI()

    def test_cleanup_names(self):
        n = Name.lookup_name(('Anaruic', 'Leclescuantebrste'))
        n.save()
        cleanup_names()
        try:
            n = Name.objects.get(first='Anaruic', last='Leclescuantebrste')
            self.assertTrue(False and 'The name has not been cleaned up')
        except ObjectDoesNotExist:
            pass

    def test_name_initial(self):
        n = self.r2.name
        p = Paper.create_by_doi("10.1002/ange.19941062339")
        n1 = p.authors[0].name
        self.assertEqual((n1.first, n1.last), (n.first, n.last))

    def test_update_paper_statuses(self):
        p = self.cr_api.create_paper_by_doi("10.1016/j.bmc.2005.06.035")
        p = Paper.from_bare(p)
        self.assertEqual(p.pdf_url, None)
        pdf_url = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'
        OaiRecord.new(source=self.arxiv,
                      identifier='oai:arXiv.org:aunrisste',
                      about=p,
                      splash_url='http://www.perdu.com/',
                      pdf_url=pdf_url)
        update_paper_statuses()
        self.assertEqual(Paper.objects.get(pk=p.pk).pdf_url, pdf_url)
Beispiel #3
0
class MaintenanceTest(TestCase):

    @classmethod
    def setUpClass(self):
        super(MaintenanceTest, self).setUpClass()
        self.cr_api = CrossRefAPI()

    def test_name_initial(self):
        n = self.r2.name
        p = Paper.create_by_doi("10.1002/ange.19941062339")
        n1 = p.authors[0].name
        self.assertEqual((n1.first, n1.last), (n.first, n.last))

    def test_update_paper_statuses(self):
        p = self.cr_api.create_paper_by_doi("10.1016/j.bmc.2005.06.035")
        p = Paper.from_bare(p)
        self.assertEqual(p.pdf_url, None)
        pdf_url = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'
        OaiRecord.new(source=self.arxiv,
                      identifier='oai:arXiv.org:aunrisste',
                      about=p,
                      splash_url='http://www.perdu.com/',
                      pdf_url=pdf_url)
        update_paper_statuses()
        self.assertEqual(Paper.objects.get(pk=p.pk).pdf_url, pdf_url)

    def test_unmerge_paper(self):
        # First we merge two unrelated papers
        p1 = Paper.create_by_doi("10.1016/j.bmc.2005.06.035")
        title1 = p1.title
        p2 = Paper.create_by_doi("10.1016/j.ijar.2017.06.011")
        title2 = p2.title
        p1.merge(p2)
        # Then we unmerge them
        unmerge_paper_by_dois(p1)
        # We have two new papers!
        p3 = Paper.get_by_doi("10.1016/j.bmc.2005.06.035")
        self.assertTrue(p3.id != p1.id)
        self.assertEqual(p3.title, title1)
        p4 = Paper.get_by_doi("10.1016/j.ijar.2017.06.011")
        self.assertTrue(p4.id != p1.id)
        self.assertTrue(p4.id != p3.id)
        self.assertEqual(p4.title, title2)

    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 #4
0
class CrossRefTest(TestCase):

    @classmethod
    def setUpClass(cls):
        super(CrossRefTest, cls).setUpClass()
        cls.testdir = os.path.dirname(os.path.abspath(__file__))

    def setUp(self):
        self.api = CrossRefAPI()

    def test_empty_pubdate(self):
        # This DOI has an empty 'issued' date
        p = self.api.create_paper_by_doi('10.1007/978-1-4020-7884-2_13')
        self.assertEqual(p.pubdate.year, 2006)

    def test_invalid_metadata(self):
        # authors with no family name
        paper = self.api.create_paper_by_doi('10.4156/aiss.vol3.issue9.31')
        self.assertEqual(paper, None)

    def test_affiliations(self):
        p = self.api.create_paper_by_doi('10.4204/eptcs.172.16')
        self.assertEqual(p.authors[0].affiliation,
                         'École Normale Supérieure, Paris')

    def test_dirty_metadata(self):
        # saving a paper with enough metadata to create a paper, but not
        # an OaiRecord.
        p = self.api.save_doi_metadata({
            "DOI": "10.1007/978-1-4020-7884-2_13",
            "subtitle": [],
            "author": [
                {
                    "affiliation": [],
                    "given": "Haowen",
                    "family": "Chan"
                },
                {
                    "affiliation": [],
                    "given": "Adrian",
                    "family": "Perrig"
                },
                {
                    "affiliation": [],
                    "given": "Dawn",
                    "family": "Song"
                }
            ],
            "created": {
                "timestamp": 1166129219000,
                "date-time": "2006-12-14T20:46:59Z",
                "date-parts": [
                    [
                        2006,
                        12,
                        14
                    ]
                ]
            },
            "title": [
                "Key Distribution Techniques for Sensor Networks"
            ],
            "type": "book-chapter"})
        self.assertTrue(p.is_orphan())
        self.assertFalse(p.visible)

    def test_doctype_book(self):
        # Books are ignored
        # (technically, that's because we currently require a
        # 'container-title' in the metadata)
        p = self.api.create_paper_by_doi('10.1385/1592597998')
        self.assertTrue(p.is_orphan())

    def test_doi_open(self):
        self.assertTrue(self.api.create_paper_by_doi('10.15200/winn.145838.88372').pdf_url)
        self.assertFalse(self.api.create_paper_by_doi('10.5061/dryad.b167g').pdf_url)

    def test_fetch_papers(self):
        generator = self.api.fetch_all_records(filters={'issn':'0302-9743'})
        for i in range(30):
            metadata = next(generator)
            self.assertTrue(metadata['DOI'].startswith('10.1007/'))

    def test_import_dump(self):
        self.api.ingest_dump(os.path.join(self.testdir, 'data/sample_crossref_dump.json.bz2'))
        p = Paper.get_by_doi('10.1016/j.jadohealth.2015.10.045')
        self.assertEqual("Sources, Type and Use of Social Support during Early Sexual Development of Black Gay and Bisexual Adolescent Males",
                         p.title)
Beispiel #5
0
class MaintenanceTest(TestCase):
    @classmethod
    def setUpClass(self):
        super(MaintenanceTest, self).setUpClass()
        self.cr_api = CrossRefAPI()

    def test_name_initial(self):
        n = self.r2.name
        p = Paper.create_by_doi("10.1002/ange.19941062339")
        n1 = p.authors[0].name
        self.assertEqual((n1.first, n1.last), (n.first, n.last))

    def test_update_paper_statuses(self):
        p = self.cr_api.create_paper_by_doi("10.1016/j.bmc.2005.06.035")
        p = Paper.from_bare(p)
        self.assertEqual(p.pdf_url, None)
        pdf_url = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'
        OaiRecord.new(source=self.arxiv,
                      identifier='oai:arXiv.org:aunrisste',
                      about=p,
                      splash_url='http://www.perdu.com/',
                      pdf_url=pdf_url)
        update_paper_statuses()
        self.assertEqual(Paper.objects.get(pk=p.pk).pdf_url, pdf_url)

    def test_unmerge_paper(self):
        # First we merge two unrelated papers
        p1 = Paper.create_by_doi("10.1016/j.bmc.2005.06.035")
        title1 = p1.title
        p2 = Paper.create_by_doi("10.1016/j.ijar.2017.06.011")
        title2 = p2.title
        p1.merge(p2)
        # Then we unmerge them
        unmerge_paper_by_dois(p1)
        # We have two new papers!
        p3 = Paper.get_by_doi("10.1016/j.bmc.2005.06.035")
        self.assertTrue(p3.id != p1.id)
        self.assertEqual(p3.title, title1)
        p4 = Paper.get_by_doi("10.1016/j.ijar.2017.06.011")
        self.assertTrue(p4.id != p1.id)
        self.assertTrue(p4.id != p3.id)
        self.assertEqual(p4.title, title2)

    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
class CrossRefTest(TestCase):
    @classmethod
    def setUpClass(cls):
        super(CrossRefTest, cls).setUpClass()
        cls.testdir = os.path.dirname(os.path.abspath(__file__))

    def setUp(self):
        self.api = CrossRefAPI()

    def test_empty_pubdate(self):
        # This DOI has an empty 'issued' date
        p = self.api.create_paper_by_doi('10.1007/978-1-4020-7884-2_13')
        self.assertEqual(p.pubdate.year, 2006)

    def test_invalid_metadata(self):
        # authors with no family name
        paper = self.api.create_paper_by_doi('10.4156/aiss.vol3.issue9.31')
        self.assertEqual(paper, None)

    def test_affiliations(self):
        p = self.api.create_paper_by_doi('10.4204/eptcs.172.16')
        self.assertEqual(p.authors[0].affiliation,
                         'École Normale Supérieure, Paris')

    def test_dirty_metadata(self):
        # saving a paper with enough metadata to create a paper, but not
        # an OaiRecord.
        p = self.api.save_doi_metadata({
            "DOI":
            "10.1007/978-1-4020-7884-2_13",
            "subtitle": [],
            "author": [{
                "affiliation": [],
                "given": "Haowen",
                "family": "Chan"
            }, {
                "affiliation": [],
                "given": "Adrian",
                "family": "Perrig"
            }, {
                "affiliation": [],
                "given": "Dawn",
                "family": "Song"
            }],
            "created": {
                "timestamp": 1166129219000,
                "date-time": "2006-12-14T20:46:59Z",
                "date-parts": [[2006, 12, 14]]
            },
            "title": ["Key Distribution Techniques for Sensor Networks"],
            "type":
            "book-chapter"
        })
        self.assertTrue(p.is_orphan())
        self.assertFalse(p.visible)

    def test_doctype_book(self):
        # Books are ignored
        # (technically, that's because we currently require a
        # 'container-title' in the metadata)
        p = self.api.create_paper_by_doi('10.1385/1592597998')
        self.assertTrue(p.is_orphan())

    def test_doi_open(self):
        self.assertTrue(
            self.api.create_paper_by_doi('10.15200/winn.145838.88372').pdf_url)
        self.assertFalse(
            self.api.create_paper_by_doi('10.5061/dryad.b167g').pdf_url)

    def test_fetch_papers(self):
        generator = self.api.fetch_all_records(filters={'issn': '0302-9743'})
        for i in range(30):
            metadata = next(generator)
            self.assertTrue(metadata['DOI'].startswith('10.1007/'))

    def test_import_dump(self):
        self.api.ingest_dump(
            os.path.join(self.testdir, 'data/sample_crossref_dump.json.bz2'))
        p = Paper.get_by_doi('10.1016/j.jadohealth.2015.10.045')
        self.assertEqual(
            "Sources, Type and Use of Social Support during Early Sexual Development of Black Gay and Bisexual Adolescent Males",
            p.title)