Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.5.x] Add assertJSONEqual method to TestCase

Backport of 089d9ca from master
  • Loading branch information...
commit 5eba053459272dce908656a5bfca2c6bab2cfc76 1 parent f2a7b52
Ian Clelland authored September 27, 2012 spookylukey committed December 24, 2012

Showing 1 changed file with 12 additions and 0 deletions. Show diff stats Hide diff stats

  1. 12  django/test/testcases.py
12  django/test/testcases.py
@@ -407,6 +407,18 @@ def assertInHTML(self, needle, haystack, count = None, msg_prefix=''):
407 407
             self.assertTrue(real_count != 0,
408 408
                 msg_prefix + "Couldn't find '%s' in response" % needle)
409 409
 
  410
+    def assertJSONEqual(self, raw, expected_data, msg=None):
  411
+        try:
  412
+            data = json.loads(raw)
  413
+        except ValueError:
  414
+            self.fail("First argument is not valid JSON: %r" % raw)
  415
+        if isinstance(expected_data, six.string_types):
  416
+            try:
  417
+                expected_data = json.loads(expected_data)
  418
+            except ValueError:
  419
+                self.fail("Second argument is not valid JSON: %r" % expected_data)
  420
+        self.assertEqual(data, expected_data, msg=msg)
  421
+
410 422
     def assertXMLEqual(self, xml1, xml2, msg=None):
411 423
         """
412 424
         Asserts that two XML snippets are semantically the same.

0 notes on commit 5eba053

Please sign in to comment.
Something went wrong with that request. Please try again.