def test_to_xml_composite(self): node = TemplateNode() node.append(TemplateWordNode("Word1")) node.append(TemplateIdNode()) srai = TemplateSRAINode() srai.append(TemplateWordNode("Srai1")) node.append(srai) node.append(TemplateWordNode("Word2")) self.assertEqual("Word1 <id /> <srai>Srai1</srai> Word2", node.to_xml(self._client_context))
def test_to_xml(self): root = TemplateNode() node = TemplateSRAINode() 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><srai>Hello</srai></template>", xml_str)
def test_xml_tree_simple_composite(self): node = TemplateNode() node.append(TemplateWordNode("Word1")) node.append(TemplateIdNode()) srai = TemplateSRAINode() srai.append(TemplateWordNode("Srai1")) node.append(srai) node.append(TemplateWordNode("Word2")) xml = node.xml_tree(self._client_context) xml_str = ET.tostring(xml, "utf-8").decode("utf-8") self.assertEqual("<template>Word1 <id /> <srai>Srai1</srai> Word2</template>", xml_str)
def test_node(self): root = TemplateNode() self.assertIsNotNone(root) self.assertIsNotNone(root.children) self.assertEqual(len(root.children), 0) node = TemplateSRAINode() self.assertIsNotNone(node) root.append(node) self.assertEqual(len(root.children), 1) node.append(TemplateWordNode("Hello")) self.assertEqual(len(node.children), 1) self._client_context.bot.response = "Hiya" self.assertEqual(root.resolve(self._client_context), "Hiya")
def __init__(self): TemplateSRAINode.__init__(self)