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._client_context))
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._client_context))
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)
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))
def parse_sraix_expression(self, expression, branch): sraix_node = TemplateSRAIXNode() branch.children.append(sraix_node) if 'host' in expression.attrib: logging.warning("'host' attrib not supported in sraix, moved to config, see documentation") if 'botid' in expression.attrib: logging.warning("'botid' attrib not supported in sraix, moved to config, see documentation") if 'hint' in expression.attrib: logging.warning("'hint' attrib not supported in sraix, moved to config, see documentation") if 'apikey' in expression.attrib: logging.warning("'apikey' attrib not supported in sraix, moved to config, see documentation") if 'service' in expression.attrib: sraix_node.service = expression.attrib['service'] head_text = self.get_text_from_element(expression) self.parse_text(head_text, sraix_node) for child in expression: if child.tag == 'host': logging.warning("'host' element not supported in sraix, moved to config, see documentation") elif child.tag == 'botid': logging.warning("'botid' element not supported in sraix, moved to config, see documentation") elif child.tag == 'hint': logging.warning("'hint' element not supported in sraix, moved to config, see documentation") elif child.tag == 'apikey': logging.warning("'apikey' element not supported in sraix, moved to config, see documentation") elif child.tag == 'service': sraix_node.service = self.get_text_from_element(child) else: self.parse_tag_expression(child, sraix_node) tail_text = self.get_tail_from_element(child) self.parse_text(tail_text, sraix_node) if sraix_node.service is None: logging.warning("SRAIX node, service missing !")
def test_to_xml_service(self): root = TemplateNode() node = TemplateSRAIXNode() node.service = "api" root.append(node) node.append(TemplateWordNode("Hello")) xml = root.xml_tree(self._client_context) self.assertIsNotNone(xml) xml_str = ET.tostring(xml, "utf-8").decode("utf-8") self.assertEqual('<template><sraix service="api">Hello</sraix></template>', xml_str)
def test_to_xml_service(self): root = TemplateNode() node = TemplateSRAIXNode() node.service = "api" root.append(node) node.append(TemplateWordNode("Hello")) xml = root.xml_tree(self._client_context) self.assertIsNotNone(xml) xml_str = ET.tostring(xml, "utf-8").decode("utf-8") self.assertEqual('<template><sraix service="api">Hello</sraix></template>', xml_str)
def test_node_service(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateSRAIXNode() self.assertIsNotNone(node) node.service = "api" self.assertEqual("api", node.service) root.append(node) self.assertEqual(len(root.children), 1) self.assertEqual("SRAIX (service=api)", node.to_string())
def test_to_xml_CustomService_only_service(self): root = TemplateNode() node = TemplateSRAIXNode() node.service = "api" 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 service="api">Hello</sraix></template>', xml_str)
def test_node_service(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateSRAIXNode() self.assertIsNotNone(node) node.service = "api" self.assertEqual("api", node.service) root.append(node) self.assertEqual(len(root.children), 1) self.assertEqual("[SRAIX (service=api)]", node.to_string())
def test_node(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)
def test_node(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)
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))
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_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))
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())