Exemple #1
0
    def test_to_xml(self):
        root = TemplateNode()
        random = TemplateRandomNode()
        root.append(random)
        random.append(TemplateWordNode("Test1"))
        random.append(TemplateWordNode("Test2"))

        xml = root.xml_tree(self._client_context)
        self.assertIsNotNone(xml)
        xml_str = ET.tostring(xml, "utf-8").decode("utf-8")
        self.assertEqual("<template><random><li>Test1</li><li>Test2</li></random></template>", xml_str)
    def test_to_xml(self):
        root = TemplateNode()
        random = TemplateRandomNode()
        root.append(random)
        random.append(TemplateWordNode("Test1"))
        random.append(TemplateWordNode("Test2"))

        xml = root.xml_tree(self._client_context)
        self.assertIsNotNone(xml)
        xml_str = ET.tostring(xml, "utf-8").decode("utf-8")
        self.assertEqual("<template><random><li>Test1</li><li>Test2</li></random></template>", xml_str)
Exemple #3
0
    def test_node(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        random = TemplateRandomNode()
        random.append(TemplateWordNode("Test1"))
        random.append(TemplateWordNode("Test2"))
        random.append(TemplateWordNode("Test3"))
        self.assertEqual(len(random.children), 3)

        root.append(random)

        resolved = root.resolve(self._client_context)
        self.assertIsNotNone(resolved)
        self.assertOneOf(resolved, ["Test1", "Test2", "Test3"])
Exemple #4
0
    def test_mixednodes(self):
        root = TemplateNode()
        self.assertIsNotNone(root)

        random1 = TemplateRandomNode()
        random1.append(TemplateWordNode("Test1"))
        random1.append(TemplateWordNode("Test2"))
        random1.append(TemplateWordNode("Test3"))
        self.assertEqual(len(random1.children), 3)

        root.append(TemplateWordNode("Hello"))
        root.append(random1)
        root.append(TemplateWordNode("World!"))

        self.assertEqual(len(root.children), 3)

        resolved = root.resolve(self._client_context)
        self.assertIsNotNone(resolved)
        self.assertOneOf(resolved, ["Hello Test1 World!", "Hello Test2 World!", "Hello Test3 World!"])
Exemple #5
0
    def test_multirandom(self):
        root = TemplateNode()
        self.assertIsNotNone(root)

        random1 = TemplateRandomNode()
        random1.append(TemplateWordNode("Test1"))
        random1.append(TemplateWordNode("Test2"))
        self.assertEqual(len(random1.children), 2)

        random2 = TemplateRandomNode()
        random2.append(TemplateWordNode("Test3"))
        random2.append(TemplateWordNode("Test4"))
        self.assertEqual(len(random1.children), 2)

        root.append(random1)
        root.append(random2)

        resolved = root.resolve(self._client_context)
        self.assertIsNotNone(resolved)
        self.assertOneOf(
            resolved,
            ["Test1 Test3", "Test1 Test4", "Test2 Test3", "Test2 Test4"])
    def test_node(self):
        root = TemplateNode()
        self.assertIsNotNone(root)
        self.assertIsNotNone(root.children)
        self.assertEqual(len(root.children), 0)

        random = TemplateRandomNode()
        random.append(TemplateWordNode("Test1"))
        random.append(TemplateWordNode("Test2"))
        random.append(TemplateWordNode("Test3"))
        self.assertEqual(len(random.children), 3)

        root.append(random)

        resolved = root.resolve(self._client_context)
        self.assertIsNotNone(resolved)
        self.assertOneOf(resolved, ["Test1", "Test2", "Test3"])
Exemple #7
0
    def test_mixednodes(self):
        root = TemplateNode()
        self.assertIsNotNone(root)

        random1 = TemplateRandomNode()
        random1.append(TemplateWordNode("Test1"))
        random1.append(TemplateWordNode("Test2"))
        random1.append(TemplateWordNode("Test3"))
        self.assertEqual(len(random1.children), 3)

        root.append(TemplateWordNode("Hello"))
        root.append(random1)
        root.append(TemplateWordNode("World!"))

        self.assertEqual(len(root.children), 3)

        resolved = root.resolve(self._client_context)
        self.assertIsNotNone(resolved)
        self.assertOneOf(
            resolved,
            ["Hello Test1 World!", "Hello Test2 World!", "Hello Test3 World!"])
Exemple #8
0
    def test_multirandom(self):
        root = TemplateNode()
        self.assertIsNotNone(root)

        random1 = TemplateRandomNode()
        random1.append(TemplateWordNode("Test1"))
        random1.append(TemplateWordNode("Test2"))
        self.assertEqual(len(random1.children), 2)

        random2 = TemplateRandomNode()
        random2.append(TemplateWordNode("Test3"))
        random2.append(TemplateWordNode("Test4"))
        self.assertEqual(len(random1.children), 2)

        root.append(random1)
        root.append(random2)

        resolved = root.resolve(self._client_context)
        self.assertIsNotNone(resolved)
        self.assertOneOf(resolved, ["Test1 Test3",
                                    "Test1 Test4",
                                    "Test2 Test3",
                                    "Test2 Test4"])
 def __init__(self):
     TemplateRandomNode.__init__(self)
Exemple #10
0
 def __init__(self):
     TemplateRandomNode.__init__(self)
Exemple #11
0
    def test_nestedrandom(self):
        root = TemplateNode()
        self.assertIsNotNone(root)

        random1 = TemplateRandomNode()
        random1.append(TemplateWordNode("Test1"))
        random1.append(TemplateWordNode("Test2"))
        self.assertEqual(len(random1.children), 2)

        random2 = TemplateRandomNode()
        random2.append(TemplateWordNode("Test3"))
        random2.append(TemplateWordNode("Test4"))
        self.assertEqual(len(random1.children), 2)

        random3 = TemplateRandomNode()
        random3.append(random1)
        random3.append(random1)
        random3.append(random2)

        root.append(random3)

        resolved = root.resolve(self._bot, self._clientid)
        self.assertIsNotNone(resolved)
        self.assertOneOf(resolved, ["Test1", "Test2", "Test3", "Test4"])