Пример #1
0
    def test_record_crud_2(self, load_entry_points, app, db, record_xml):
        synchronizer = current_oai_client.providers["uk"].synchronizers["xoai"]
        oai_sync = OAISync(provider_code="uk")
        synchronizer.oai_sync = oai_sync
        oai_identifier = "oai:dspace.cuni.cz:20.500.11956/2623"

        # vytvoření záznamu
        synchronizer.record_crud(oai_identifier=oai_identifier, xml=record_xml)
        db.session.commit()
        oai_rec = OAIRecord.get_record(oai_identifier)
        assert oai_rec is not None

        # smazání záznamu
        synchronizer.record_crud(oai_rec=oai_rec, deleted=True)
        db.session.commit()
        oai_rec2 = OAIRecord.get_record(oai_identifier)
        assert oai_rec == oai_rec2

        # obnovení záznamu
        synchronizer.record_crud(oai_rec=oai_rec,
                                 timestamp='2050-10-22T08:18:08.567698+00:00',
                                 xml=record_xml)
        db.session.commit()
        oai_rec3 = OAIRecord.get_record(oai_identifier)
        assert oai_rec3 is not None
        record = Record.get_record(oai_rec.id)
        assert record is not None
Пример #2
0
 def test_record_crud(self, load_entry_points, app, db, record_xml):
     synchronizer = current_oai_client.providers["uk"].synchronizers["xoai"]
     oai_sync = OAISync(provider_code="uk")
     synchronizer.oai_sync = oai_sync
     oai_identifier = "oai:dspace.cuni.cz:20.500.11956/2623"
     with pytest.raises(
             Exception,
             match="You have to provide oai_rec or oai_identifier"):
         synchronizer.record_crud()
     synchronizer.record_crud(oai_identifier=oai_identifier, xml=record_xml)
     db.session.commit()
     oai_rec = OAIRecord.get_record(oai_identifier)
     assert oai_rec is not None
     synchronizer.record_crud(oai_rec=oai_rec)
     db.session.commit()
     oai_rec2 = OAIRecord.get_record(oai_identifier)
     assert oai_rec == oai_rec2
     timestamp2 = oai_rec2.timestamp
     synchronizer.record_crud(oai_rec=oai_rec,
                              timestamp='2050-10-22T08:18:08.567698+00:00',
                              xml=record_xml)
     db.session.commit()
     oai_rec3 = OAIRecord.get_record(oai_identifier)
     assert oai_rec3.timestamp > timestamp2
     synchronizer.record_crud(oai_rec=oai_rec3, deleted=True)
     db.session.commit()
Пример #3
0
    def test_record_handling(self, load_entry_points, app, db, record_xml):
        synchronizer = current_oai_client.providers["uk"].synchronizers["xoai"]
        oai_sync = OAISync(provider_code="uk")
        db.session.add(oai_sync)
        db.session.commit()
        synchronizer.oai_sync = oai_sync

        synchronizer.record_handling(1, xml=record_xml)
        oai_rec = OAIRecord.get_record(
            oai_identifier="oai:dspace.cuni.cz:20.500.11956/2623")
        record = Record.get_record(id_=oai_rec.id)
        assert record == {'pid': '1', 'title': 'Testovací záznam'}
Пример #4
0
    def test_update_oai_sync_2(self, load_entry_points, app, db, record_xml):
        synchronizer = current_oai_client.providers["uk"].synchronizers["xoai"]
        oai_sync = OAISync(provider_code="uk")
        db.session.add(oai_sync)
        db.session.commit()
        synchronizer.oai_sync = oai_sync
        try:
            raise Exception("Test exception")
        except Exception:
            synchronizer.update_oai_sync("failed")

        res_oai_sync = OAISync.query.get(1)
        assert res_oai_sync.logs is not None
Пример #5
0
 def test_exception_handler(self, load_entry_points, app, db):
     synchronizer = current_oai_client.providers["uk"].synchronizers["xoai"]
     oai_sync = OAISync(provider_code="uk")
     db.session.add(oai_sync)
     db.session.commit()
     synchronizer.oai_sync = oai_sync
     oai_identifier = "oai:dspace.cuni.cz:20.500.11956/2623"
     try:
         raise Exception("Test exception")
     except Exception:
         synchronizer.exception_handler(oai_identifier)
     oai_exc = OAIRecordExc.query.filter_by(id=1).one_or_none()
     print(oai_exc.traceback)
Пример #6
0
def test_get_record(load_entry_points, app, db, record_xml):
    synchronizer = current_oai_client.providers["uk"].synchronizers["xoai"]
    oai_sync = OAISync(provider_code="uk")
    synchronizer.oai_sync = oai_sync
    record = synchronizer.create_or_update(
        "oai:dspace.cuni.cz:20.500.11956/2623",
        '2017-09-11T08:12:53Z',
        xml=record_xml)
    db.session.commit()
    assert record == {'pid': '1', 'title': 'Testovací záznam'}
    oai_rec = OAIRecord.get_record("oai:dspace.cuni.cz:20.500.11956/2623")
    assert oai_rec is not None
    assert isinstance(oai_rec, OAIRecord)
Пример #7
0
    def run(self,
            start_oai: str = None,
            start_id: int = 0,
            break_on_error: bool = True,
            oai_id: Union[str, List[str]] = None,
            overwrite: bool = False,
            only_fetch: bool = False,
            index: str = None):
        """

        :return:
        :rtype:
        """
        if index:
            self._index = index
        self.only_fetch = only_fetch
        self.overwrite = overwrite
        self.restart_counters()
        with db.session.begin_nested():
            self.oai_sync = OAISync(
                provider_code=self.provider_code,
                synchronizer_code=self.name,
                sync_start=arrow.utcnow().
                datetime,  # datetime.datetime.utcnow(),
                status="active",
                purpose="fetch" if only_fetch else "sync")
            db.session.add(self.oai_sync)
        db.session.commit()
        try:
            if oai_id:
                if isinstance(oai_id, str):
                    oai_ids = [oai_id]
                elif isinstance(oai_id, list):
                    oai_ids = oai_id
                else:  # pragma: no cover
                    raise Exception(
                        "OAI identifier must be string or list of strings")
                self.synchronize(identifiers=oai_ids,
                                 break_on_error=break_on_error)
                self.update_oai_sync("ok")
            else:
                self.synchronize(start_oai=start_oai,
                                 start_id=start_id,
                                 break_on_error=break_on_error)
                self.update_oai_sync("ok")
        except:
            self.update_oai_sync("failed")
            raise
        finally:
            db.session.commit()
Пример #8
0
 def test_update_record(self, load_entry_points, app, db, metadata):
     synchronizer = current_oai_client.providers["uk"].synchronizers["xoai"]
     record, id_ = synchronizer.create_record(metadata)
     oai_sync = OAISync(provider_code="uk")
     db.session.add(oai_sync)
     db.session.commit()
     oai_rec = OAIRecord(id=record.id,
                         oai_identifier="oai:example.cz:1",
                         creation_sync_id=oai_sync.id,
                         pid="1",
                         timestamp=datetime.now())
     db.session.add(oai_rec)
     db.session.commit()
     metadata["title"] = "Updated record"
     record2 = synchronizer.update_record(oai_rec, metadata)
     assert record2 == {'title': 'Updated record', 'pid': '1'}
Пример #9
0
    def test_update_oai_sync(self, load_entry_points, app, db, record_xml):
        synchronizer = current_oai_client.providers["uk"].synchronizers["xoai"]
        oai_sync = OAISync(provider_code="uk")
        db.session.add(oai_sync)
        db.session.commit()
        synchronizer.oai_sync = oai_sync

        synchronizer.created = 100
        db.session.commit()
        synchronizer.update_oai_sync("ok")

        res_oai_sync = OAISync.query.get(1)
        print(type(res_oai_sync.sync_end))
        assert res_oai_sync.records_created == 100
        assert res_oai_sync.status == "ok"
        assert isinstance(res_oai_sync.sync_end, datetime)
Пример #10
0
 def test_delete_record(self, load_entry_points, app, db, metadata):
     synchronizer = current_oai_client.providers["uk"].synchronizers["xoai"]
     record, id_ = synchronizer.create_record(metadata)
     oai_sync = OAISync(provider_code="uk")
     db.session.add(oai_sync)
     db.session.commit()
     oai_rec = OAIRecord(id=record.id,
                         oai_identifier="oai:example.cz:1",
                         creation_sync_id=oai_sync.id,
                         pid="1",
                         timestamp=datetime.now())
     db.session.add(oai_rec)
     db.session.commit()
     synchronizer.delete_record(oai_rec)
     with pytest.raises(NoResultFound):
         Record.get_record(oai_rec.id)
     deleted_record = Record.get_record(oai_rec.id, with_deleted=True)
Пример #11
0
 def test_create_or_update_es(self, load_entry_points, app, db, record_xml,
                              index):
     synchronizer = current_oai_client.providers["uk"].synchronizers["xoai"]
     oai_sync = OAISync(provider_code="uk")
     synchronizer.oai_sync = oai_sync
     synchronizer.create_or_update_es(
         "oai:dspace.cuni.cz:20.500.11956/2623",
         xml=record_xml,
         index=index)
     es_record = current_search_client.get(
         id="oai:dspace.cuni.cz:20.500.11956/2623", index=index)
     assert es_record is not None
     synchronizer.create_or_update_es(
         "oai:dspace.cuni.cz:20.500.11956/2623", xml=record_xml)
     es_record_2 = current_search_client.get(
         id="oai:dspace.cuni.cz:20.500.11956/2623", index=index)
     assert es_record_2 is not None
     assert es_record == es_record_2
Пример #12
0
 def test_create_or_update(self, load_entry_points, app, db, record_xml):
     synchronizer = current_oai_client.providers["uk"].synchronizers["xoai"]
     oai_sync = OAISync(provider_code="uk")
     synchronizer.oai_sync = oai_sync
     record = synchronizer.create_or_update(
         "oai:dspace.cuni.cz:20.500.11956/2623",
         '2017-09-11T08:12:53Z',
         xml=record_xml)
     db.session.commit()
     assert record == {'pid': '1', 'title': 'Testovací záznam'}
     oai_rec = OAIRecord.query.filter_by(pid=1).one_or_none()
     record2 = synchronizer.create_or_update(
         "oai:dspace.cuni.cz:20.500.11956/2623",
         '2017-09-11T08:12:53Z',
         xml=record_xml,
         oai_rec=oai_rec)
     assert record2 is None
     new_time_stemp = datetime.utcnow().replace(tzinfo=utc).isoformat()
     record3 = synchronizer.create_or_update(
         "oai:dspace.cuni.cz:20.500.11956/2623",
         new_time_stemp,
         xml=record_xml,
         oai_rec=oai_rec)
     assert record3 == {'pid': '1', 'title': 'Testovací záznam'}