def test_check_enhance_after_index_receiver_when_record_not_provided(
        isolated_app):
    json_rec = {
        "titles": [
            {
                "title": "Some title"
            },
        ],
        "$schema":
        "https://qa.inspirehep.net/schemas/records/hep.json",
        "authors": [{
            "uuid": "e4110d73-5f9e-46a5-b7d8-668d727a3acf",
            "full_name": "Raczka, P.A.",
        }],
        "citeable":
        True,
        "abstracts": [{
            "value": "Abstract value"
        }],
        "control_number":
        425592,
    }
    with pytest.raises(MissingInspireRecordError) as exc:
        after_record_update.send(isolated_app, json=json_rec, record=None)
    assert str(exc.value) == "Record is not InspireRecord!"
Beispiel #2
0
    def edit(self, pid=None):
        """Edit deposit."""
        pid = pid or self.pid

        def _edit(record):
            """Update selected keys."""
            data = record.dumps()
            # Keep current record revision for merging.
            data['_deposit']['pid']['revision_id'] = record.revision_id
            data['_deposit']['status'] = 'draft'
            data['$schema'] = self.build_deposit_schema(record)
            return data

        with db.session.begin_nested():
            before_record_update.send(self)

            record_pid, record = self.fetch_published()
            assert PIDStatus.REGISTERED == record_pid.status
            assert record['_deposit'] == self['_deposit']

            self.model.json = _edit(record)

            flag_modified(self.model, 'json')
            db.session.merge(self.model)

        after_record_update.send(self)
        return self.__class__(self.model.json, model=self.model)
def test_check_enhance_after_index_receiver_when_record_not_provided(isolated_app):
    json_rec = {
        "titles": [
            {
                "title": "Some title"
            },
        ],
        "$schema": "https://qa.inspirehep.net/schemas/records/hep.json",
        "authors": [
            {
                "uuid": "e4110d73-5f9e-46a5-b7d8-668d727a3acf",
                "full_name": "Raczka, P.A.",
            }
        ],
        "citeable": True,
        "abstracts": [
            {
                "value": "Abstract value"
            }
        ],
        "control_number": 425592,
    }
    with pytest.raises(MissingInspireRecordError) as exc:
        after_record_update.send(
            isolated_app,
            json=json_rec,
            record=None
        )
    assert str(exc.value) == "Record is not InspireRecord!"
def test_check_enhance_after_index_receiver_when_sender_is_not_a_record(
        isolated_app):
    json_rec = {
        "titles": [
            {
                "title": "Some title"
            },
        ],
        "$schema":
        "https://qa.inspirehep.net/schemas/records/hep.json",
        "authors": [{
            "uuid": "e4110d73-5f9e-46a5-b7d8-668d727a3acf",
            "full_name": "Raczka, P.A.",
        }],
        "citeable":
        True,
        "abstracts": [{
            "value": "Abstract value"
        }],
        "control_number":
        425592,
    }
    record = TestRecordMetadata.create_from_kwargs(
        json=json_rec).inspire_record
    after_record_update.send(isolated_app, record=record)

    assert 'citation_count' in record.model._enhanced_record
Beispiel #5
0
    def edit(self, pid=None):
        """Edit deposit."""
        pid = pid or self.pid

        if 'published' != self['_deposit']['status']:
            raise PIDInvalidAction()

        def _edit(record):
            """Update selected keys."""
            data = record.dumps()
            # Keep current record revision for merging.
            data['_deposit']['pid']['revision_id'] = record.revision_id
            data['_deposit']['status'] = 'draft'
            data['$schema'] = self.build_deposit_schema(record)
            return data

        with db.session.begin_nested():
            before_record_update.send(self)

            record_pid, record = self.fetch_published()
            assert PIDStatus.REGISTERED == record_pid.status
            assert record['_deposit'] == self['_deposit']

            self.model.json = _edit(record)

            flag_modified(self.model, 'json')
            db.session.merge(self.model)

        after_record_update.send(self)
        return self.__class__(self.model.json, model=self.model)
def test_check_enhance_after_index_receiver_when_sender_is_not_a_record(isolated_app):
    json_rec = {
        "titles": [
            {
                "title": "Some title"
            },
        ],
        "$schema": "https://qa.inspirehep.net/schemas/records/hep.json",
        "authors": [
            {
                "uuid": "e4110d73-5f9e-46a5-b7d8-668d727a3acf",
                "full_name": "Raczka, P.A.",
            }
        ],
        "citeable": True,
        "abstracts": [
            {
                "value": "Abstract value"
            }
        ],
        "control_number": 425592,
    }
    record = TestRecordMetadata.create_from_kwargs(json=json_rec).inspire_record
    after_record_update.send(
        isolated_app,
        record=record
    )

    assert 'citation_count' in record.model._enhanced_record
Beispiel #7
0
    def discard(self, pid=None):
        """Discard deposit changes."""
        pid = pid or self.pid

        with db.session.begin_nested():
            before_record_update.send(self)

            _, record = self.fetch_published()
            self.model.json = record.model.json
            self.model.json['$schema'] = self.build_deposit_schema(record)

            flag_modified(self.model, 'json')
            db.session.merge(self.model)

        after_record_update.send(self)
        return self.__class__(self.model.json, model=self.model)
