Пример #1
0
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'}
Пример #2
0
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'