mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Added assertXML[Not]Equal assertions
This is especially needed to compare XML when hash randomization is on, as attribute order may vary. Refs #17758, #19038. Thanks Taylor Mitchell for the initial patch, and Ian Clelland for review and cleanup.
This commit is contained in:
@@ -450,6 +450,41 @@ class HTMLEqualTests(TestCase):
|
||||
self.assertContains(response, '<p class="help">Some help text for the title (with unicode ŠĐĆŽćžšđ)</p>', html=True)
|
||||
|
||||
|
||||
class XMLEqualTests(TestCase):
|
||||
def test_simple_equal(self):
|
||||
xml1 = "<elem attr1='a' attr2='b' />"
|
||||
xml2 = "<elem attr1='a' attr2='b' />"
|
||||
self.assertXMLEqual(xml1, xml2)
|
||||
|
||||
def test_simple_equal_unordered(self):
|
||||
xml1 = "<elem attr1='a' attr2='b' />"
|
||||
xml2 = "<elem attr2='b' attr1='a' />"
|
||||
self.assertXMLEqual(xml1, xml2)
|
||||
|
||||
def test_simple_equal_raise(self):
|
||||
xml1 = "<elem attr1='a' />"
|
||||
xml2 = "<elem attr2='b' attr1='a' />"
|
||||
with self.assertRaises(AssertionError):
|
||||
self.assertXMLEqual(xml1, xml2)
|
||||
|
||||
def test_simple_not_equal(self):
|
||||
xml1 = "<elem attr1='a' attr2='c' />"
|
||||
xml2 = "<elem attr1='a' attr2='b' />"
|
||||
self.assertXMLNotEqual(xml1, xml2)
|
||||
|
||||
def test_simple_not_equal_raise(self):
|
||||
xml1 = "<elem attr1='a' attr2='b' />"
|
||||
xml2 = "<elem attr2='b' attr1='a' />"
|
||||
with self.assertRaises(AssertionError):
|
||||
self.assertXMLNotEqual(xml1, xml2)
|
||||
|
||||
def test_parsing_errors(self):
|
||||
xml_unvalid = "<elem attr1='a attr2='b' />"
|
||||
xml2 = "<elem attr2='b' attr1='a' />"
|
||||
with self.assertRaises(AssertionError):
|
||||
self.assertXMLNotEqual(xml_unvalid, xml2)
|
||||
|
||||
|
||||
class SkippingExtraTests(TestCase):
|
||||
fixtures = ['should_not_be_loaded.json']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user