async def test_json_response_parsing(): """Test json response parsing.""" response = HttpResponse() response._set_response_initial(b'HTTP/1.1 200 OK\r\n') response._set_header('content-type', 'application/json; charset=utf-8') response.body = b'{"foo": "bar"}' assert (await response.json()) == {'foo': 'bar'}
def test_encoding_from_header(): """Test use encoder from header.""" response = HttpResponse() response._set_response_initial(b'HTTP/1.1 200 OK\r\n') response._set_header('content-type', 'text/html; charset=utf-8') response.body = b'foo' assert response._get_encoding() == 'utf-8' response._set_header('content-type', 'application/json') assert response._get_encoding() == 'utf-8' response._set_header('content-type', 'text/html; charset=weirdencoding') assert response._get_encoding() == 'ascii'
def test_parse_response_line_with_empty_reason(): """Test parsing response line with empty reason-phrase""" response = HttpResponse() response._set_response_initial(b'HTTP/1.1 200 \r\n') assert response.status_code == 200
def test_parse_response_line(): """Test parsing response line""" response = HttpResponse() response._set_response_initial(b'HTTP/1.1 200 OK\r\n') assert response.status_code == 200