Last active
June 11, 2018 21:53
-
-
Save vahedq/9bf15f121b28aa7f1c57e382bfea3ab8 to your computer and use it in GitHub Desktop.
Django TestCase for XML comparison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.test import TestCase | |
from doctest import Example | |
from lxml.doctestcompare import LXMLOutputChecker | |
class XmlTestCase(TestCase): | |
def assertXmlEqual(self, got, want): | |
checker = LXMLOutputChecker() | |
if not checker.check_output(want, got, 0): | |
message = checker.output_difference(Example('', want), got, 0) | |
raise AssertionError(message) | |
# Then use it like this in your django test module. | |
class MyTextModule(XmlTestCase): | |
def test(self): | |
self.assertXmlEqual(xml_str_1, xml_str_2) | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment