summaryrefslogtreecommitdiff
path: root/django/test/testcases.py
diff options
context:
space:
mode:
authorIan Clelland <ian@fullfactor.com>2012-09-27 16:52:24 -0700
committerLuke Plant <L.Plant.98@cantab.net>2012-12-24 00:18:50 +0000
commit089d9ca1df43fb36eaa857e2d617a94a82c6b906 (patch)
tree617aa1dbc6f614c378512b9d1545e99aad88d823 /django/test/testcases.py
parentdc704516c240011a9aeda17f631ade35c65cda58 (diff)
Add assertJSONEqual method to TestCase
Diffstat (limited to 'django/test/testcases.py')
-rw-r--r--django/test/testcases.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 9e92bf5bb5..6f9bc0e724 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -407,6 +407,18 @@ class SimpleTestCase(ut2.TestCase):
self.assertTrue(real_count != 0,
msg_prefix + "Couldn't find '%s' in response" % needle)
+ def assertJSONEqual(self, raw, expected_data, msg=None):
+ try:
+ data = json.loads(raw)
+ except ValueError:
+ self.fail("First argument is not valid JSON: %r" % raw)
+ if isinstance(expected_data, six.string_types):
+ try:
+ expected_data = json.loads(expected_data)
+ except ValueError:
+ self.fail("Second argument is not valid JSON: %r" % expected_data)
+ self.assertEqual(data, expected_data, msg=msg)
+
def assertXMLEqual(self, xml1, xml2, msg=None):
"""
Asserts that two XML snippets are semantically the same.