Exemple #1
0
    def test_apply_rdf_updates_intime(self):
        config = FileStorageConfiguration()
        config._rdf_storage = FileStoreConfiguration(dirs=[
            os.path.dirname(__file__) + os.sep + "data" + os.sep + "rdfs" +
            os.sep + "text"
        ],
                                                     extension="rdf",
                                                     subdirs=True,
                                                     format="text",
                                                     encoding="utf-8",
                                                     delete_on_start=False)
        tmpdir = os.path.dirname(__file__) + os.sep + "rdf_updates"
        config.rdf_updates_storage._dirs = [tmpdir]
        config.rdf_updates_storage._has_single_file = True

        engine = FileStorageEngine(config)
        engine.initialise()
        rdf_store = FileRDFStore(engine)
        updates_store = FileRDFUpdatesStore(engine)
        filepath = updates_store._updates_filename(
            updates_store._get_storage_path())

        updates_store.empty_updates()
        self.assertFalse(os.path.exists(filepath))

        map_collection = RDFCollection()
        rdf_store.load_all(map_collection)

        updates_store.add_entry("subject1", "predicate1", "object1")
        updates_store.add_entry("subject2", "predicate2", "object2")

        lastDate = datetime.now()
        sleep(1)

        updates_store.add_entry("subject3", "predicate3", "object3")
        updates_store.delete_entry("subject2", None, None)

        updates_store.apply_rdf_updates(map_collection, lastDate)

        self.assertFalse(map_collection.has_subject('SUBJECT1'))
        self.assertFalse(map_collection.has_subject('SUBJECT2'))
        self.assertTrue(map_collection.has_subject('SUBJECT3'))

        updates_store.empty_updates()
        self.assertFalse(os.path.exists(filepath))
Exemple #2
0
    def test_rdf_add_entry(self):
        config = FileStorageConfiguration()
        tmpdir = os.path.dirname(__file__) + os.sep + "rdf_updates"
        config.rdf_updates_storage._dirs = [tmpdir]
        config.rdf_updates_storage._has_single_file = True

        engine = FileStorageEngine(config)
        engine.initialise()
        updates_store = FileRDFUpdatesStore(engine)
        filepath = updates_store._updates_filename(
            updates_store._get_storage_path())

        updates_store.empty_updates()
        self.assertFalse(os.path.exists(filepath))

        updates_store.add_entry("subject", "predicate", "object")

        self.assertTrue(os.path.exists(filepath))

        updates_store.empty_updates()
        self.assertFalse(os.path.exists(filepath))