Beispiel #1
0
 def setUpClass(self):
     super(HALProtocolTest, self).setUpClass()
     self.repo.username = '******'
     self.repo.password = '******'
     self.repo.endpoint = 'https://api-preprod.archives-ouvertes.fr/sword/'
     self.repo.save()
     # f =
     self.proto = HALProtocol(self.repo)
Beispiel #2
0
class TopicPredictionTest(TestCase):
    def setUp(self):
        self.protocol = HALProtocol(repository=Repository())

    @responses.activate
    def test_predict_topic(self):
        text = 'A complete model for faceted dataflow programs'
        expected_response = {
            "results": [{
                "label":
                "Computer science",
                "score":
                0.8055065870285034,
                "uri":
                "https://aurehal.archives-ouvertes.fr/domain/INFO"
            }, {
                "label":
                "Cognitive science",
                "score":
                0.09652446210384369,
                "uri":
                "https://aurehal.archives-ouvertes.fr/domain/SCCO"
            }, {
                "label":
                "Statistics",
                "score":
                0.02962828427553177,
                "uri":
                "https://aurehal.archives-ouvertes.fr/domain/STAT"
            }]
        }
        responses.add(
            responses.POST,
            'https://annif.dissem.in/v1/projects/hal-fasttext/suggest',
            json=expected_response)

        self.assertEqual(self.protocol.predict_topic(text), 'INFO')

    @responses.activate
    def test_predict_empty_text(self):
        self.assertEqual(self.protocol.predict_topic(''), None)
Beispiel #3
0
 def setUpClass(self):
     super(HALProtocolTest, self).setUpClass()
     self.proto = HALProtocol(self.repo)
Beispiel #4
0
 def setUp(self):
     self.protocol = HALProtocol(repository=Repository())
