def parse_bot_expression(self, expression, branch): bot_node = TemplateBotNode() branch.children.append(bot_node) name_found = False if 'name' in expression.attrib: node = TemplateNode() name_node = TemplateWordNode(expression.attrib['name']) node.append(name_node) name_found = True bot_node.name = node self.parse_text(self.get_text_from_element(expression), bot_node) for child in expression: if child.tag == 'name': node = TemplateNode() self.parse_text(self.get_text_from_element(child), node) for sub_child in child: self.parse_tag_expression(sub_child, node) self.parse_text(self.get_text_from_element(child), node) bot_node.name = node name_found = True else: self.parse_tag_expression(child, bot_node) self.parse_text(self.get_tail_from_element(child), bot_node) if name_found is False: raise ParserException("Error, name not found", xml_element=expression)
def test_to_xml(self): root = TemplateNode() node = TemplateBotNode() node.name = TemplateWordNode("name") root.append(node) xml = root.xml_tree(self.bot, self.clientid) self.assertIsNotNone(xml) xml_str = ET.tostring(xml, "utf-8").decode("utf-8") self.assertEqual('<template><bot name="name" /></template>', xml_str)
def test_to_xml(self): root = TemplateNode() node = TemplateBotNode() node.name = TemplateWordNode("name") root.append(node) xml = root.xml_tree(self._client_context) self.assertIsNotNone(xml) xml_str = ET.tostring(xml, "utf-8").decode("utf-8") self.assertEqual('<template><bot name="name" /></template>', xml_str)
def test_node_no_default_get(self): self._client_context.brain.configuration.defaults._default_get = None root = TemplateNode() node = TemplateBotNode() node.name = TemplateWordNode("location") root.append(node) result = node.resolve(self._client_context) self.assertIsNotNone(result) self.assertEquals("unknown", result)
def test_node_no_value(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateBotNode() self.assertIsNotNone(node) node.name = TemplateWordNode("location") root.append(node) self.assertEqual(len(root.children), 1) self.bot.brain.properties.add_property("default-property", "unknown") result = node.resolve(self.bot, self.clientid) self.assertIsNotNone(result) self.assertEqual("unknown", result)
def test_node_no_value(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateBotNode() self.assertIsNotNone(node) node.name = TemplateWordNode("location") root.append(node) self.assertEqual(len(root.children), 1) self._client_context.brain.properties.add_property("default-property", "unknown") result = node.resolve(self._client_context) self.assertIsNotNone(result) self.assertEqual("unknown", result)
def test_node(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateBotNode() self.assertIsNotNone(node) node.name = TemplateWordNode("location") root.append(node) self.assertEqual(len(root.children), 1) self.bot.brain.properties.add_property("location", "Scotland") result = node.resolve(self.bot, self.clientid) self.assertIsNotNone(result) self.assertEqual("Scotland", result)
def test_node(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateBotNode() self.assertIsNotNone(node) node.name = TemplateWordNode("location") root.append(node) self.assertEqual(len(root.children), 1) self._client_context.brain.properties.add_property("location", "Scotland") result = node.resolve(self._client_context) self.assertIsNotNone(result) self.assertEqual("Scotland", result)