Пример #1
0
    def test_empty_variables(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisVariableStore(engine)

        self.assert_empty_variables(store)
Пример #2
0
    def test_load_logs(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisLogsStore(engine)

        client = TestClient()
        client_context = client.create_client_context("user1")
        conversation = Conversation(client_context)

        error_log = {"error": "logger ERROR log"}
        warning_log = {"warning": "logger WARNING log"}
        info_log = {"info": "logger INFO log"}
        debug_log = {"debug": "logger DEBUG log"}

        conversation.append_log(error_log)
        conversation.append_log(warning_log)
        conversation.append_log(info_log)
        conversation.append_log(debug_log)

        store.store_logs(client_context, conversation)

        logInfo = store.load_logs(client_context)
        self.assertIsNotNone(logInfo)
        logs = logInfo['logs']
        self.assertIsNotNone(logs)
        self.assertEqual(4, len(logs))
        self.assertEqual({"error": "logger ERROR log"}, logs[0])
Пример #3
0
    def test_save_learnf_same_pattern(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisLearnfStore(engine)

        test_client = TestClient()
        client_context = test_client.create_client_context("test1")

        pattern = ET.Element('pattern')
        pattern.text = "HELLO"
        topic = ET.Element('topic')
        topic.text = '*'
        that = ET.Element('that')
        that.text = '*'
        template = TemplateNode()
        template.append(TemplateWordNode("Hello"))

        category = LearnCategory(pattern, topic, that, template)

        is_replace = False
        store.save_learnf(client_context, category, is_replace)

        is_replace = True
        store.save_learnf(client_context, category, is_replace)
    def test_load_duplicates_no_redis(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisDuplicatesStore(engine)

        duplicateInfo = store.load_duplicates()
        self.assertIsNone(duplicateInfo)
    def test_save_duplicates(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisDuplicatesStore(engine)

        duplicates = [["aiml1.xml", "10", "20", "1", "5", "Duplicate_1"]]
        store.save_duplicates(duplicates)
Пример #6
0
    def tests_conversation_storage(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisConversationStore(engine)
        self.assertEqual(store.storage_engine, engine)

        self.assert_conversation_storage(store, can_empty=True, test_load=True)
Пример #7
0
    def tests_odify_conversation(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisConversationStore(engine)
        self.assertEqual(store.storage_engine, engine)

        self.assert_modify_conversation_data(store)
Пример #8
0
    def test_load_errors_no_redis(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisErrorsStore(engine)

        errorInfo = store.load_errors()
        self.assertIsNone(errorInfo)
Пример #9
0
    def test_save_errors(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisErrorsStore(engine)

        errors = [["aiml1.xml", "10", "20", "1", "5", "node", "Error_1"]]
        store.save_errors(errors)
Пример #10
0
    def test_operations(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisConversationStore(engine)

        store.save('TESTKEY', "Hello world")
        self.assertEquals('Hello world', store.get('TESTKEY'))
        store.delete('TESTKEY')
        self.assertEquals(None, store.get('TESTKEY'))
Пример #11
0
    def test_delete_learnf_no_file(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisLearnfStore(engine)

        test_client = TestClient()
        client_context = test_client.create_client_context("test1")

        store.delete_learnf(client_context)
Пример #12
0
    def test_save_braintree_xml_format(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisBraintreeStore(engine)

        test_client = TestClient()
        client_context = test_client.create_client_context("test1")
        pattern_graph = client_context.brain.aiml_parser.pattern_parser

        store.save_braintree(client_context, pattern_graph)
Пример #13
0
    def test_load_logs_no_redis(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisLogsStore(engine)

        client = TestClient()
        client_context = client.create_client_context("user1")

        logs = store.load_logs(client_context)
        self.assertIsNone(logs)
Пример #14
0
    def tests_debug_conversation_no_file(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisConversationStore(engine)
        self.assertEqual(store.storage_engine, engine)

        client = TestClient()
        client_context = client.create_client_context("user1")

        debugInfo = store.debug_conversation_data(client_context)
        self.assertEqual(0, len(debugInfo))
Пример #15
0
    def tests_conversation_storage_no_file(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisConversationStore(engine)
        self.assertEqual(store.storage_engine, engine)

        client = TestClient()
        client_context = client.create_client_context("user1")
        conversation = Conversation(client_context)

        store.load_conversation(client_context, conversation)
        self.assertEqual(0, len(conversation.questions))
Пример #16
0
    def test_save_load_binaries(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisBinariesStore(engine)

        aiml_parser = PretendAimlParser("pretend1")

        store.save_binary(aiml_parser)

        aiml_parser2 = store.load_binary()
        self.assertIsNotNone(aiml_parser2)

        self.assertEqual(aiml_parser2._name, "pretend1")
    def test_load_duplicates(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisDuplicatesStore(engine)

        duplicates = [["aiml1.xml", "10", "20", "1", "5", "Duplicate_1"]]
        store.save_duplicates(duplicates)

        duplicateInfo = store.load_duplicates()
        self.assertIsNotNone(duplicateInfo)
        self.assertIsNotNone(duplicateInfo['duplicates'])
        duplicates = duplicateInfo['duplicates']
        duplicate = duplicates[0]
        self.assertEqual("aiml1.xml", duplicate['file'])
Пример #18
0
    def test_load_errors(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisErrorsStore(engine)

        errors = [["aiml1.xml", "10", "20", "1", "5", "node", "Error_1"]]
        store.save_errors(errors)

        errorInfo = store.load_errors()
        self.assertIsNotNone(errorInfo)
        self.assertIsNotNone(errorInfo['errors'])
        errors = errorInfo['errors']
        error = errors[0]
        self.assertEqual("aiml1.xml", error['file'])
Пример #19
0
    def test_conversations_storage_exception_on_save_load(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = MockRedisConversationStore(engine, fail_write=False, fail_read=False)

        client = TestClient()
        client_context = client.create_client_context("user1")

        conversation1 = Conversation(client_context)

        store.store_conversation(client_context, conversation1)

        conversation2 = Conversation(client_context)

        store.load_conversation(client_context, conversation2)
Пример #20
0
    def test_conversations_storage(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisConversationStore(engine)

        client = TestClient()
        client_context = client.create_client_context("user1")

        conversation1 = Conversation(client_context)

        conversation1.properties['ckey1'] = "cvalue1"
        conversation1.properties['ckey2'] ="cvalue2"

        question1 = Question.create_from_text(client_context, "Hello There")
        question1.sentence(0).response = "Hi"
        question1.sentence(0)._positivity = 0.5
        question1.sentence(0)._subjectivity = 0.6
        question1.properties['qkey1'] = "qvalue1"
        question1.properties['qkey2'] = "qvalue2"

        conversation1.record_dialog(question1)

        store.store_conversation(client_context, conversation1)

        conversation2 = Conversation(client_context)

        store.load_conversation(client_context, conversation2)
        self.assertIsNotNone(conversation2)

        self.assertEqual(conversation2.properties['ckey1'], "cvalue1")
        self.assertEqual(conversation2.properties['ckey2'], "cvalue2")

        self.assertEqual(conversation2.questions[0].sentence(0).response, "Hi")
        self.assertEqual(conversation2.questions[0].sentence(0)._positivity, 0.5)
        self.assertEqual(conversation2.questions[0].sentence(0)._subjectivity, 0.6)

        self.assertEqual(conversation2.questions[0].properties['qkey1'], "qvalue1")
        self.assertEqual(conversation2.questions[0].properties['qkey2'], "qvalue2")

        store.empty()
Пример #21
0
    def test_store_logs(self):
        config = RedisStorageConfiguration()
        engine = RedisStorageEngine(config)
        engine.initialise()
        store = RedisLogsStore(engine)

        client = TestClient()
        client_context = client.create_client_context("user1")
        conversation = Conversation(client_context)

        error_log = {"error": "logger ERROR log"}
        warning_log = {"warning": "logger WARNING log"}
        info_log = {"info": "logger INFO log"}
        debug_log = {"debug": "logger DEBUG log"}

        conversation.append_log(error_log)
        conversation.append_log(warning_log)
        conversation.append_log(info_log)
        conversation.append_log(debug_log)

        store.store_logs(client_context, conversation)
Пример #22
0
 def test_init_with_configuration(self):
     config = RedisStorageConfiguration()
     engine = RedisStorageEngine(config)
     self.assertIsNotNone(engine)
     self.assertIsNotNone(engine.configuration)
Пример #23
0
 def test_initialise_with_password(self):
     config = RedisStorageConfiguration()
     config._password = "******"
     engine = RedisStorageEngine(config)
     engine.initialise()
     self.conversation_asserts(storage_engine=engine)
Пример #24
0
 def test_conversations_without_dropapp(self):
     config = RedisStorageConfiguration()
     config._drop_all_first = False
     engine = RedisStorageEngine(config)
     engine.initialise()
     self.conversation_asserts(storage_engine=engine)
Пример #25
0
 def test_conversations(self):
     config = RedisStorageConfiguration()
     engine = RedisStorageEngine(config)
     engine.initialise()
     self.conversation_asserts(storage_engine=engine)
Пример #26
0
 def test_properties(self):
     config = RedisStorageConfiguration()
     engine = RedisStorageEngine(config)
     engine.initialise()
     self.property_asserts(storage_engine=engine)
Пример #27
0
 def create_engine(self):
     engine = RedisStorageEngine(self)
     engine.initialise()
     return engine
Пример #28
0
 def test_variables(self):
     config = RedisStorageConfiguration()
     engine = RedisStorageEngine(config)
     engine.initialise()
     self.variable_asserts(storage_engine=engine)
Пример #29
0
 def test_initialise(self):
     config = RedisStorageConfiguration()
     engine = RedisStorageEngine(config)
     engine.initialise()
     store = RedisVariableStore(engine)
     self.assertEqual(store.storage_engine, engine)