Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.5.x] Add assertJSONEqual method to TestCase

Backport of 089d9ca from master
  • Loading branch information...
commit 5eba053459272dce908656a5bfca2c6bab2cfc76 1 parent f2a7b52
@clelland clelland authored spookylukey committed
Showing with 12 additions and 0 deletions.
  1. +12 −0 django/test/testcases.py
View
12 django/test/testcases.py
@@ -407,6 +407,18 @@ def assertInHTML(self, needle, haystack, count = None, msg_prefix=''):
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.
Please sign in to comment.
Something went wrong with that request. Please try again.