def test_node_PublishedBot(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateSRAIXNode() self.assertIsNotNone(node) node._botId = "publishedBot" node._botHost = "www.co.jp" node._default = "unknown" node._locale = TemplateWordNode("ja-JP") node._time = TemplateWordNode("2019-01-01:00: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")) self.assertEqual("publishedBot", node.botId) root.append(node) self.assertEqual(len(root.children), 1) with self.assertRaises(Exception): node.resolve_to_string(self._client_context) self.assertEqual( '[SRAIX (botID=publishedBot, host=www.co.jp, default=unknown, locale=ja-JP, ' + 'time=2019-01-01:00:00:00+09:00, userId=1234567890, topic=*, ' + 'deleteVariable=false, metadata=1234567890, ' + 'config={"config":{"logLevel":"debug"}})]', node.to_string())
def test_to_xml_PublishedBot(self): root = TemplateNode() node = TemplateSRAIXNode() node._botId = "publishedBot" node._botHost = "www.co.jp" node._default = "unknown" root.append(node) node._locale = TemplateWordNode("ja-JP") node._time = TemplateWordNode("2019-01-01:00: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")) with self.assertRaises(Exception): node.resolve_to_string(self._client_context) xml = root.xml_tree(self._client_context) self.assertIsNotNone(xml) xml_str = ET.tostring(xml, "utf-8").decode("utf-8") self.assertEqual( '<template><sraix botId="publishedBot" default="unknown" host="www.co.jp">' + '<locale>ja-JP</locale><time>2019-01-01:00:00:00+09:00</time><userId>1234567890</userId>' + '<topic>*</topic><deleteVariable>false</deleteVariable><metadata>1234567890</metadata>' + '<config>{"config":{"logLevel":"debug"}}</config>Hello</sraix></template>', xml_str)
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._botId = "testBot" node._default = "unknown" node.append(TemplateWordNode("Hello")) root.append(node) service = ServiceFactory.get_service("__PUBLISHEDBOT__") 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_EXTBOT__.testBot'))
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))
def test_to_xml_PublishedBot_only_botid(self): root = TemplateNode() node = TemplateSRAIXNode() node._botId = "publishedBot" node.append(TemplateWordNode("Hello")) root.append(node) with self.assertRaises(Exception): node.resolve_to_string(self._client_context) xml = root.xml_tree(self._client_context) self.assertIsNotNone(xml) xml_str = ET.tostring(xml, "utf-8").decode("utf-8") self.assertEqual( '<template><sraix botId="publishedBot">Hello</sraix></template>', xml_str)
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))
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))
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._botId = "testBot" node._locale = TemplateWordNode('ja-JP') node._time = TemplateWordNode('2019-01-01:00: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.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__'))