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)
    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)