Esempio n. 1
0
    def test_reload_map(self):
        extension = HotReloadAdminExtension()

        ReloadTestClient.map_files = os.path.dirname(
            __file__) + os.sep + "test_config" + os.sep + "maps1"

        client = ReloadTestClient()
        client_context = client.create_client_context("testid")

        self.assertIsNotNone(client_context.brain.maps)
        self.assertTrue(client_context.brain.maps.contains("animallegs"))
        al_map = client_context.brain.maps.map("animallegs")
        self.assertIsNotNone(al_map)
        self.assertEquals('4', al_map['BUFFALO'])
        al_map['BUFFALO'] = '6'
        self.assertEquals('6', al_map['BUFFALO'])

        result = extension.execute(client_context, "RELOAD MAP ANIMALLEGS")
        self.assertEquals("HOTRELOAD OK", result)

        self.assertIsNotNone(client_context.brain.maps)
        self.assertTrue(client_context.brain.maps.contains("animallegs"))
        al_map = client_context.brain.maps.map("animallegs")
        self.assertIsNotNone(al_map)
        self.assertEquals('4', al_map['BUFFALO'])
Esempio n. 2
0
    def test_reload_aimls(self):
        extension = HotReloadAdminExtension()

        ReloadTestClient.aiml_files = os.path.dirname(
            __file__) + os.sep + "test_config" + os.sep + 'aimls1'

        client = ReloadTestClient()
        client_context = client.create_client_context("testid")

        self.assertEquals(
            "That was test 1",
            client_context.bot.ask_question(client_context, "TEST1"))
        self.assertEquals(
            "That was test 2",
            client_context.bot.ask_question(client_context, "TEST2"))

        client_context.client.configuration.client_configuration.brain_config[
            0].brain_config[0].files._aiml_files._files = [
                os.path.dirname(__file__) + os.sep + "test_config" + os.sep +
                'aimls2'
            ]

        result = extension.execute(client_context, "RELOAD ALL AIML")
        self.assertEquals("HOTRELOAD OK", result)

        self.assertEquals(
            "That was test 3",
            client_context.bot.ask_question(client_context, "TEST3"))
        self.assertEquals(
            "That was test 4",
            client_context.bot.ask_question(client_context, "TEST4"))
Esempio n. 3
0
    def test_reload_rdfs(self):
        extension = HotReloadAdminExtension()

        ReloadTestClient.rdf_files = os.path.dirname(
            __file__) + os.sep + "test_config" + os.sep + "rdfs1"

        client = ReloadTestClient()
        client_context = client.create_client_context("testid")

        self.assertIsNotNone(client_context.brain.rdf)
        self.assertTrue(client_context.brain.rdf.has_subject("ANIMAL"))
        self.assertTrue(client_context.brain.rdf.has_subject("JUPITER"))
        self.assertFalse(client_context.brain.rdf.has_subject("SOUTH"))
        self.assertFalse(client_context.brain.rdf.has_subject("IBM"))

        client_context.client.configuration.client_configuration.brain_config[
            0].brain_config[0].files._rdf_files._files = [
                os.path.dirname(__file__) + os.sep + "test_config" + os.sep +
                "rdfs2"
            ]

        result = extension.execute(client_context, "RELOAD ALL RDFS")
        self.assertEquals("HOTRELOAD OK", result)

        self.assertIsNotNone(client_context.brain.rdf)
        self.assertFalse(client_context.brain.rdf.has_subject("ANIMAL"))
        self.assertFalse(client_context.brain.rdf.has_subject("JUPITER"))
        self.assertTrue(client_context.brain.rdf.has_subject("SOUTH"))
        self.assertTrue(client_context.brain.rdf.has_subject("IBM"))
Esempio n. 4
0
    def test_reload_sets(self):
        extension = HotReloadAdminExtension()

        ReloadTestClient.set_files = os.path.dirname(
            __file__) + os.sep + "test_config" + os.sep + "sets1"

        client = ReloadTestClient()
        client_context = client.create_client_context("testid")

        self.assertIsNotNone(client_context.brain.sets)
        self.assertTrue(client_context.brain.sets.contains("animal"))
        self.assertTrue(client_context.brain.sets.contains("animals"))
        self.assertFalse(client_context.brain.sets.contains("fastfood"))
        self.assertFalse(client_context.brain.sets.contains("food"))

        client_context.client.configuration.client_configuration.brain_config[
            0].brain_config[0].files._set_files._files = [
                os.path.dirname(__file__) + os.sep + "test_config" + os.sep +
                "sets2"
            ]

        result = extension.execute(client_context, "RELOAD ALL SETS")
        self.assertEquals("HOTRELOAD OK", result)

        self.assertIsNotNone(client_context.brain.sets)
        self.assertFalse(client_context.brain.sets.contains("animal"))
        self.assertFalse(client_context.brain.sets.contains("animals"))
        self.assertTrue(client_context.brain.sets.contains("fastfood"))
        self.assertTrue(client_context.brain.sets.contains("food"))
