Exemple #1
0
    def test_call_GeneralRest_response_empty(self):
        service_config = BrainServiceConfiguration("__PUBLISHEDREST__")
        service_config._classname = 'programytest.services.test_service.MockService'
        brain_config = BrainConfiguration()
        brain_config.services._services['__PUBLISHEDREST__'] = service_config
        ServiceFactory.preload_services(brain_config.services)

        root = TemplateNode()
        node = TemplateSRAIXNode()
        node._host = TemplateWordNode("hostname")
        root.append(node)

        service = ServiceFactory.get_service("__PUBLISHEDREST__")
        service.set_response("")

        self.assertEqual("", node.resolve(self._client_context))

        conversation = self._client_context.bot.get_conversation(
            self._client_context)
        self.assertIsNotNone(conversation)
        question = Question.create_from_text(
            self._client_context, "Hello",
            self._client_context.bot.sentence_splitter)
        conversation.record_dialog(question)
        self.assertIsNotNone(conversation.current_question())

        self.assertEqual("", node.resolve(self._client_context))
Exemple #2
0
    def test_call_CustomService_response_default(self):
        service_config = BrainServiceConfiguration("mock")
        service_config._classname = 'programytest.services.test_service.MockService'
        brain_config = BrainConfiguration()
        brain_config.services._services['mock'] = service_config
        ServiceFactory.preload_services(brain_config.services)

        root = TemplateNode()
        node = TemplateSRAIXNode()
        node._service = "mock"
        node._default = "unknown"
        node.append(TemplateWordNode("Hello"))
        root.append(node)

        service = ServiceFactory.get_service("mock")
        service.set_response("")

        self.assertEqual("unknown", node.resolve(self._client_context))

        conversation = self._client_context.bot.get_conversation(
            self._client_context)
        self.assertIsNotNone(conversation)
        question = Question.create_from_text(
            self._client_context, "Hello",
            self._client_context.bot.sentence_splitter)
        conversation.record_dialog(question)
        self.assertIsNotNone(conversation.current_question())

        self.assertEqual("unknown", node.resolve(self._client_context))
        self.assertEqual("unknown", question.property('__SUBAGENT__.mock'))
Exemple #3
0
    def test_call_PublishedBot_response_default(self):
        service_config = BrainServiceConfiguration("__PUBLISHEDBOT__")
        service_config._classname = 'programytest.services.test_service.MockService'
        brain_config = BrainConfiguration()
        brain_config.services._services['__PUBLISHEDBOT__'] = service_config
        ServiceFactory.preload_services(brain_config.services)

        root = TemplateNode()
        node = TemplateSRAIXNode()
        node._botName = "testbot"
        node._userId = TemplateWordNode('1234567890')
        node._default = "unknown"
        node.append(TemplateWordNode("Hello"))
        root.append(node)

        service = ServiceFactory.get_service("__PUBLISHEDBOT__")
        service.set_response("")

        self.set_collection_botnames()
        self.assertEqual("unknown", node.resolve(self._client_context))

        conversation = self._client_context.bot.get_conversation(
            self._client_context)
        self.assertIsNotNone(conversation)
        question = Question.create_from_text(
            self._client_context, "Hello",
            self._client_context.bot.sentence_splitter)
        conversation.record_dialog(question)
        self.assertIsNotNone(conversation.current_question())

        self.assertEqual("unknown", node.resolve(self._client_context))
        self.assertEqual("unknown",
                         question.property('__SUBAGENT_EXTBOT__.testbot'))
Exemple #4
0
    def test_call_GeneralRest(self):
        service_config = BrainServiceConfiguration("__PUBLISHEDREST__")
        service_config._classname = 'programytest.services.test_service.MockService'
        brain_config = BrainConfiguration()
        brain_config.services._services['__PUBLISHEDREST__'] = service_config
        ServiceFactory.preload_services(brain_config.services)

        root = TemplateNode()
        node = TemplateSRAIXNode()
        node._host = TemplateWordNode("hostname")
        node._method = TemplateWordNode("POST")
        node._query = TemplateWordNode('"userid":"1234567890"')
        node._header = TemplateWordNode('"Content-Type":"application/json"')
        node._body = TemplateWordNode("Hello")
        root.append(node)

        self.assertEqual("asked", node.resolve(self._client_context))

        conversation = self._client_context.bot.get_conversation(
            self._client_context)
        self.assertIsNotNone(conversation)
        question = Question.create_from_text(
            self._client_context, "Hello",
            self._client_context.bot.sentence_splitter)
        conversation.record_dialog(question)
        self.assertIsNotNone(conversation.current_question())

        self.assertEqual("asked", node.resolve(self._client_context))
        self.assertEqual("asked", question.property('__SUBAGENT_BODY__'))