Beispiel #8
0
    def discard(self, pid=None):
        """Discard deposit changes."""
        pid = pid or self.pid

        with db.session.begin_nested():
            before_record_update.send(self)

            _, record = self.fetch_published()
            self.model.json = record.model.json
            self.model.json['$schema'] = self.build_deposit_schema(record)

            flag_modified(self.model, 'json')
            db.session.merge(self.model)

        after_record_update.send(self)
        return self.__class__(self.model.json, model=self.model)
Beispiel #9
0
    def edit(self, pid=None):
        """Edit deposit.

        #. The signal :data:`invenio_records.signals.before_record_update`
           is sent before the edit execution.

        #. The following meta information are saved inside the deposit:

        .. code-block:: python

            deposit['_deposit']['pid'] = record.revision_id
            deposit['_deposit']['status'] = 'draft'
            deposit['$schema'] = deposit_schema_from_record_schema

        #. The signal :data:`invenio_records.signals.after_record_update` is
            sent after the edit execution.

        #. The deposit index is updated.

        Status required: `published`.

        .. note:: the process fails if the pid has status
            :attr:`invenio_pidstore.models.PIDStatus.REGISTERED`.

        :param pid: Force a pid object. (Default: ``None``)
        :returns: A new Deposit object.
        """
        pid = pid or self.pid

        with db.session.begin_nested():
            before_record_update.send(current_app._get_current_object(),
                                      record=self)

            record_pid, record = self.fetch_published()
            assert PIDStatus.REGISTERED == record_pid.status
            assert record['_deposit'] == self['_deposit']

            self.model.json = self._prepare_edit(record)

            flag_modified(self.model, 'json')
            db.session.merge(self.model)

        after_record_update.send(current_app._get_current_object(),
                                 record=self)
        return self.__class__(self.model.json, model=self.model)
Beispiel #10
0
    def edit(self, pid=None):
        """Edit deposit."""
        pid = pid or self.pid

        with db.session.begin_nested():
            before_record_update.send(self)

            record_pid, record = self.fetch_published()
            assert PIDStatus.REGISTERED == record_pid.status
            assert record['_deposit'] == self['_deposit']

            self.model.json = self._prepare_edit(record)

            flag_modified(self.model, 'json')
            db.session.merge(self.model)

        after_record_update.send(self)
        return self.__class__(self.model.json, model=self.model)
Beispiel #11
0
    def edit(self, pid=None):
        """Edit deposit.

        #. The signal :data:`invenio_records.signals.before_record_update`
           is sent before the edit execution.

        #. The following meta information are saved inside the deposit:

        .. code-block:: python

            deposit['_deposit']['pid'] = record.revision_id
            deposit['_deposit']['status'] = 'draft'
            deposit['$schema'] = deposit_schema_from_record_schema

        #. The signal :data:`invenio_records.signals.after_record_update` is
            sent after the edit execution.

        #. The deposit index is updated.

        Status required: `published`.

        .. note:: the process fails if the pid has status
            :attr:`invenio_pidstore.models.PIDStatus.REGISTERED`.

        :param pid: Force a pid object. (Default: ``None``)
        :returns: A new Deposit object.
        """
        pid = pid or self.pid

        with db.session.begin_nested():
            before_record_update.send(self)

            record_pid, record = self.fetch_published()
            assert PIDStatus.REGISTERED == record_pid.status
            assert record['_deposit'] == self['_deposit']

            self.model.json = self._prepare_edit(record)

            flag_modified(self.model, 'json')
            db.session.merge(self.model)

        after_record_update.send(self)
        return self.__class__(self.model.json, model=self.model)
Beispiel #12
0
    def discard(self, pid=None):
        """Discard deposit changes.

        #. The signal :data:`invenio_records.signals.before_record_update` is
            sent before the edit execution.

        #. It restores the last published version.

        #. The following meta information are saved inside the deposit:

        .. code-block:: python

            deposit['$schema'] = deposit_schema_from_record_schema

        #. The signal :data:`invenio_records.signals.after_record_update` is
            sent after the edit execution.

        #. The deposit index is updated.

        Status required: ``'draft'``.

        :param pid: Force a pid object. (Default: ``None``)
        :returns: A new Deposit object.
        """
        pid = pid or self.pid

        with db.session.begin_nested():
            before_record_update.send(current_app._get_current_object(),
                                      record=self)

            _, record = self.fetch_published()
            self.model.json = deepcopy(record.model.json)
            self.model.json['$schema'] = self.build_deposit_schema(record)

            flag_modified(self.model, 'json')
            db.session.merge(self.model)

        after_record_update.send(current_app._get_current_object(),
                                 record=self)
        return self.__class__(self.model.json, model=self.model)
Beispiel #13
0
    def discard(self, pid=None):
        """Discard deposit changes.

        #. The signal :data:`invenio_records.signals.before_record_update` is
            sent before the edit execution.

        #. It restores the last published version.

        #. The following meta information are saved inside the deposit:

        .. code-block:: python

            deposit['$schema'] = deposit_schema_from_record_schema

        #. The signal :data:`invenio_records.signals.after_record_update` is
            sent after the edit execution.

        #. The deposit index is updated.

        Status required: ``'draft'``.

        :param pid: Force a pid object. (Default: ``None``)
        :returns: A new Deposit object.
        """
        pid = pid or self.pid

        with db.session.begin_nested():
            before_record_update.send(self)

            _, record = self.fetch_published()
            self.model.json = deepcopy(record.model.json)
            self.model.json['$schema'] = self.build_deposit_schema(record)

            flag_modified(self.model, 'json')
            db.session.merge(self.model)

        after_record_update.send(self)
        return self.__class__(self.model.json, model=self.model)