Esempio n. 5
0
    def test_reload_templates(self):
        extension = HotReloadAdminExtension()

        ReloadTestClient.template_nodes = os.path.dirname(
            __file__) + os.sep + "test_config" + os.sep + "pattern_nodes1.conf"

        client = ReloadTestClient()
        client_context = client.create_client_context("testid")

        self.assertTrue(
            client_context.brain.aiml_parser.pattern_parser._pattern_factory.
            exists("word"))

        client_context.brain.aiml_parser.brain.configuration.nodes._pattern_nodes = os.path.dirname(
            __file__) + os.sep + "test_config" + os.sep + "pattern_nodes2.conf"

        result = extension.execute(client_context, "RELOAD PATTERNS")
        self.assertEquals("HOTRELOAD OK", result)

        self.assertFalse(
            client_context.brain.aiml_parser.pattern_parser._pattern_factory.
            exists("word"))
        self.assertTrue(
            client_context.brain.aiml_parser.pattern_parser._pattern_factory.
            exists("word2"))
Esempio n. 6
0
    def test_reload_maps(self):
        extension = HotReloadAdminExtension()

        ReloadTestClient.map_files = os.path.dirname(
            __file__) + os.sep + "test_config" + os.sep + "maps1"

        client = ReloadTestClient()
        client_context = client.create_client_context("testid")

        self.assertIsNotNone(client_context.brain.maps)
        self.assertTrue(client_context.brain.maps.contains("animallegs"))
        self.assertTrue(client_context.brain.maps.contains("animalsounds"))
        self.assertFalse(client_context.brain.maps.contains("state2captial"))
        self.assertFalse(
            client_context.brain.maps.contains("state2largestcity"))

        client_context.client.configuration.client_configuration.brain_config[
            0].brain_config[0].files._map_files._files = [
                os.path.dirname(__file__) + os.sep + "test_config" + os.sep +
                "maps2"
            ]

        result = extension.execute(client_context, "RELOAD ALL MAPS")
        self.assertEquals("HOTRELOAD OK", result)

        self.assertIsNotNone(client_context.brain.maps)
        self.assertFalse(client_context.brain.maps.contains("animallegs"))
        self.assertFalse(client_context.brain.maps.contains("animalsounds"))
        self.assertTrue(client_context.brain.maps.contains("state2capital"))
        self.assertTrue(
            client_context.brain.maps.contains("state2largestcity"))
Esempio n. 7
0
 def test_hotreload_commands(self):
     extension = HotReloadAdminExtension()
     client = ReloadTestClient()
     client_context = client.create_client_context("testid")
     self.assertEquals(
         "RELOAD [DENORMAL|NORMAL|GENDER|PERSON|PERSON2|PROPERTIES|DEFAULTS|REGEX|PATTERNS|TEMPLATES] | [SET|MAP|RDF] NAME | ALL [AIML|MAPS|SETS|RDFS]",
         extension.execute(client_context, "COMMANDS"))
Esempio n. 8
0
    def test_reload_regex(self):
        extension = HotReloadAdminExtension()

        ReloadTestClient.regex_templates = os.path.dirname(
            __file__
        ) + os.sep + "test_config" + os.sep + "regex-templates1.txt"

        client = ReloadTestClient()
        client_context = client.create_client_context("testid")

        self.assertIsNotNone(client_context.brain.regex_templates)
        self.assertIsNotNone(client_context.brain.regex_templates["anything"])
        self.assertEquals(re.compile('^.*$', re.IGNORECASE),
                          client_context.brain.regex_templates["anything"])

        client_context.brain.configuration.files._regex_templates = os.path.dirname(
            __file__
        ) + os.sep + "test_config" + os.sep + "regex-templates2.txt"

        result = extension.execute(client_context, "RELOAD REGEX")
        self.assertEquals("HOTRELOAD OK", result)

        self.assertIsNotNone(client_context.brain.regex_templates)
        self.assertIsNotNone(client_context.brain.regex_templates["anything"])
        self.assertEquals(re.compile('^.2*$', re.IGNORECASE),
                          client_context.brain.regex_templates["anything"])
Esempio n. 9
0
    def test_reload_all(self):
        extension = HotReloadAdminExtension()

        client = ReloadTestClient()
        client_context = client.create_client_context("testid")

        result = extension.execute(client_context, "RELOAD ALL")
        self.assertEquals("HOTRELOAD OK", result)
Esempio n. 10
0
    def test_reload_rdf(self):
        extension = HotReloadAdminExtension()

        ReloadTestClient.rdf_files = os.path.dirname(
            __file__) + os.sep + "test_config" + os.sep + "rdfs1"

        client = ReloadTestClient()
        client_context = client.create_client_context("testid")

        self.assertTrue(client_context.brain.rdf.has_subject('ANTEATER'))
        client_context.brain.rdf.delete_entity('ANTEATER')
        self.assertFalse(client_context.brain.rdf.has_subject('ANTEATER'))

        result = extension.execute(client_context, "RELOAD RDF ANIMAL")
        self.assertEquals("HOTRELOAD OK", result)

        self.assertTrue(client_context.brain.rdf.has_subject('ANTEATER'))
