MCPcopy
hub / github.com/django/django / assertJSONEqual

Method assertJSONEqual

django/test/testcases.py:1029–1044  ·  view source on GitHub ↗

Assert 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.

(self, raw, expected_data, msg=None)

Source from the content-addressed store, hash-verified

1027 self.assertInHTML(needle, haystack, count=0, msg_prefix=msg_prefix)
1028
1029 def assertJSONEqual(self, raw, expected_data, msg=None):
1030 """
1031 Assert that the JSON fragments raw and expected_data are equal.
1032 Usual JSON non-significant whitespace rules apply as the heavyweight
1033 is delegated to the json library.
1034 """
1035 try:
1036 data = json.loads(raw)
1037 except json.JSONDecodeError:
1038 self.fail("First argument is not valid JSON: %r" % raw)
1039 if isinstance(expected_data, str):
1040 try:
1041 expected_data = json.loads(expected_data)
1042 except ValueError:
1043 self.fail("Second argument is not valid JSON: %r" % expected_data)
1044 self.assertEqual(data, expected_data, msg=msg)
1045
1046 def assertJSONNotEqual(self, raw, expected_data, msg=None):
1047 """

Calls 1

loadsMethod · 0.45

Tested by

no test coverage detected