async def test_can_read_json_data_even_without_content_type_header(): request = Request(b'POST', b'/', Headers(), None) request.extend_body(b'{"hello":"world","foo":false}') request.complete.set() json = await request.json() assert json == {"hello": "world", "foo": False}
async def test_if_read_json_fails_content_type_header_is_checked_non_json_gives_invalid_operation( ): request = Request(b'POST', b'/', Headers([Header(b'Content-Type', b'text/html')]), None) request.extend_body(b'{"hello":') # broken json request.complete.set() with pytest.raises(InvalidOperation): await request.json()
async def test_if_read_json_fails_content_type_header_is_checked_json_gives_bad_request_format( ): request = Request(b'POST', b'/', Headers([Header(b'Content-Type', b'application/json')]), None) request.extend_body(b'{"hello":') # broken json request.complete.set() with pytest.raises(BadRequestFormat): await request.json()