Example #1
0
    def test_load(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._person2_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "person2.txt",
            fileformat="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.PERSON2] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.PERSON2] = storage_engine

        collection = Person2Collection()
        self.assertIsNotNone(collection)

        self.assertTrue(collection.load(storage_factory))

        self.assertEqual(collection.personalise_string("I was"),
                         "he or she was")
        self.assertEqual(
            collection.personalise_string("hello he was over there"),
            "hello i was over there")

        self.assertEquals([
            re.compile('(^I WAS | I WAS | I WAS$)', re.IGNORECASE),
            ' HE OR SHE WAS '
        ], collection.person(" I WAS "))
        self.assertEquals(None, collection.person(" I XXX "))
Example #2
0
    def test_load(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._normal_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "normal.txt",
            fileformat="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.NORMAL] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.NORMAL] = storage_engine

        collection = NormalCollection()
        self.assertIsNotNone(collection)

        self.assertTrue(collection.load(storage_factory))

        self.assertEqual(collection.normalise_string("keithsterling.COM"),
                         "keithsterling dot com")

        self.assertEquals([
            re.compile('(^\\.COM|\\.COM|\\.COM$)', re.IGNORECASE), ' DOT COM '
        ], collection.normalise(".COM"))
        self.assertEquals(None, collection.normalise(".XXX"))
Example #3
0
    def test_load(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._person_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "person.txt",
            format="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.PERSON] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.PERSON] = storage_engine

        collection = PersonCollection()
        self.assertIsNotNone(collection)

        collection.load(storage_factory)

        self.assertEqual(collection.personalise_string(None, "with me"),
                         "with you2")
        self.assertEqual(
            collection.personalise_string(None, "Hello are you with me"),
            "Hello am I2 with you2")
    def test_load(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._denormal_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "denormal.txt",
            format="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.DENORMAL] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.DENORMAL] = storage_engine

        collection = DenormalCollection()
        self.assertIsNotNone(collection)

        collection.load(storage_factory)

        self.assertEqual(
            collection.denormalise_string(None, "keithsterling dot com"),
            "keithsterling.com")
        self.assertIsNone(collection.denormalise("dot cox"))
    def test_reload_jp(self):
        storage_factory = StorageFactory()
        tokenizer = TokenizerJP()

        file_store_config = FileStorageConfiguration()
        file_store_config._denormal_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "denormal_jp.txt",
            format="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.DENORMAL] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.DENORMAL] = storage_engine

        collection = DenormalCollection()
        self.assertIsNotNone(collection)

        collection.load(storage_factory)

        self.assertEqual(collection.denormalise_string(tokenizer, "丸1の回答"),
                         "①の回答")
        self.assertIsNone(collection.denormalise("丸"))

        collection.reload(storage_factory)

        self.assertEqual(collection.denormalise_string(tokenizer, "丸1の回答"),
                         "①の回答")
        self.assertIsNone(collection.denormalise("丸"))
Example #6
0
    def add_default_stores(amap):

        sql = SQLStorageConfiguration()
        amap['sqlite'] = {
            'type': 'sql',
            'config': sql.create_sqlstorage_config()
        }

        mongo = MongoStorageConfiguration()
        amap['mongo'] = {
            'type': 'mongo',
            'config': mongo.create_mongostorage_config()
        }

        redis = RedisStorageConfiguration()
        amap['redis'] = {
            'type': 'redis',
            'config': redis.create_redisstorage_config()
        }

        file = FileStorageConfiguration()
        amap['file'] = {
            'type': 'file',
            'config': file.create_filestorage_config()
        }

        logger = LoggerStorageConfiguration()
        amap['logger'] = {
            'type': 'logger',
            'config': logger.create_loggerstorage_config()
        }
Example #7
0
    def test_load_jp(self):
        storage_factory = StorageFactory()
        tokenizer = TokenizerJP()

        file_store_config = FileStorageConfiguration()
        file_store_config._person_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "person_jp.txt",
            format="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.PERSON] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.PERSON] = storage_engine

        collection = PersonCollection()
        self.assertIsNotNone(collection)

        collection.load(storage_factory)

        self.assertEqual(collection.personalise_string(tokenizer, "私が正しい"),
                         "貴方が正しい")
        self.assertEqual(collection.personalise_string(tokenizer, "あなたは変"),
                         "わたしは変")
Example #8
0
    def test_to_yaml_with_defaults(self):

        config = FileStorageConfiguration()

        data = {}
        config.to_yaml(data, defaults=True)

        self.assertEquals(30, len(data.keys()))
Example #9
0
    def test_load_spelling_with_exception(self):
        config = FileStorageConfiguration()
        config._spelling_storage =  FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "spelling" + os.sep + "corpus.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileSpellingStore(engine)

        spelling_checker = NorvigSpellingChecker()
        self.assertFalse(store.load_spelling(spelling_checker))
Example #10
0
    def test_to_yaml_no_defaults(self):

        config = FileStorageConfiguration()

        data = {}
        config.to_yaml(data, defaults=False)

        self.assertEquals(30, len(data.keys()))
        self._assert_storage_map(data, config)
Example #11
0
    def test_load_spelling(self):
        config = FileStorageConfiguration()
        config._spelling_storage =  FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "spelling" + os.sep + "corpus.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileSpellingStore(engine)

        spelling_checker = NorvigSpellingChecker()
        self.assertTrue(store.load_spelling(spelling_checker))

        self.assertEqual("THESE ARE SOME WORDS", spelling_checker.correct("Thise ara sime wards"))
Example #12
0
    def test_reload_from_file_jp(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._sets_storage = FileStoreConfiguration(dirs=[
            os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "sets_jp"
        ])
        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[StorageFactory.SETS] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.SETS] = storage_engine

        collection = SetCollection()
        self.assertIsNotNone(collection)

        collection.load(storage_factory)

        self.assertIsNotNone(collection._sets)
        self.assertEqual(len(collection._sets), 1)

        self.assertIsNotNone(collection._stores)
        self.assertEqual(len(collection._stores), 1)

        self.assertTrue("TEST_SET" in collection._sets)
        self.assertTrue("TEST_SET" in collection._stores)
        self.assertTrue("TEST_SET" in collection._is_cjk)

        self.assertTrue(collection.contains('TEST_SET'))
        self.assertTrue(collection.is_cjk('TEST_SET'))

        aset = collection.set_list('TEST_SET')
        self.assertIsNotNone(aset)
        values = aset['千']
        self.assertIsNotNone(values)
        self.assertEqual(['千葉', '千葉県', '千葉県下'], values)

        collection.reload(storage_factory, "TEST_SET")

        self.assertIsNotNone(collection._sets)
        self.assertEqual(len(collection._sets), 1)

        self.assertIsNotNone(collection._stores)
        self.assertEqual(len(collection._stores), 1)

        self.assertTrue("TEST_SET" in collection._sets)
        self.assertTrue("TEST_SET" in collection._stores)

        self.assertTrue(collection.contains('TEST_SET'))

        values = aset['千']
        self.assertIsNotNone(values)
        self.assertEqual(['千葉', '千葉県', '千葉県下'], values)
    def test_load_postprocessors(self):
        config = FileStorageConfiguration()
        config._postquestionprocessors_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "processors" + os.sep + "postquestionprocessors.conf", fileformat="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FilePostQuestionProcessorsStore(engine)

        collection = ProcessorCollection()
        store.load(collection)

        self.assertEqual(0, len(collection.processors))
Example #14
0
    def test_reload_no_engine(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._maps_storage = FileStoreConfiguration(dirs=[
            os.path.dirname(__file__) + os.sep + "test_files" + os.sep + "maps"
        ])
        collection = MapCollection()
        self.assertIsNotNone(collection)

        self.assertTrue(collection.reload(storage_factory, "TEST_MAP") == 0)
Example #15
0
    def test_load_from_test_dir_no_subdir(self):
        config = FileStorageConfiguration()
        config._rdf_storage = FileStoreConfiguration(dirs=[os.path.dirname(__file__) + os.sep + "data" + os.sep + "rdfs" + os.sep + "text"], extension="rdf", subdirs=False, format="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileRDFStore(engine)

        map_collection = RDFCollection()
        store.load_all(map_collection)

        self.assertTrue(map_collection.contains('ACTIVITY'))
    def test_load_variables(self):
        config = FileStorageConfiguration()
        config._pattern_nodes_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "nodes" + os.sep + "pattern_nodes.conf", format="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FilePatternNodeStore(engine)

        collection = PatternNodeFactory()
        store.load(collection)

        self.assertEqual(12, len(collection.nodes))
        self.assertTrue(collection.exists("zeroormore"))
Example #17
0
    def test_storage_path_multi_paths(self):
        config = FileStorageConfiguration()
        tmpdir = FileStorageConfiguration.get_temp_dir()
        config._learnf_storage = FileStoreConfiguration(dirs=[tmpdir + os.sep + "categories/learnf", tmpdir + os.sep + "categories/learnf2"], extension="aiml",
                                                      subdirs=False, fileformat="xml", encoding="utf-8",
                                                      delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileLearnfStore(engine)

        self.assertEquals('/tmp/categories/learnf', store._get_storage_path())
        self.assertIsInstance(store.get_storage(), FileStoreConfiguration)
Example #18
0
    def test_load_from_file(self):
        config = FileStorageConfiguration()
        config._person_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "person.txt", format="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FilePersonStore(engine)

        person_collection = PersonCollection()
        
        store.load(person_collection)

        self.assertEqual(person_collection.person(" WITH YOU "), [re.compile('(^WITH YOU | WITH YOU | WITH YOU$)', re.IGNORECASE), ' WITH ME2 '])
        self.assertEqual(person_collection.personalise_string("Is he with you"), "Is he with me2")
Example #19
0
    def test_load_all_from_text_file_diff_extension(self):
        config = FileStorageConfiguration()
        file = os.path.dirname(__file__) + os.sep + "data" + os.sep + "categories" + os.sep + "kinghorn.aiml"
        self.assertTrue(os.path.exists(file))
        config._categories_storage = FileStoreConfiguration(file=file, extension="xml", fileformat="xml", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileCategoryStore(engine)

        parser = MockAIMLParser()
        store.load_all(parser)

        self.assertEqual(0, len(parser._parsed_files))
Example #20
0
    def test_load_from_file(self):
        config = FileStorageConfiguration()
        config._person2_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "person2.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FilePerson2Store(engine)

        person2_collection = PersonCollection()
        
        store.load(person2_collection)

        self.assertEqual(person2_collection.person(" I WAS "), [re.compile('(^I WAS | I WAS | I WAS$)', re.IGNORECASE), ' HE OR SHE WAS '])
        self.assertEqual(person2_collection.personalise_string("I was there"), "he or she was there")
Example #21
0
    def test_load_from_file(self):
        config = FileStorageConfiguration()
        config._gender_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "gender.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileGenderStore(engine)

        gender_collection = GenderCollection()
        
        store.load(gender_collection)

        self.assertEqual(gender_collection.gender(" WITH HIM "), [re.compile('(^WITH HIM | WITH HIM | WITH HIM$)', re.IGNORECASE), ' WITH HER '])
        self.assertEqual(gender_collection.genderise_string("This is with him "), "This is with her")
Example #22
0
    def test_load_from_file(self):
        config = FileStorageConfiguration()
        config._normal_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "normal.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileNormalStore(engine)

        normal_collection = NormalCollection()
        
        store.load(normal_collection)

        self.assertEqual(normal_collection.normalise(".COM"), [re.compile('(^\\.COM|\\.COM|\\.COM$)', re.IGNORECASE), ' DOT COM '])
        self.assertEqual(normal_collection.normalise_string("keith.com"), "keith dot com")
Example #23
0
    def test_initialise_without_config_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
                other:
                """, ConsoleConfiguration(), ".")

        file_config = yaml.get_section("files")

        config = FileStorageConfiguration()
        config.load_config_section(yaml, file_config, ".")

        tmpdir = FileStorageConfiguration.get_temp_dir()

        self.assert_object_config(config.categories_storage, dirs=[tmpdir + os.sep + "categories"], extension="aiml", subdirs=True, fileformat="xml", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.learnf_storage, dirs=[tmpdir + os.sep + "categories/learnf"], extension="aiml", subdirs=False, fileformat="xml", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.conversation_storage, dirs=[tmpdir + os.sep + "conversations"], extension="txt", subdirs=False, fileformat="text", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.sets_storage, dirs=[tmpdir + os.sep + "sets"], extension="txt", subdirs=False, fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.maps_storage, dirs=[tmpdir + os.sep + "maps"], extension="txt", subdirs=False, fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.rdf_storage, dirs=[tmpdir + os.sep + "rdfs"], extension="txt", subdirs=True, fileformat="text", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.denormal_storage, file=tmpdir + os.sep + "lookups/denormal.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.normal_storage, file=tmpdir + os.sep + "lookups/normal.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.gender_storage, file=tmpdir + os.sep + "lookups/gender.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.person_storage, file=tmpdir + os.sep + "lookups/person.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.person2_storage, file=tmpdir + os.sep + "lookups/person2.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.regex_storage, file=tmpdir + os.sep + "regex/regex-templates.txt", fileformat="text", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.properties_storage, file=tmpdir + os.sep + "properties/properties.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.defaults_storage, file=tmpdir + os.sep + "properties/defaults.txt", fileformat="text", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.twitter_storage, dirs=[tmpdir + os.sep + "twitter"], extension="txt", subdirs=False, fileformat="text", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.spelling_storage, file=tmpdir + os.sep + "spelling/corpus.txt", fileformat="text", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.license_storage, file=tmpdir + os.sep + "licenses/license.keys", fileformat="text", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.pattern_nodes_storage, file=tmpdir + os.sep + "nodes/pattern_nodes.conf", fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.template_nodes_storage, file=tmpdir + os.sep + "nodes/template_nodes.conf", fileformat="text", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.binaries_storage, file=tmpdir + os.sep + "binaries/binaries.bin", fileformat="binary", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.braintree_storage, file=tmpdir + os.sep + "braintree/braintree.xml", fileformat="xml", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.preprocessors_storage, file=tmpdir + os.sep + "processing/preprocessors.conf", fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.postprocessors_storage, file=tmpdir + os.sep + "processing/postprocessors.conf", fileformat="text", encoding="utf-8", delete_on_start=False)
        self.assert_object_config(config.postquestionprocessors_storage, file=tmpdir + os.sep + "processing/postquestionprocessors.conf", fileformat="text", encoding="utf-8", delete_on_start=False)

        self.assert_object_config(config.usergroups_storage, file=tmpdir + os.sep + "security/usergroups.yaml", fileformat="yaml", encoding="utf-8", delete_on_start=False)
Example #24
0
    def test_load_from_test_dir_no_subdir(self):
        config = FileStorageConfiguration()
        config._maps_storage = FileStoreConfiguration(dirs=[os.path.dirname(__file__) + os.sep + "data" + os.sep + "maps" + os.sep + "text"], extension="txt", subdirs=False, format="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileMapsStore(engine)

        map_collection = MapCollection()
        store.load_all(map_collection)

        self.assertTrue(map_collection.contains('TESTMAP'))
        the_map = map_collection.map('TESTMAP')
        self.assertIsNotNone(the_map)
        self.assertEqual("6", the_map['ANT'])
Example #25
0
    def test_load_all_from_test_dir_no_subdir(self):
        config = FileStorageConfiguration()
        dirs = os.path.dirname(__file__) + os.sep + "data" + os.sep + "categories"
        self.assertTrue(os.path.exists(dirs))
        config._categories_storage = FileStoreConfiguration(dirs=[dirs], extension="aiml", subdirs=False, fileformat="xml", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileCategoryStore(engine)

        parser = MockAIMLParser()
        store.load_all(parser)

        self.assertEqual(1, len(parser._parsed_files))
        self.assertTrue(parser._parsed_files[0].endswith("/kinghorn.aiml"))
Example #26
0
    def test_reload_from_file(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._sets_storage = FileStoreConfiguration(dirs=[
            os.path.dirname(__file__) + os.sep + "test_files" + os.sep + "sets"
        ])
        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[StorageFactory.SETS] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.SETS] = storage_engine

        collection = SetCollection()
        self.assertIsNotNone(collection)

        self.assertTrue(collection.load(storage_factory) > 0)

        self.assertIsNotNone(collection._sets)
        self.assertEqual(len(collection._sets), 1)

        self.assertIsNotNone(collection._stores)
        self.assertEqual(len(collection._stores), 1)

        self.assertTrue("TEST_SET" in collection._sets)
        self.assertTrue("TEST_SET" in collection._stores)

        self.assertTrue(collection.contains('TEST_SET'))

        aset = collection.set('TEST_SET')
        self.assertIsNotNone(aset)
        self.assertTrue(['Air', 'Force', 'blue'] in aset['AIR'])

        self.assertTrue(collection.reload(storage_factory, "TEST_SET") > 0)

        self.assertIsNotNone(collection._sets)
        self.assertEqual(len(collection._sets), 1)

        self.assertIsNotNone(collection._stores)
        self.assertEqual(len(collection._stores), 1)

        self.assertTrue("TEST_SET" in collection._sets)
        self.assertTrue("TEST_SET" in collection._stores)

        self.assertTrue(collection.contains('TEST_SET'))

        self.assertIsNotNone(collection.set('TEST_SET'))
        self.assertTrue(
            ['Air', 'Force', 'blue'] in collection.set('TEST_SET')['AIR'])
    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"))
Example #28
0
    def test_load_users_and_groups(self):
        config = FileStorageConfiguration()
        config._usergroups_storage =  FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "security" + os.sep + "roles.yaml", fileformat="yaml", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileUserGroupStore(engine)

        config = unittest.mock.Mock()
        config.usergroups = "Test"
        usersgroupsauthorisor = BasicUserGroupAuthorisationService(config)
        self.assertTrue(store.load_usergroups(usersgroupsauthorisor))

        self.assertTrue(usersgroupsauthorisor.authorise("console", "admin"))
        with self.assertRaises(Exception):
            self.assertFalse(usersgroupsauthorisor.authorise("offred", "admin"))
Example #29
0
    def test_load_with_exception(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._denormal_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep + "denormal.txt", fileformat="text", extension="txt", encoding="utf-8", delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[StorageFactory.DENORMAL] = storage_engine
        storage_factory._store_to_engine_map[StorageFactory.DENORMAL] = storage_engine

        collection = DenormalCollection()
        self.assertIsNotNone(collection)

        self.assertFalse(collection.load(storage_factory))
Example #30
0
    def test_load_regex(self):
        config = FileStorageConfiguration()
        config._regex_storage =  FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "regex-templates.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileRegexStore(engine)

        collection = RegexTemplatesCollection()
        store.load(collection)

        self.assertIsNotNone(store.get_regular_expressions())
        self.assertTrue(collection.has_regex("anything"))
        self.assertEqual(re.compile('^.*$', re.IGNORECASE), collection.regex("anything"))
        self.assertTrue(collection.has_regex("legion"))
        self.assertFalse(collection.has_regex("XXXXX"))