def test_ask_question_exception(self):

        config = BrainServiceConfiguration("__PUBLISHEDBOT__")
        config._host = "test_publishdbot"

        response_data = '{"response": "Hello"}'
        request_api = MockPublishedBotAPI(response=response_data, throw_exception=True)
        service = PublishedBotService(config=config, api=request_api)
        self.assertIsNotNone(service)

        bot_info = PublicBotInfo("https://cotobadesign.co.jp/bots/PublishedBot/ask", 'api_key')

        bot_info._locale = "ja-JP"
        bot_info._time = "2019-01-01T00:00:00+09:00"
        bot_info._topic = "morning"
        bot_info._deleteVariable = True
        bot_info._metadata = "Test Data"
        bot_info._config = '{"logLevel": "debug"}'

        service.botInfo = bot_info
        service.userId = "user00"

        question = "Hello"
        response = service.ask_question(self._client_context, question)
        self.assertEqual('', response)
        self.assertEqual('000', service._status_code)
Esempio n. 2
0
    def test_ask_default_method(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"

        service = GenericRESTService(config=config)
        self.assertIsNotNone(service)
        self.assertEquals(service.method, "GET")
    def test_ask_question_set_parameter(self):

        config = BrainServiceConfiguration("__PUBLISHEDBOT__")
        config._host = "test_publishdbot"

        service = PublishedBotService(config=config)
        self.assertIsNotNone(service)

        bot_info = PublicBotInfo("https://cotobadesign.co.jp/bots/PublishedBot/ask", 'api_key')

        bot_info._locale = "ja-JP"
        bot_info._time = "2019-01-01T00:00:00+09:00"
        bot_info._topic = "morning"
        bot_info._deleteVariable = True
        bot_info._metadata = "Test Data"
        bot_info._config = '{"logLevel": "debug"}'

        service.botInfo = bot_info
        service.userId = "user00"

        self.assertEqual(service.botInfo.url, "https://cotobadesign.co.jp/bots/PublishedBot/ask")
        self.assertEqual(service.botInfo.apikey, 'api_key')
        self.assertEqual(service.botInfo.locale, "ja-JP")
        self.assertEqual(service.botInfo.time, "2019-01-01T00:00:00+09:00")
        self.assertEqual(service.botInfo.topic, "morning")
        self.assertEqual(service.botInfo.deleteVariable, True)
        self.assertEqual(service.botInfo.metadata, "Test Data")
        self.assertEqual(service.botInfo.config, '{"logLevel": "debug"}')

        self.assertEqual(service.userId, "user00")
        self.assertEqual(service.botInfo.header['Content-Type'], "application/json;charset=UTF-8")
        self.assertEqual(service.botInfo.header['x-api-key'], "api_key")
    def test_ask_question(self):

        config = BrainServiceConfiguration("__PUBLISHEDBOT__")
        config._host = "test_publishdbot"

        response_data = '{"response": "Hello"}'
        request_api = MockPublishedBotAPI(response=response_data)
        service = PublishedBotService(config=config, api=request_api)
        self.assertIsNotNone(service)

        bot_info = PublicBotInfo("https://cotobadesign.co.jp/bots/PublishedBot/ask", 'api_key')

        bot_info._locale = None
        bot_info._time = None
        bot_info._topic = None
        bot_info._deleteVariable = None
        bot_info._metadata = None
        bot_info._config = None

        service.botInfo = bot_info
        service.userId = "user00"

        question = "Hello"
        response = service.ask_question(self._client_context, question)
        self.assertEqual('{"response": "Hello"}', response)
        self.assertEqual('200', service._status_code)
Esempio n. 5
0
    def test_ask_default_method(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"

        service = GenericRESTService(config=config)
        self.assertIsNotNone(service)
        self.assertEquals(service.method, "GET")
    def test_ask_question_set_parameter(self):

        config = BrainServiceConfiguration("__PUBLISHEDBOT__")
        config._host = "test_publishdbot"

        service = PublishedBotService(config=config)
        self.assertIsNotNone(service)

        service._botId = "PublishedBot"
        service._botHost = "cotobadesign.co.jp"
        service._locale = "ja-JP"
        service._time = "2019-01-01T00:00:00+09:00"
        service._userId = "user00"
        service._topic = "morning"
        service._deleteVariable = True
        service._metadata = "Test Data"
        service._config = '{"logLevel": "debug"}'

        self.assertEqual(service.botId, "PublishedBot")
        self.assertEqual(service.botHost, "cotobadesign.co.jp")
        self.assertEqual(service.locale, "ja-JP")
        self.assertEqual(service.time, "2019-01-01T00:00:00+09:00")
        self.assertEqual(service.userId, "user00")
        self.assertEqual(service.topic, "morning")
        self.assertEqual(service.deleteVariable, True)
        self.assertEqual(service.metadata, "Test Data")
        self.assertEqual(service.config, '{"logLevel": "debug"}')
    def test_ask_question_exception(self):

        config = BrainServiceConfiguration("__PUBLISHEDBOT__")
        config._host = "test_publishdbot"

        self._client_context.bot.brain.configuration._bot_name = "RequestBot"
        self._client_context.bot.brain.configuration._manager_name = "Bot_API_key"

        response_data = '{"response": "Hello"}'
        request_api = MockPublishedBotAPI(response=response_data,
                                          throw_exception=True)
        service = PublishedBotService(config=config, api=request_api)
        self.assertIsNotNone(service)

        service.botId = "PublishedBot"
        service.botHost = None
        service.locale = None
        service.time = None
        service.userId = "user00"
        service.topic = None
        service.deleteVariable = None
        service.metadata = None
        service.config = None

        question = "Hello"
        response = service.ask_question(self._client_context, question)
        self.assertEqual('', response)
    def test_ask_question_no_botid(self):

        config = BrainServiceConfiguration("__PUBLISHEDBOT__")
        config._host = "test_publishdbot"

        self._client_context.bot.brain.configuration._bot_name = "RequestBot"
        self._client_context.bot.brain.configuration._manager_name = "Bot_API_key"

        userInfo = UserInfo(None, None)
        userInfo.set("__USER_LOCALE__", "ja-JP")
        userInfo.set("__USER_TIME__", "2019-01-01T00:00:00+09:00")
        userInfo.set("__USER_METADATA__", "Test Data")
        self._client_context.userInfo = userInfo

        response_data = '{"response": "Hello"}'
        request_api = MockPublishedBotAPI(response=response_data)
        service = PublishedBotService(config=config, api=request_api)
        self.assertIsNotNone(service)

        service.botId = None
        service.botHost = None
        service.locale = None
        service.time = None
        service.userId = "user00"
        service.topic = None
        service.deleteVariable = None
        service.metadata = None
        service.config = None

        question = "Hello"
        response = service.ask_question(self._client_context, question)
        self.assertEqual('', response)
    def test_ask_question_all_parameter(self):

        config = BrainServiceConfiguration("__PUBLISHEDBOT__")
        config._host = "test_publishdbot"

        self._client_context.bot.brain.configuration._bot_name = "RequestBot"
        self._client_context.bot.brain.configuration._manager_name = "Bot_API_key"

        response_data = '{"response": "Hello"}'
        request_api = MockPublishedBotAPI(response=response_data)
        service = PublishedBotService(config=config, api=request_api)
        self.assertIsNotNone(service)

        service.botId = "PublishedBot"
        service.botHost = "cotobadesign.co.jp"
        service.locale = "ja-JP"
        service.time = "2019-01-01T00:00:00+09:00"
        service.userId = "user00"
        service.topic = "morning"
        service.deleteVariable = True
        service.metadata = "Test Data"
        service.config = '{"logLevel": "debug"}'

        question = "Hello"
        response = service.ask_question(self._client_context, question)
        self.assertEqual('{"response": "Hello"}', response)
Esempio n. 10
0
    def test_init_default_api(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"
        config._method = "GET"

        service = GenericRESTService(config=config)
        self.assertIsNotNone(service)
        self.assertIsInstance(service.api, RestAPI)
Esempio n. 11
0
    def test_init_default_api(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"
        config._method = "GET"

        service = GenericRESTService(config=config)
        self.assertIsNotNone(service)
        self.assertIsInstance(service.api, RestAPI)
Esempio n. 12
0
    def test_ask_question_error(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"
        config._method = "GET"

        service = GenericRESTService(config=config, api=MockRestAPI(500, "Bad thing happened!"))
        self.assertIsNotNone(service)

        self.assertEquals("", service.ask_question(self.bot, "testid", "what is a cat"))
Esempio n. 13
0
    def test_ask_question_delete(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"
        config._method = "DELETE"

        service = GenericRESTService(config=config, api=MockRestAPI())
        self.assertIsNotNone(service)

        self.assertEquals("", service.ask_question(self.bot, "testid", "what is a cat"))
Esempio n. 14
0
    def test_ask_question_error(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"
        config._method = "GET"

        service = GenericRESTService(config=config, api=MockRestAPI(500, "Bad thing happened!"))
        self.assertIsNotNone(service)

        self.assertEquals("", service.ask_question(self._client_context, "what is a cat"))
Esempio n. 15
0
    def test_ask_question_delete(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"
        config._method = "DELETE"

        service = GenericRESTService(config=config, api=MockRestAPI())
        self.assertIsNotNone(service)

        self.assertEquals("", service.ask_question(self._client_context, "what is a cat"))
Esempio n. 16
0
    def test_ask_question_post(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"
        config._method = "POST"

        service = GenericRESTService(config=config, api=MockRestAPI(200, "Post REST response"))
        self.assertIsNotNone(service)

        response = service.ask_question(self.bot, "testid", "what is a cat")
        self.assertEquals("Post REST response", response)
Esempio n. 17
0
    def test_ask_question_post(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"
        config._method = "POST"

        service = GenericRESTService(config=config, api=MockRestAPI(200, "Post REST response"))
        self.assertIsNotNone(service)

        response = service.ask_question(self._client_context, "what is a cat")
        self.assertEquals("Post REST response", response)
Esempio n. 18
0
    def test_ask_question_get(self):
        config = BrainServiceConfiguration("rest")
        config._host = "127.0.0.1"
        config._method = "GET"

        service = GenericRESTService(config=config, api=MockRestAPI(200, "Test REST response"))
        self.assertIsNotNone(service)

        response = service.ask_question(self._client_context, "what is a cat")
        self.assertEqual("Test REST response", response)
    def test_ask_question_none_setting(self):

        config = BrainServiceConfiguration("__PUBLISHEDBOT__")
        config._host = "test_publishdbot"

        response_data = '{"response": "Hello"}'
        request_api = MockPublishedBotAPI(response=response_data)
        service = PublishedBotService(config=config, api=request_api)
        self.assertIsNotNone(service)

        question = "Hello"
        response = service.ask_question(self._client_context, question)
        self.assertEqual('', response)
        self.assertEqual('', service._status_code)
    def test_ask_question_no_parameter(self):

        config = BrainServiceConfiguration("__PUBLISHEDBOT__")
        config._host = "test_publishdbot"

        self._client_context.bot.brain.configuration._bot_name = "RequestBot"
        self._client_context.bot.brain.configuration._manager_name = "Bot_API_key"

        response_data = '{"response": "Hello"}'
        request_api = MockPublishedBotAPI(response=response_data)
        service = PublishedBotService(config=config, api=request_api)
        self.assertIsNotNone(service)

        question = "Hello"
        response = service.ask_question(self._client_context, question)
        self.assertEqual('', response)