summaryrefslogtreecommitdiff
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 02:18:56 +0000
commit5eba053459272dce908656a5bfca2c6bab2cfc76 (patch)
treec16590001458be448d5c0792c042d1caa4d8a1e5
parentf2a7b52cfbe51cff2ef6d9f0c7ea05a7f04f33cc (diff)
[1.5.x] Add assertJSONEqual method to TestCase
Backport of 089d9ca1df43fb36eaa857e2d617a94a82c6b906 from master
-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 5ae1316421..bb555fbecb 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.