def test_nested_payload(): input_json = \ b""" { "name": "rattan", "a": "value", "c": { "za": "value", "a": "hello" } } """ sorted_json = \ b""" { "a": "value", "c": { "a": "hello", "za": "value" }, "name": "rattan" } """ assert signer.__get_hashed_payload(input_json) == \ signer.__get_hashed_payload(sorted_json)
def test_unordered_payload(): assert signer.__get_hashed_payload(b'{"name": "rattan", "a": "value"}') == \ signer.__get_hashed_payload(b'{"a": "value", "name": "rattan"}')
def test_malformed_payload(): with pytest.raises(ValueError) as excepinfo: signer.__get_hashed_payload(b'{""}') assert excepinfo.type is json.JSONDecodeError
def test_none_payload(): assert signer.__get_hashed_payload(b'{}') == \ signer.__get_hashed_payload(None)
def test_get_hashed_payload(payload, expected_hash): assert signer.__get_hashed_payload(payload) == expected_hash