Example #1
0
    def test_complex_tree(self):
        tree = etree.fromstring(TEST_TREE)
        gen = xml.XMPPXMLGenerator(self.buf, short_empty_elements=True)
        lxml.sax.saxify(tree, gen)

        tree2 = etree.fromstring(self.buf.getvalue())

        self.assertSubtreeEqual(tree, tree2)
Example #2
0
    def test_assertSubtreeEqual_attr_key_missing(self):
        t1 = etree.fromstring("<foo a='1'/>")
        t2 = etree.fromstring("<foo />")

        with self.assertRaises(AssertionError):
            self.assertSubtreeEqual(t1, t2)

        with self.assertRaises(AssertionError):
            self.assertSubtreeEqual(t1, t2, ignore_surplus_attr=True)
Example #3
0
    def test_assertSubtreeEqual_attr_key_missing(self):
        t1 = etree.fromstring("<foo a='1'/>")
        t2 = etree.fromstring("<foo />")

        with self.assertRaises(AssertionError):
            self.assertSubtreeEqual(t1, t2)

        with self.assertRaises(AssertionError):
            self.assertSubtreeEqual(t1, t2, ignore_surplus_attr=True)
Example #4
0
    def test_assertSubtreeEqual_allow_surplus_child(self):
        t1 = etree.fromstring("<foo />")
        t2 = etree.fromstring("<foo><bar/></foo>")

        self.assertSubtreeEqual(t1, t2, ignore_surplus_children=True)

        t1 = etree.fromstring("<foo><bar/></foo>")
        t2 = etree.fromstring("<foo><bar/><bar/><fnord /></foo>")

        self.assertSubtreeEqual(t1, t2, ignore_surplus_children=True)
Example #5
0
    def test_assertSubtreeEqual_allow_surplus_child(self):
        t1 = etree.fromstring("<foo />")
        t2 = etree.fromstring("<foo><bar/></foo>")

        self.assertSubtreeEqual(t1, t2, ignore_surplus_children=True)

        t1 = etree.fromstring("<foo><bar/></foo>")
        t2 = etree.fromstring("<foo><bar/><bar/><fnord /></foo>")

        self.assertSubtreeEqual(t1, t2, ignore_surplus_children=True)
Example #6
0
    def test_no_duplicate_auto_assignments_of_prefixes(self):
        gen = xml.XMPPXMLGenerator(self.buf)
        gen.startDocument()
        gen.startPrefixMapping("ns0", "uri:foo")
        gen.startElementNS(("uri:bar", "foo"), None, None)
        gen.startElementNS(("uri:foo", "foo"), None, None)
        gen.endElementNS(("uri:foo", "foo"), None)
        gen.endElementNS(("uri:bar", "foo"), None)
        gen.endPrefixMapping("ns0")
        gen.endDocument()

        self.assertSubtreeEqual(
            etree.fromstring("<foo xmlns='uri:bar'>" "<foo xmlns='uri:foo' />" "</foo>"),
            etree.fromstring(self.buf.getvalue()),
        )
Example #7
0
    def test_store_and_retrieve_xml_unregistered(self):
        tree = etree.fromstring('<example xmlns="urn:example:unregistered">'
                                '<payload xmlns="urn:example:unregistered">'
                                'foobar'
                                '</payload>'
                                '</example>')

        query = private_xml.xso.Query(None)
        query.unregistered_payload.append(tree)

        iq = aioxmpp.IQ(
            type_=aioxmpp.IQType.SET,
            payload=query,
        )

        yield from self.client.send(iq)

        query.unregistered_payload[0].clear()

        iq = aioxmpp.IQ(
            type_=aioxmpp.IQType.GET,
            payload=query,
        )

        retrieved = yield from self.client.send(iq)

        self.assertEqual(len(retrieved.unregistered_payload), 1)
        self.assertEqual(retrieved.unregistered_payload[0].tag,
                         "{urn:example:unregistered}example")
        self.assertEqual(len(retrieved.unregistered_payload[0]), 1)
        self.assertEqual(retrieved.unregistered_payload[0][0].tag,
                         "{urn:example:unregistered}payload")
        self.assertEqual(retrieved.unregistered_payload[0][0].text, "foobar")
