Esempio n. 1
0
    def test_node_defaultformat_with_userinfo_locale_US(self):

        userInfo = UserInfo(None, None)
        userInfo.set('__USER_LOCALE__', "en-US")
        userInfo.set('__USER_TIME__', "2019-01-01T00:00:00+0900")
        self._client_context.userInfo = userInfo

        root = TemplateNode()
        node = TemplateDateNode()
        root.append(node)

        dateTime = root.resolve(self._client_context)
        self.assertEqual(dateTime, "Mon Dec 31 10:00:00 2018")
Esempio n. 2
0
    def test_node_defaultformat_with_userinfo_invalid_timeform(self):

        userInfo = UserInfo(None, None)
        userInfo.set('__USER_LOCALE__', "ja-jp")
        userInfo.set('__USER_TIME__', "2019-01-01T00:00:00+09:00")
        self._client_context.userInfo = userInfo

        root = TemplateNode()
        node = TemplateDateNode()
        root.append(node)

        dateTime = root.resolve(self._client_context)
        self.assertRegex(dateTime,
                         TemplateDateNodeTests.DEFAULT_DATETIME_REGEX)
    def test_ask_question_default_userid(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_USERID__", "default_uesrid")
        userInfo.set("__USER_LOCALE__", "ja-JP")
        userInfo.set("__USER_TIME__", "2019-01-01T00:00:00+09:00")
        userInfo.set("__USER_METADATA__", None)
        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 = "PublishedBot"
        service.botHost = None
        service.locale = None
        service.time = None
        service.userId = None
        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": "Hello"}', response)
Esempio n. 4
0
    def test_node_defaultformat_with_userinfo_invalid_locale(self):

        userInfo = UserInfo(None, None)
        userInfo.set('__USER_LOCALE__', "x-x")
        userInfo.set('__USER_TIME__', "2019-01-01T00:00:00+0900")
        self._client_context.userInfo = userInfo

        root = TemplateNode()
        node = TemplateDateNode()
        root.append(node)

        dateTime = root.resolve(self._client_context)
        self.assertEqual(dateTime, "Tue Jan 1 00:00:00 2019")

        userInfo.set('__USER_LOCALE__', "JP")
        dateTime = root.resolve(self._client_context)
        self.assertEqual(dateTime, "Tue Jan 1 00:00:00 2019")