Ejemplo n.º 1
0
    def test_assertXmlEquivalentOutputs_namespaces(self):
        """Asserts assertXmlEquivalentOutputs raises when comparison failed.

        Assertion with different namespaces: the namespace URI is the same,
        but the prefix is different. In this case, the two XML are equivalents.

        """
        test_case = XmlTestCase(methodName='assertXmlEquivalentOutputs')

        # Same XML, but with different namespace prefixes
        data = b"""<?xml version="1.0" encoding="UTF-8" ?>
        <root xmlns:foo="mynamespace">
            <foo:tag>foo</foo:tag>
        </root>"""

        expected = b"""<?xml version="1.0" encoding="UTF-8" ?>
        <root xmlns:bar="mynamespace">
            <bar:tag>foo</bar:tag>
        </root>"""

        test_case.assertXmlEquivalentOutputs(data, expected)

        wrong_namespace = b"""<?xml version="1.0" encoding="UTF-8" ?>
        <root xmlns:foo="not_the_same_namespace">
            <foo:tag>foo</foo:tag>
        </root>
        """

        with self.assertRaises(test_case.failureException):
            test_case.assertXmlEquivalentOutputs(wrong_namespace, expected)
Ejemplo n.º 2
0
    def test_assertXmlEquivalentOutputs_namespaces(self):
        """Asserts assertXmlEquivalentOutputs raises when comparison failed.

        Assertion with different namespaces: the namespace URI is the same,
        but the prefix is different. In this case, the two XML are equivalents.

        """
        test_case = XmlTestCase(methodName='assertXmlEquivalentOutputs')

        # Same XML, but with different namespace prefixes
        data = b"""<?xml version="1.0" encoding="UTF-8" ?>
        <root xmlns:foo="mynamespace">
            <foo:tag>foo</foo:tag>
        </root>"""

        expected = b"""<?xml version="1.0" encoding="UTF-8" ?>
        <root xmlns:bar="mynamespace">
            <bar:tag>foo</bar:tag>
        </root>"""

        test_case.assertXmlEquivalentOutputs(data, expected)

        wrong_namespace = b"""<?xml version="1.0" encoding="UTF-8" ?>
        <root xmlns:foo="not_the_same_namespace">
            <foo:tag>foo</foo:tag>
        </root>
        """

        with self.assertRaises(test_case.failureException):
            test_case.assertXmlEquivalentOutputs(wrong_namespace, expected)
Ejemplo n.º 3
0
    def test_assertXmlEquivalentOutputs(self):
        """Asserts assertXmlEquivalentOutputs raises when comparison failed.

        Basic assertion: same document, with different order of attributes,
        text with useless spaces, etc.

        """
        test_case = XmlTestCase(methodName='assertXmlEquivalentOutputs')

        # Same XML (with different spacings placements and attrs order)
        data = b"""<?xml version="1.0" encoding="UTF-8" ?>
        <root>
            <tag foo="bar" bar="foo">foo</tag>
        </root>"""
        expected = b"""<?xml version="1.0" encoding="UTF-8" ?>
        <root><tag bar="foo" foo="bar"> foo </tag></root>"""

        test_case.assertXmlEquivalentOutputs(data, expected)

        # Not the right element given
        wrong_element = b"""<?xml version="1.0" encoding="UTF-8" ?>
        <root>
            <notTag foo="bar" bar="foo">foo</notTag>
        </root>"""

        with self.assertRaises(test_case.failureException):
            test_case.assertXmlEquivalentOutputs(wrong_element, expected)

        # Too many tag elements
        data = b"""<?xml version="1.0" encoding="UTF-8" ?>
        <root>
            <tag foo="bar" bar="foo">foo</tag>
            <tag foo="bar" bar="foo">foo</tag>
        </root>"""

        with self.assertRaises(test_case.failureException):
            test_case.assertXmlEquivalentOutputs(wrong_element, expected)
Ejemplo n.º 4
0
    def test_assertXmlEquivalentOutputs(self):
        """Asserts assertXmlEquivalentOutputs raises when comparison failed.

        Basic assertion: same document, with different order of attributes,
        text with useless spaces, etc.

        """
        test_case = XmlTestCase(methodName='assertXmlEquivalentOutputs')

        # Same XML (with different spacings placements and attrs order)
        data = b"""<?xml version="1.0" encoding="UTF-8" ?>
        <root>
            <tag foo="bar" bar="foo">foo</tag>
        </root>"""
        expected = b"""<?xml version="1.0" encoding="UTF-8" ?>
        <root><tag bar="foo" foo="bar"> foo </tag></root>"""

        test_case.assertXmlEquivalentOutputs(data, expected)

        # Not the right element given
        wrong_element = b"""<?xml version="1.0" encoding="UTF-8" ?>
        <root>
            <notTag foo="bar" bar="foo">foo</notTag>
        </root>"""

        with self.assertRaises(test_case.failureException):
            test_case.assertXmlEquivalentOutputs(wrong_element, expected)

        # Too many tag elements
        data = b"""<?xml version="1.0" encoding="UTF-8" ?>
        <root>
            <tag foo="bar" bar="foo">foo</tag>
            <tag foo="bar" bar="foo">foo</tag>
        </root>"""

        with self.assertRaises(test_case.failureException):
            test_case.assertXmlEquivalentOutputs(wrong_element, expected)