Example #8
0
    def test_element_path(self):
        el = etree.fromstring("<foo><bar><baz /></bar>"
                              "<subfoo />"
                              "<bar><baz /></bar></foo>")
        baz1 = el[0][0]
        subfoo = el[1]
        baz2 = el[2][0]

        self.assertEqual("/foo", element_path(el))
        self.assertEqual("/foo/bar[0]/baz[0]", element_path(baz1))
        self.assertEqual("/foo/subfoo[0]", element_path(subfoo))
        self.assertEqual("/foo/bar[1]/baz[0]", element_path(baz2))
Example #9
0
    def test_store_and_retrieve_xml_unregistered(self):
        tree = etree.fromstring(
            '<example xmlns="urn:example:unregistered">'
            '<payload xmlns="urn:example:unregistered">'
            'foobar'
            '</payload>'
            '</example>'
        )

        query = private_xml.xso.Query(None)
        query.unregistered_payload.append(tree)

        iq = aioxmpp.IQ(
            type_=aioxmpp.IQType.SET,
            payload=query,
        )

        yield from self.client.send(iq)

        query.unregistered_payload[0].clear()

        iq = aioxmpp.IQ(
            type_=aioxmpp.IQType.GET,
            payload=query,
        )

        retrieved = yield from self.client.send(iq)

        self.assertEqual(len(retrieved.unregistered_payload), 1)
        self.assertEqual(
            retrieved.unregistered_payload[0].tag,
            "{urn:example:unregistered}example"
        )
        self.assertEqual(len(retrieved.unregistered_payload[0]), 1)
        self.assertEqual(
            retrieved.unregistered_payload[0][0].tag,
            "{urn:example:unregistered}payload"
        )
        self.assertEqual(
            retrieved.unregistered_payload[0][0].text,
            "foobar"
        )
Example #10
0
    def test_element_path(self):
        el = etree.fromstring("<foo><bar><baz /></bar>"
                              "<subfoo />"
                              "<bar><baz /></bar></foo>")
        baz1 = el[0][0]
        subfoo = el[1]
        baz2 = el[2][0]

        self.assertEqual(
            "/foo",
            element_path(el))
        self.assertEqual(
            "/foo/bar[0]/baz[0]",
            element_path(baz1))
        self.assertEqual(
            "/foo/subfoo[0]",
            element_path(subfoo))
        self.assertEqual(
            "/foo/bar[1]/baz[0]",
            element_path(baz2))
Example #11
0
    def test_assertSubtreeEqual_text_no_join_text_parts_is_strict(self):
        t1 = etree.fromstring("<foo><a/>text1</foo>")
        t2 = etree.fromstring("<foo>text1<a/></foo>")

        with self.assertRaises(AssertionError):
            self.assertSubtreeEqual(t1, t2, join_text_parts=False)
Example #12
0
    def test_assertSubtreeEqual_text_including_tails(self):
        t1 = etree.fromstring("<foo>t<a/>ext1</foo>")
        t2 = etree.fromstring("<foo>te<a/>xt1</foo>")

        self.assertSubtreeEqual(t1, t2)
Example #13
0
    def test_assertSubtreeEqual_text(self):
        t1 = etree.fromstring("<foo>text1</foo>")
        t2 = etree.fromstring("<foo>text2</foo>")

        with self.assertRaises(AssertionError):
            self.assertSubtreeEqual(t1, t2)
Example #14
0
    def test_assertSubtreeEqual_strict_ordering(self):
        t1 = etree.fromstring("<foo><bar/><baz/></foo>")
        t2 = etree.fromstring("<foo><baz/><bar/></foo>")

        with self.assertRaises(AssertionError):
            self.assertSubtreeEqual(t1, t2, strict_ordering=True)
Example #15
0
    def test_assertSubtreeEqual_text_no_join_text_parts_is_strict(self):
        t1 = etree.fromstring("<foo><a/>text1</foo>")
        t2 = etree.fromstring("<foo>text1<a/></foo>")

        with self.assertRaises(AssertionError):
            self.assertSubtreeEqual(t1, t2, join_text_parts=False)
Example #16
0
    def test_assertSubtreeEqual_attr_value_mismatch_allow_surplus(self):
        t1 = etree.fromstring("<foo a='1'/>")
        t2 = etree.fromstring("<foo a='1' b='2'/>")

        self.assertSubtreeEqual(t1, t2, ignore_surplus_attr=True)
