def test_load_from_file(self): storage_factory = StorageFactory() file_store_config = FileStorageConfiguration() file_store_config._properties_storage = FileStoreConfiguration( file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep + "properties.txt", format="text", extension="txt", encoding="utf-8", delete_on_start=False) storage_engine = FileStorageEngine(file_store_config) storage_factory._storage_engines[ StorageFactory.PROPERTIES] = storage_engine storage_factory._store_to_engine_map[ StorageFactory.PROPERTIES] = storage_engine collection = PropertiesCollection() self.assertIsNotNone(collection) collection.load(storage_factory) self.assertTrue(collection.has_property("name")) self.assertFalse(collection.has_property("age")) self.assertEqual("KeiffBot 1.0", collection.property("name")) self.assertIsNone(collection.property("age"))
def test_properties_operations(self): collection = PropertiesCollection() self.assertIsNotNone(collection) collection.add_property("name", "KeiffBot 1.0") collection.add_property("firstname", "Keiff") collection.add_property("middlename", "AIML") collection.add_property("lastname", "BoT") collection.add_property("fullname", "KeiffBot") self.assertTrue(collection.has_property("name")) self.assertFalse(collection.has_property("age")) self.assertEqual("KeiffBot 1.0", collection.property("name")) self.assertIsNone(collection.property("age"))
def test_load_variables(self): config = FileStorageConfiguration() config._defaults_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "defaults.txt", format="text", encoding="utf-8", delete_on_start=False) engine = FileStorageEngine(config) engine.initialise() store = FileDefaultVariablesStore(engine) collection = PropertiesCollection() store.load(collection) self.assertTrue(collection.has_property("var1")) self.assertTrue("val1", collection.property("var1")) self.assertTrue(collection.has_property("var2")) self.assertTrue("val2", collection.property("val2"))