async def test_api_async_endpoint(cli, async_app): res = await cli.post( "/path/to/identity", headers=[("Content-Type", "application/json"), ("Accept", "application/json")], data=json_dumps({"data": "toto"}), ) assert res.status == 200 assert res.content_type == "application/json" assert await res.read() == json_dumps("toto").encode()
def test_complex_exception_serializer_round_trip_json(): exception = ComplexExceptionType("NotFound", "the object is missing") json_data = json_dumps({"exception": exception}) actual_data = json_loads(json_data) assert "exception" in actual_data assert type(actual_data["exception"]) == Exception assert str(actual_data["exception"]) == str(exception)
def test_exception_serializer_round_trip_json(): error_message = "unreachable host" json_data = json_dumps({"exception": ConnectionError(error_message)}, ) actual_data = json_loads(json_data) assert "exception" in actual_data assert type(actual_data["exception"]) == ConnectionError assert str(actual_data["exception"]) == error_message
async def test_api_async_nego_default_msgpack(cli): res = await cli.post( "/path/to/identity", headers=[("Content-Type", "application/json")], data=json_dumps({"data": "toto"}), ) assert res.status == 200 assert res.content_type == "application/x-msgpack" assert await res.read() == msgpack_dumps("toto")
def test_json_extra_encoders_mutation(): data = json_dumps({}, extra_encoders=extra_encoders) assert data is not None assert ENCODERS[-1][0] != ExtraType
def test_serializers_encode_native_datetime_json(): dt = datetime.datetime(2015, 1, 1, 12, 4, 42, 231455) with pytest.raises(TypeError, match="datetime"): json_dumps(dt)
def test_serializers_generator_json(): data = json_dumps((i for i in range(5))) assert json_loads(data) == [i for i in range(5)]
def test_serializers_encode_swh_json(): json_str = json_dumps(DATA) actual_data = json.loads(json_str) assert actual_data == ENCODED_DATA
def test_serializers_round_trip_json_extra_types(): expected_original_data = [ExtraType("baz", DATA), "qux"] data = json_dumps(expected_original_data, extra_encoders=extra_encoders) actual_data = json_loads(data, extra_decoders=extra_decoders) assert actual_data == expected_original_data
def test_serializers_round_trip_json(): json_data = json_dumps(DATA) actual_data = json_loads(json_data) assert actual_data == DATA