Exemple #5
0
    def test_call_no_CustomService_exists(self):

        root = TemplateNode()

        node = TemplateSRAIXNode()
        node.service = "mock1"
        root.append(node)
        node.append(TemplateWordNode("Hello"))

        with self.assertRaises(Exception):
            node.resolve(self._client_context)
Exemple #6
0
    def test_call_no_service_defined(self):

        root = TemplateNode()

        node = TemplateSRAIXNode()
        root.append(node)
        node.append(TemplateWordNode("Hello"))

        self.assertEqual("", node.resolve(self._client_context))
    def test_call_no_service_defined(self):

        root = TemplateNode()

        node = TemplateSRAIXNode()
        root.append(node)
        node.append(TemplateWordNode("Hello"))

        self.assertEqual("", node.resolve(self._client_context))
Exemple #8
0
    def test_call_no_service_exists(self):

        root = TemplateNode()

        node = TemplateSRAIXNode()
        node.service = "mock"
        root.append(node)
        node.append(TemplateWordNode("Hello"))

        self.assertEqual("", node.resolve(self.bot, self.clientid))
Exemple #9
0
    def test_call_service(self):

        self._client_context.brain.service_handler.add_service("mock", MockService(ServiceConfiguration(service_type='library')))

        root = TemplateNode()

        node = TemplateSRAIXNode()
        node.service = "mock"
        root.append(node)
        node.append(TemplateWordNode("Hello"))

        self.assertEqual("asked", node.resolve(self._client_context))
Exemple #10
0
    def test_call_GeneralRest_only_host(self):
        service_config = BrainServiceConfiguration("__PUBLISHEDREST__")
        service_config._classname = 'programytest.services.test_service.MockService'
        brain_config = BrainConfiguration()
        brain_config.services._services['__PUBLISHEDREST__'] = service_config
        ServiceFactory.preload_services(brain_config.services)

        root = TemplateNode()
        node = TemplateSRAIXNode()
        node._host = TemplateWordNode("hostname")
        root.append(node)

        self.assertEqual("asked", node.resolve(self._client_context))
    def test_call_PublishedBot_topic(self):
        service_config = BrainServiceConfiguration("__PUBLISHEDBOT__")
        service_config._classname = 'programytest.services.test_service.MockService'
        brain_config = BrainConfiguration()
        brain_config.services._services['__PUBLISHEDBOT__'] = service_config

        ServiceFactory.preload_services(brain_config.services)

        root = TemplateNode()
        node = TemplateSRAIXNode()
        node._botId = "testBot"
        node.append(TemplateWordNode("Hello"))
        root.append(node)

        conversation = self._client_context.bot.get_conversation(
            self._client_context)
        conversation.set_property('topic', 'morning')

        self.assertEqual("asked", node.resolve(self._client_context))

        node._topic = TemplateWordNode("evening")
        self.assertEqual("asked", node.resolve(self._client_context))
