From 8394e570baf91cff5e5349c0ef06c4f06f06d0b1 Mon Sep 17 00:00:00 2001 From: amatellanes Date: Thu, 17 Apr 2014 11:44:30 +0200 Subject: Fixed #22465 -- New assertion assertJSONNotEqual --- tests/test_utils/tests.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'tests/test_utils') diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index e9f6da7279..1465c2be71 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -542,6 +542,51 @@ class HTMLEqualTests(TestCase): self.assertContains(response, '

Some help text for the title (with unicode ŠĐĆŽćžšđ)

', html=True) +class JSONEqualTests(TestCase): + def test_simple_equal(self): + json1 = '{"attr1": "foo", "attr2":"baz"}' + json2 = '{"attr1": "foo", "attr2":"baz"}' + self.assertJSONEqual(json1, json2) + + def test_simple_equal_unordered(self): + json1 = '{"attr1": "foo", "attr2":"baz"}' + json2 = '{"attr2":"baz", "attr1": "foo"}' + self.assertJSONEqual(json1, json2) + + def test_simple_equal_raise(self): + json1 = '{"attr1": "foo", "attr2":"baz"}' + json2 = '{"attr2":"baz"}' + with self.assertRaises(AssertionError): + self.assertJSONEqual(json1, json2) + + def test_equal_parsing_errors(self): + invalid_json = '{"attr1": "foo, "attr2":"baz"}' + valid_json = '{"attr1": "foo", "attr2":"baz"}' + with self.assertRaises(AssertionError): + self.assertJSONEqual(invalid_json, valid_json) + with self.assertRaises(AssertionError): + self.assertJSONEqual(valid_json, invalid_json) + + def test_simple_not_equal(self): + json1 = '{"attr1": "foo", "attr2":"baz"}' + json2 = '{"attr2":"baz"}' + self.assertJSONNotEqual(json1, json2) + + def test_simple_not_equal_raise(self): + json1 = '{"attr1": "foo", "attr2":"baz"}' + json2 = '{"attr1": "foo", "attr2":"baz"}' + with self.assertRaises(AssertionError): + self.assertJSONNotEqual(json1, json2) + + def test_not_equal_parsing_errors(self): + invalid_json = '{"attr1": "foo, "attr2":"baz"}' + valid_json = '{"attr1": "foo", "attr2":"baz"}' + with self.assertRaises(AssertionError): + self.assertJSONNotEqual(invalid_json, valid_json) + with self.assertRaises(AssertionError): + self.assertJSONNotEqual(valid_json, invalid_json) + + class XMLEqualTests(TestCase): def test_simple_equal(self): xml1 = "" -- cgit v1.3