Beispiel #5
0
class HALProtocolTest(ProtocolTest):

    def setUpClass(self):
        super(HALProtocolTest, self).setUpClass()
        self.repo.username = '******'
        self.repo.password = '******'
        self.repo.endpoint = 'https://api-preprod.archives-ouvertes.fr/sword/'
        self.repo.save()
        # f =
        self.proto = HALProtocol(self.repo)

    @expectedFailure
    def test_lncs_many_authors(self):
        """
        Submit a paper from LNCS (type: book-chapter).
        This fails with the default test account because
        it does not have the right to deposit with only one
        affiliation.
        """
        # the DOI below should *not* already exist in HAL
        # so it may need to be changed if the test fails
        p = Paper.create_by_doi('10.1007/978-3-319-63342-8_1')
        r = self.dry_deposit(p,
            abstract='this is an abstract',
            topic='INFO',
            depositing_author=0,
            affiliation=59704) # ENS
        self.assertEqualOrLog(r.status, 'faked')

    def test_lncs(self):
        """
        Same as test_lncs but with only one author
        """
        p = Paper.create_by_doi('10.1007/978-3-319-63342-8_1')
        p.authors_list = [p.authors_list[0]]
        r = self.dry_deposit(p,
            abstract='this is an abstract',
            topic='INFO',
            depositing_author=0,
            affiliation=59704) # ENS
        self.assertEqualOrLog(r.status, 'faked')


    def test_lics(self):
        """
        Submit a paper from LICS (type: conference-proceedings)
        """
        p = Paper.create_by_doi('10.1109/lics.2015.37')
        p.authors_list = [p.authors_list[0]]
        r = self.dry_deposit(p,
             abstract='here is my great result',
             topic='NLIN',
             depositing_author=0,
             affiliation=128940)
        self.assertEqualOrLog(r.status, 'faked')

    def test_journal_article(self):
        """
        Submit a journal article
        """
        p = Paper.create_by_doi('10.1016/j.agee.2004.10.001')
        p.authors_list = [p.authors_list[0]]
        r = self.dry_deposit(p,
             abstract='here is my great result',
             topic='SDV',
             depositing_author=0,
             affiliation=128940)
        self.assertEqualOrLog(r.status, 'faked')

    def test_topic_set_to_other(self):
        """
        Submit a journal article with "OTHER" as topic,
        which is forbidden by HAL
        """
        p = Paper.create_by_doi('10.1016/j.agee.2004.10.001')
        self.proto.init_deposit(p, self.user)

        # the user is presented with initial data
        args = self.proto.get_form_initial_data()
        # they fill the form with an invalid topic
        form_fields = {'abstract':'here is my great result',
             'topic':'OTHER',
             'depositing_author':0,
             'affiliation':128940}
        args.update(form_fields)

        # the form should reject the "OTHER" topic
        form = self.proto.get_bound_form(args)
        self.assertFalse(form.is_valid())

    def test_keywords(self):
        """
        Keywords are mandatory
        """
        p = Paper.create_by_doi('10.1007/s00268-016-3429-x')
        p.authors_list = [p.authors_list[0]]
        r = self.dry_deposit(p,
            abstract='bla ble bli blo blu',
            topic='SDV',
            depositing_author=0,
            affiliation=128940)
        self.assertEqualOrLog(r.status, 'faked')

    def test_preprint(self):
        """
        Submit a preprint
        """
        oai = OaiPaperSource(endpoint='http://doai.io/oai')
        oai.add_translator(BASEDCTranslator())
        p = oai.create_paper_by_identifier('ftarxivpreprints:oai:arXiv.org:1207.2079', 'base_dc')
        p.authors_list = [p.authors_list[0]]
        r = self.dry_deposit(p,
             abstract='here is my great result',
             topic='SDV',
             depositing_author=0,
             affiliation=128940)
        self.assertEqualOrLog(r.status, 'faked')

    def test_bad_journal_article(self):
        """
        Submit something that pretends to be a journal article,
        but for which we fail to find publication metadata.
        The interface should fall back on something lighter.
        """
        oai = OaiPaperSource(endpoint='http://doai.io/oai')
        oai.add_translator(BASEDCTranslator())
        p = oai.create_paper_by_identifier(
            'ftalborguniv:oai:pure.atira.dk:openaire/30feea10-9c2f-11db-8ed6-000ea68e967b',
            'base_dc')
        p.authors_list = [p.authors_list[0]]
        p.doctype = 'journal-article'
        p.save()
        r = self.dry_deposit(p,
            abstract='hey you, yes you',
            topic='SDV',
            depositing_author=0,
            affiliation=128940)
        self.assertEqualOrLog(r.status, 'faked')

    def test_paper_already_in_hal(self):
        p = get_proaixy_instance().create_paper_by_identifier(
            'ftunivsavoie:oai:HAL:hal-01062241v1', 'base_dc')
        enabled = self.proto.init_deposit(p, self.user)
        self.assertFalse(enabled)

    def test_predict_topic(self):
        cases = [
                ('IBEX: Harvesting Entities from the Web Using Unique Identifiers', 'INFO'),
                ('Global climate change entails many threats and challenges for the majority of crops.', 'SDV'),
                ('', None),
            ]
        for text, topic in cases:
            self.assertEqual(self.proto.predict_topic(text), topic)

    def test_refresh_deposit_status(self):
        # This is the identifier of a paper which should
        # currently be published on HAL preprod
        hal_id = 'hal-01211282'
        # First, fake the deposition of a paper
        p = Paper.create_by_doi('10.1109/lics.2015.37')
        r = OaiRecord.new(source=self.repo.oaisource,
                        identifier='deposition:1:'+hal_id,
                        splash_url='https://hal-preprod.archives-ouvertes.fr/'+hal_id,
                        pdf_url=None,
                        about=p)
        f = UploadedPDF.objects.create(
                user=self.user,
                orig_name='File.pdf',
                file='mediatest/blank.pdf',
                thumbnail='my_thumbnail.png')
        d = DepositRecord.objects.create(
                paper=p,
                oairecord=r,
                repository=self.repo,
                user=self.user,
                status='pending',
                identifier=hal_id,
                upload_type='postprint',
                file=f)
        self.proto.refresh_deposit_status(d)
        self.assertEqual(d.status, 'published')
        self.assertTrue(r.pdf_url)

    def test_get_new_status(self):
        cases = {
            'tel-01584471':'published',
            'hal-01038374':'deleted',
            # the document below should have "pending" status on hal-preprod
            # and may need to be updated if the preprod database is reset
            'hal-01587501':'pending',
        }
        for identifier in cases:
            self.assertEqual(self.proto.get_new_status(identifier),
                            cases[identifier])

    def test_paper_already_in_hal_but_not_in_dissemin(self):
        """
        In this case, Dissemin missed the paper on HAL
        (for some reason) and so the deposit interface was
        enabled. But HAL refuses the deposit! We have to
        give a good error message to the user.
        """
        # this paper is currently in HAL-preprod
        p = Paper.create_by_doi('10.1051/jphys:01975003607-8060700')

        # this is just to make sure that we are depositing with
        # a single author (otherwise, the deposit would fail because
        # we are not providing enough affiliations).
        p.authors_list = [p.authors_list[0]]

        r = self.dry_deposit(p,
            abstract='this is an abstract',
            topic='INFO',
            depositing_author=0,
            affiliation=59704) # ENS

        # Deposit fails: a duplicate is found
        self.assertEqualOrLog(r.status, 'failed')

        # The error message should be specific
        self.assertTrue('already in HAL' in r.message)

    def test_on_behalf_of(self):
        # Set on-behalf-of to some user
        # Currently we are using "test_ws" as deposit account
        preferences = self.proto.get_preferences(self.user)
        preferences.on_behalf_of = 'dissemin_test'
        preferences.save()

        # the DOI here should *not* already exist in HAL
        # so it may need to be changed if the test fails
        p = Paper.create_by_doi('10.1007/978-3-319-63342-8_1')
        p.authors_list = [p.authors_list[0]]
        r = self.dry_deposit(p,
            abstract='this is an abstract',
            topic='INFO',
            depositing_author=0,
            affiliation=59704) # ENS
        self.assertEqualOrLog(r.status, 'faked')