Exemple #12
0
    def test_call_PublishedBot(self):
        service_config = BrainServiceConfiguration("__PUBLISHEDBOT__")
        service_config._classname = 'programytest.services.test_service.MockService'
        brain_config = BrainConfiguration()
        brain_config.services._services['__PUBLISHEDBOT__'] = service_config
        ServiceFactory.preload_services(brain_config.services)

        root = TemplateNode()
        node = TemplateSRAIXNode()
        node._botName = "testbot"
        node._locale = TemplateWordNode('ja-JP')
        node._time = TemplateWordNode('2019-01-01T00:00:00+09:00')
        node._userId = TemplateWordNode('1234567890')
        node._topic = TemplateWordNode('*')
        node._deleteVariable = TemplateWordNode('false')
        node._metadata = TemplateWordNode('1234567890')
        node._config = TemplateWordNode('{"config":{"logLevel":"debug"}}')
        node.append(TemplateWordNode("Hello"))
        root.append(node)

        self.set_collection_botnames()
        self.assertEqual("asked", node.resolve(self._client_context))

        conversation = self._client_context.bot.get_conversation(
            self._client_context)
        self.assertIsNotNone(conversation)
        question = Question.create_from_text(
            self._client_context, "Hello",
            self._client_context.bot.sentence_splitter)
        conversation.record_dialog(question)
        self.assertIsNotNone(conversation.current_question())

        service = ServiceFactory.get_service("__PUBLISHEDBOT__")
        service.set_response('{"response": "asked"}')

        self.assertEqual("asked", node.resolve(self._client_context))
        self.assertEqual('{"testbot": {"response": "asked"}}',
                         question.property('__SUBAGENT_EXTBOT__'))
    def test_call_PublishedBot_deleteValiables(self):
        service_config = BrainServiceConfiguration("__PUBLISHEDBOT__")
        service_config._classname = 'programytest.services.test_service.MockService'
        brain_config = BrainConfiguration()
        brain_config.services._services['__PUBLISHEDBOT__'] = service_config
        ServiceFactory.preload_services(brain_config.services)

        root = TemplateNode()
        node = TemplateSRAIXNode()
        node._botId = "testBot"
        node._deleteVariable = TemplateWordNode('true')
        node.append(TemplateWordNode("Hello"))
        root.append(node)

        self.assertEqual("asked", node.resolve(self._client_context))
Exemple #14
0
    def test_call_CustomService_response_none(self):
        service_config = BrainServiceConfiguration("mock")
        service_config._classname = 'programytest.services.test_service.MockService'
        brain_config = BrainConfiguration()
        brain_config.services._services['mock'] = service_config
        ServiceFactory.preload_services(brain_config.services)

        root = TemplateNode()
        node = TemplateSRAIXNode()
        node._service = "mock"
        node.append(TemplateWordNode("Hello"))
        root.append(node)

        service = ServiceFactory.get_service("mock")
        service.set_response(None)

        self.assertEqual(None, node.resolve(self._client_context))
    def test_call_PublishedBot_response_none(self):
        service_config = BrainServiceConfiguration("__PUBLISHEDBOT__")
        service_config._classname = 'programytest.services.test_service.MockService'
        brain_config = BrainConfiguration()
        brain_config.services._services['__PUBLISHEDBOT__'] = service_config
        ServiceFactory.preload_services(brain_config.services)

        root = TemplateNode()
        node = TemplateSRAIXNode()
        node._botId = "testBot"
        node.append(TemplateWordNode("Hello"))
        root.append(node)

        service = ServiceFactory.get_service("__PUBLISHEDBOT__")
        service.set_response(None)

        self.assertIsNone(node.resolve(self._client_context))
Exemple #16
0
    def test_call_service(self):

        service_config = BrainServiceConfiguration("mock")
        service_config._classname = 'programytest.services.test_service.MockService'

        brain_config = BrainConfiguration()
        brain_config.services._services['mock'] = service_config

        ServiceFactory.preload_services(brain_config.services)

        root = TemplateNode()

        node = TemplateSRAIXNode()
        node.service = "mock"
        root.append(node)
        node.append(TemplateWordNode("Hello"))

        self.assertEqual("asked", node.resolve(self.bot, self.clientid))
Exemple #17
0
    def test_call_PublishedBot_only_botname(self):
        service_config = BrainServiceConfiguration("__PUBLISHEDBOT__")
        service_config._classname = 'programytest.services.test_service.MockService'
        brain_config = BrainConfiguration()
        brain_config.services._services['__PUBLISHEDBOT__'] = service_config

        ServiceFactory.preload_services(brain_config.services)

        root = TemplateNode()

        node = TemplateSRAIXNode()
        node._botName = "testbot"
        node._userId = TemplateWordNode('1234567890')
        root.append(node)
        node.append(TemplateWordNode("Hello"))

        self.set_collection_botnames()
        self.assertEqual("asked", node.resolve(self._client_context))
Exemple #18
0
    def test_call_service(self):

        service_config = BrainServiceConfiguration("mock")
        service_config._classname = 'programytest.services.test_service.MockService'

        brain_config = BrainConfiguration()
        brain_config.services._services['mock'] = service_config

        ServiceFactory.preload_services(brain_config.services)

        root = TemplateNode()

        node = TemplateSRAIXNode()
        node.service = "mock"
        root.append(node)
        node.append(TemplateWordNode("Hello"))

        self.assertEqual("asked", node.resolve(self._client_context))