Ejemplo n.º 1
0
    def test_get_initial_question_initial_question_srai_match(self):

        bot_config = BotConfiguration()
        self.assertIsNotNone(bot_config)

        bot = MockBot(bot_config)
        self.assertIsNotNone(bot)

        client_context2 = ClientContext(TestClient(), "testid2")
        client_context2._bot = bot
        client_context2._brain = MockBrain(bot, bot.configuration.brain_config[0])
        client_context2._brain._response = "Y DEFAULT RESPONSE"

        self.assertEquals("Y DEFAULT RESPONSE", bot.get_initial_question(client_context2))
Ejemplo n.º 2
0
    def test_get_default_response_default_response_srai_match(self):

        bot_config = BotConfiguration()
        self.assertIsNotNone(bot_config)

        bot_config.default_response_srai = "YDEFAULTRESPONSE"
        bot_config.default_response = "Default response!"

        bot = MockBot(bot_config)
        self.assertIsNotNone(bot)

        client_context2 = ClientContext(TestClient(), "testid2")
        client_context2._bot = bot
        client_context2._brain = MockBrain(bot, bot.configuration.brain_config[0])
        client_context2._brain._response = "Y DEFAULT RESPONSE"

        response = bot.get_default_response(client_context2)
        self.assertIsNotNone(response)
        self.assertEquals("Y DEFAULT RESPONSE", response)
Ejemplo n.º 3
0
    def test_format_message_with_client_context(self):

        client = TestClient()

        bot_config = BotConfiguration()
        bot_config._section_name = "testbot"
        bot = Bot(bot_config, client)

        brain_config = BrainConfiguration()
        brain_config._section_name = "testbrain"
        brain = Brain(bot, brain_config)

        client_context = ClientContext(client, "testuser")
        client_context._bot = bot
        client_context._brain = brain

        msg = YLogger.format_message(client_context, "Test Message")
        self.assertIsNotNone(msg)
        self.assertEquals(
            "[testclient] [testbot] [testbrain] [testuser] - Test Message",
            msg)
Ejemplo n.º 4
0
    def test_bot_with_conversation(self):
        
        bot = Bot(BotConfiguration())
        self.assertIsNotNone(bot)

        self.assertFalse(bot.has_conversation(self._client_context))

        response = bot.ask_question(self._client_context, "hello")
        self.assertIsNotNone(response)
        self.assertTrue(bot.has_conversation(self._client_context))

        response = bot.ask_question(self._client_context, "hello")
        self.assertIsNotNone(response)
        self.assertTrue(bot.has_conversation(self._client_context))

        client_context2 = ClientContext(TestClient(), "testid2")
        client_context2._bot = bot
        client_context2._brain = self._client_context.bot.brain

        response = bot.ask_question(client_context2, "hello")
        self.assertIsNotNone(response)
        self.assertTrue(bot.has_conversation(client_context2))