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._botName = "testbot" node._default = "unknown" 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")) self.assertEqual("testbot", node.botName) root.append(node) self.assertEqual(len(root.children), 1) with self.assertRaises(Exception): node.resolve_to_string(self._client_context) self.assertEqual( '[SRAIX (botName=testbot, default=unknown, locale=ja-JP, ' + 'time=2019-01-01T00:00:00+09:00, userId=1234567890, topic=*, ' + 'deleteVariable=false, metadata=1234567890, ' + 'config={"config":{"logLevel":"debug"}})]', node.to_string())
def test_node_GeneralRest(self): ServiceFactory.clear() root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateSRAIXNode() self.assertIsNotNone(node) node._default = "unknown" node._host = TemplateWordNode("hostname") node._method = TemplateWordNode("POST") node._query = TemplateWordNode('"userid":"1234567890"') node._header = TemplateWordNode('"Content-Type":"application/json"') node._body = TemplateWordNode("Hello") self.assertEqual("hostname", node._host.word) root.append(node) self.assertEqual(len(root.children), 1) with self.assertRaises(Exception): node.resolve_to_string(self._client_context) self.assertEqual( '[SRAIX (host=hostname, default=unknown, method=POST, ' + 'query={"userid":"1234567890"}, header={"Content-Type":"application/json"}, ' + 'body=Hello)]', node.to_string())
def test_node_no_service(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateSRAIXNode() self.assertIsNotNone(node) root.append(node) self.assertEqual(len(root.children), 1) self.assertEqual("[SRAIX ()]", node.to_string())
def test_node_no_service(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateSRAIXNode() self.assertIsNotNone(node) root.append(node) self.assertEqual(len(root.children), 1) self.assertEqual("SRAIX ()", node.to_string())
def test_node_unsupported_attributes(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateSRAIXNode() self.assertIsNotNone(node) node.host = "http://somebot.org" node.botid = "1234567890" node.hint = "The usual" node.apikey = "ABCDEF" node.service = "api" root.append(node) self.assertEqual(len(root.children), 1) self.assertEqual("[SRAIX (service=api)]", node.to_string())
def test_node_unsupported_attributes(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateSRAIXNode() self.assertIsNotNone(node) node.host = "http://somebot.org" node.botid = "1234567890" node.hint = "The usual" node.apikey = "ABCDEF" node.service = "api" root.append(node) self.assertEqual(len(root.children), 1) self.assertEqual("SRAIX (service=api)", node.to_string())
def test_node_CustomService(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateSRAIXNode() self.assertIsNotNone(node) node.service = "api" node._default = "unknown" self.assertEqual("api", node.service) root.append(node) self.assertEqual(len(root.children), 1) with self.assertRaises(Exception): node.resolve_to_string(self._client_context) self.assertEqual("[SRAIX (service=api, default=unknown)]", node.to_string())