Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAISets: implement add and remove record #211

Open
ppanero opened this issue Feb 1, 2022 · 0 comments
Open

OAISets: implement add and remove record #211

ppanero opened this issue Feb 1, 2022 · 0 comments

Comments

@ppanero
Copy link
Member

ppanero commented Feb 1, 2022

With the new dynamic implementation of sets, the old add_record and remove_records do not work. They can be implemented but would require to do update the search_pattern.

    def add_record(self, record):
        """Add a record to the OAISet.

        :param record: Record to be added.
        :type record: `invenio_records.api.Record` or derivative.
        """
        record.setdefault('_oai', {}).setdefault('sets', [])

        assert not self.has_record(record)

        record['_oai']['sets'].append(self.spec)

    def remove_record(self, record):
        """Remove a record from the OAISet.

        :param record: Record to be removed.
        :type record: `invenio_records.api.Record` or derivative.
        """
        assert self.has_record(record)

        record['_oai']['sets'] = [
            s for s in record['_oai']['sets'] if s != self.spec]

Old tests:

def test_oaiset_add_remove_record(app):
    """Test the API method for manual record adding."""
    with app.app_context():
        oaiset1 = OAISet(spec='abc')
        rec1 = Record.create({'title_statement': {'title': 'Test1'}})
        rec1.commit()
        # Adding a record to an OAIset should change the record's updated date
        dt1 = rec1.updated
        assert not oaiset1.has_record(rec1)
        oaiset1.add_record(rec1)
        assert 'abc' in rec1['_oai']['sets']
        assert oaiset1.has_record(rec1)
        rec1.commit()
        dt2 = rec1.updated
        assert dt2 > dt1

        oaiset1.remove_record(rec1)
        rec1.commit()
        dt3 = rec1.updated
        assert 'abc' not in rec1['_oai']['sets']
        assert not oaiset1.has_record(rec1)
        assert dt3 > dt2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant