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 /tests/test_utils | |
| parent | 9bc377d7d0c33697326172513aac6e8dad58fe96 (diff) | |
Fixed #22465 -- New assertion assertJSONNotEqual
Diffstat (limited to 'tests/test_utils')
| -rw-r--r-- | tests/test_utils/tests.py | 45 |
1 files changed, 45 insertions, 0 deletions
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, '<p class="help">Some help text for the title (with unicode ŠĐĆŽćžšđ)</p>', 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 = "<elem attr1='a' attr2='b' />" |