Esempio n. 11
0
    def test_reload_person2(self):
        extension = HotReloadAdminExtension()

        ReloadTestClient.person2 = os.path.dirname(
            __file__) + os.sep + "test_config" + os.sep + "person2_1.txt"

        client = ReloadTestClient()
        client_context = client.create_client_context("testid")

        self.assertIsNotNone(client_context.brain.person2s)
        self.assertTrue(client_context.brain.person2s.has_key(" I was "))
        self.assertFalse(client_context.brain.person2s.has_key(" she was "))

        client_context.brain.configuration.files._person2 = os.path.dirname(
            __file__) + os.sep + "test_config" + os.sep + "person2_2.txt"

        result = extension.execute(client_context, "RELOAD PERSON2")
        self.assertEquals("HOTRELOAD OK", result)

        self.assertIsNotNone(client_context.brain.person2s)
        self.assertTrue(client_context.brain.person2s.has_key(" she was "))
        self.assertFalse(client_context.brain.person2s.has_key(" I was "))
Esempio n. 12
0
    def test_reload_gender(self):
        extension = HotReloadAdminExtension()

        ReloadTestClient.gender = os.path.dirname(
            __file__) + os.sep + "test_config" + os.sep + "gender1.txt"

        client = ReloadTestClient()
        client_context = client.create_client_context("testid")

        self.assertIsNotNone(client_context.brain.genders)
        self.assertTrue(client_context.brain.genders.has_key(" with him "))
        self.assertFalse(client_context.brain.genders.has_key(" to him "))

        client_context.brain.configuration.files._gender = os.path.dirname(
            __file__) + os.sep + "test_config" + os.sep + "gender2.txt"

        result = extension.execute(client_context, "RELOAD GENDER")
        self.assertEquals("HOTRELOAD OK", result)

        self.assertIsNotNone(client_context.brain.genders)
        self.assertTrue(client_context.brain.genders.has_key(" to him "))
        self.assertFalse(client_context.brain.genders.has_key(" to you "))
Esempio n. 13
0
    def test_reload_normal(self):
        extension = HotReloadAdminExtension()

        ReloadTestClient.normal = os.path.dirname(
            __file__) + os.sep + "test_config" + os.sep + "normal1.txt"

        client = ReloadTestClient()
        client_context = client.create_client_context("testid")

        self.assertIsNotNone(client_context.brain.normals)
        self.assertTrue(client_context.brain.normals.has_key("%20"))
        self.assertFalse(client_context.brain.normals.has_key("%2C"))

        client_context.brain.configuration.files._normal = os.path.dirname(
            __file__) + os.sep + "test_config" + os.sep + "normal2.txt"

        result = extension.execute(client_context, "RELOAD NORMAL")
        self.assertEquals("HOTRELOAD OK", result)

        self.assertIsNotNone(client_context.brain.normals)
        self.assertTrue(client_context.brain.normals.has_key("%2C"))
        self.assertFalse(client_context.brain.normals.has_key("%20"))
Esempio n. 14
0
    def test_reload_set(self):
        extension = HotReloadAdminExtension()

        ReloadTestClient.set_files = os.path.dirname(
            __file__) + os.sep + "test_config" + os.sep + "sets1"

        client = ReloadTestClient()
        client_context = client.create_client_context("testid")

        self.assertIsNotNone(client_context.brain.sets)
        self.assertTrue(client_context.brain.sets.contains("animal"))
        set = client_context.brain.sets.set("animal")
        self.assertTrue('BUFFALO' in set)
        del set['BUFFALO']
        self.assertFalse('BUFFALO' in set)

        result = extension.execute(client_context, "RELOAD SET ANIMAL")
        self.assertEquals("HOTRELOAD OK", result)

        self.assertIsNotNone(client_context.brain.sets)
        self.assertTrue(client_context.brain.sets.contains("animal"))
        set = client_context.brain.sets.set("animal")
        self.assertTrue('BUFFALO' in set)
Esempio n. 15
0
    def test_reload_defaults(self):
        extension = HotReloadAdminExtension()

        ReloadTestClient.variables = os.path.dirname(
            __file__) + os.sep + "test_config" + os.sep + "variables1.txt"

        client = ReloadTestClient()
        client_context = client.create_client_context("testid")

        self.assertIsNotNone(client_context.brain.variables)
        self.assertTrue(client_context.brain.variables.has_property("name"))
        self.assertEquals("Y-Bot",
                          client_context.brain.variables.property("name"))

        client_context.brain.configuration.files._variables = os.path.dirname(
            __file__) + os.sep + "test_config" + os.sep + "variables2.txt"

        result = extension.execute(client_context, "RELOAD DEFAULTS")
        self.assertEquals("HOTRELOAD OK", result)

        self.assertIsNotNone(client_context.brain.variables)
        self.assertTrue(client_context.brain.variables.has_property("name"))
        self.assertEquals("Y-Bot2",
                          client_context.brain.variables.property("name"))