diff options
| author | amatellanes <dev.amatellanes@gmail.com> | 2014-04-17 11:44:30 +0200 |
|---|---|---|
| committer | Loic Bistuer <loic.bistuer@gmail.com> | 2014-04-18 15:11:08 +0700 |
| commit | 8394e570baf91cff5e5349c0ef06c4f06f06d0b1 (patch) | |
| tree | e48a289964cc5f275079aedf21a9daa479e155b8 /django | |
| parent | 9bc377d7d0c33697326172513aac6e8dad58fe96 (diff) | |
Fixed #22465 -- New assertion assertJSONNotEqual
Diffstat (limited to 'django')
| -rw-r--r-- | django/test/testcases.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py index a7986dd028..46237aecd2 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -676,6 +676,11 @@ class SimpleTestCase(unittest.TestCase): msg_prefix + "Couldn't find '%s' in response" % needle) def assertJSONEqual(self, raw, expected_data, msg=None): + """ + Asserts that the JSON fragments raw and expected_data are equal. + Usual JSON non-significant whitespace rules apply as the heavyweight + is delegated to the json library. + """ try: data = json.loads(raw) except ValueError: @@ -687,6 +692,23 @@ class SimpleTestCase(unittest.TestCase): self.fail("Second argument is not valid JSON: %r" % expected_data) self.assertEqual(data, expected_data, msg=msg) + def assertJSONNotEqual(self, raw, expected_data, msg=None): + """ + Asserts that the JSON fragments raw and expected_data are not equal. + Usual JSON non-significant whitespace rules apply as the heavyweight + is delegated to the json library. + """ + 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.assertNotEqual(data, expected_data, msg=msg) + def assertXMLEqual(self, xml1, xml2, msg=None): """ Asserts that two XML snippets are semantically the same. |