Example #17
0
    def test_assertSubtreeEqual_forbid_reordering_of_same(self):
        t1 = etree.fromstring("<foo><bar a='1' /><bar a='2' /></foo>")
        t2 = etree.fromstring("<foo><bar a='2' /><bar a='1' /></foo>")

        with self.assertRaises(AssertionError):
            self.assertSubtreeEqual(t1, t2)
Example #18
0
    def test_assertSubtreeEqual_allow_relative_reordering(self):
        t1 = etree.fromstring("<foo><bar/><baz/></foo>")
        t2 = etree.fromstring("<foo><baz/><bar/></foo>")

        self.assertSubtreeEqual(t1, t2)
Example #19
0
    def test_assertSubtreeEqual_surplus_child(self):
        t1 = etree.fromstring("<foo><bar/></foo>")
        t2 = etree.fromstring("<foo><bar/><bar/></foo>")

        with self.assertRaises(AssertionError):
            self.assertSubtreeEqual(t1, t2)
Example #20
0
    def test_assertSubtreeEqual_attr_value_mismatch_allow_surplus(self):
        t1 = etree.fromstring("<foo a='1'/>")
        t2 = etree.fromstring("<foo a='1' b='2'/>")

        self.assertSubtreeEqual(t1, t2, ignore_surplus_attr=True)
Example #21
0
    def test_assertSubtreeEqual_attr_value_mismatch(self):
        t1 = etree.fromstring("<foo a='1'/>")
        t2 = etree.fromstring("<foo a='2'/>")

        with self.assertRaises(AssertionError):
            self.assertSubtreeEqual(t1, t2)
Example #22
0
    def test_assertSubtreeEqual_text(self):
        t1 = etree.fromstring("<foo>text1</foo>")
        t2 = etree.fromstring("<foo>text2</foo>")

        with self.assertRaises(AssertionError):
            self.assertSubtreeEqual(t1, t2)
Example #23
0
    def test_assertSubtreeEqual_tag(self):
        t1 = etree.fromstring("<foo />")
        t2 = etree.fromstring("<bar />")

        with self.assertRaisesRegex(AssertionError, "tag mismatch"):
            self.assertSubtreeEqual(t1, t2)
Example #24
0
    def test_assertSubtreeEqual_strict_ordering(self):
        t1 = etree.fromstring("<foo><bar/><baz/></foo>")
        t2 = etree.fromstring("<foo><baz/><bar/></foo>")

        with self.assertRaises(AssertionError):
            self.assertSubtreeEqual(t1, t2, strict_ordering=True)
Example #25
0
    def test_assertSubtreeEqual_tag(self):
        t1 = etree.fromstring("<foo />")
        t2 = etree.fromstring("<bar />")

        with self.assertRaisesRegex(AssertionError, "tag mismatch"):
            self.assertSubtreeEqual(t1, t2)
Example #26
0
    def test_assertSubtreeEqual_allow_relative_reordering(self):
        t1 = etree.fromstring("<foo><bar/><baz/></foo>")
        t2 = etree.fromstring("<foo><baz/><bar/></foo>")

        self.assertSubtreeEqual(t1, t2)
Example #27
0
    def test_assertSubtreeEqual_attr_value_mismatch(self):
        t1 = etree.fromstring("<foo a='1'/>")
        t2 = etree.fromstring("<foo a='2'/>")

        with self.assertRaises(AssertionError):
            self.assertSubtreeEqual(t1, t2)
Example #28
0
    def test_assertSubtreeEqual_forbid_reordering_of_same(self):
        t1 = etree.fromstring("<foo><bar a='1' /><bar a='2' /></foo>")
        t2 = etree.fromstring("<foo><bar a='2' /><bar a='1' /></foo>")

        with self.assertRaises(AssertionError):
            self.assertSubtreeEqual(t1, t2)
Example #29
0
    def test_assertSubtreeEqual_missing_child(self):
        t1 = etree.fromstring("<foo><bar/></foo>")
        t2 = etree.fromstring("<foo />")

        with self.assertRaises(AssertionError):
            self.assertSubtreeEqual(t1, t2)
Example #30
0
    def test_assertSubtreeEqual_text_including_tails(self):
        t1 = etree.fromstring("<foo>t<a/>ext1</foo>")
        t2 = etree.fromstring("<foo>te<a/>xt1</foo>")

        self.assertSubtreeEqual(t1, t2)