示例#1
0
def test_content_type():
    response = Response(content_type='foo/bar')
    assert response.headers['Content-Type'] == 'foo/bar'
示例#2
0
def test_multi():
    with pytest.raises(ValueError):
        Response(text='foobar', body=b'foobar')
示例#3
0
def test_ok():
    assert Response(status=200).ok
    assert Response(status=301).ok
    assert not Response(status=400).ok
    assert not Response(status=500).ok
示例#4
0
async def test_text_response():
    response = Response(text='foobar')
    assert response.status == 200
    assert response.headers['Content-Type'] == 'text/plain; charset=UTF-8'
    assert await response.body() == b'foobar'
    assert await response.text() == 'foobar'
示例#5
0
async def test_redirect_response():
    response = Response(redirect='https://www.foobar.test/')
    assert response.status == 304
    assert response.headers['Location'] == 'https://www.foobar.test/'
    assert await response.body() == b''
示例#6
0
async def test_html_response():
    response = Response(html='<p>foobar</p>')
    assert response.status == 200
    assert response.headers['Content-Type'] == 'text/html; charset=UTF-8'
    assert await response.body() == b'<p>foobar</p>'
    assert await response.text() == '<p>foobar</p>'
示例#7
0
async def test_multipart_file_response():
    response = Response(file=File('foo.txt', 'text/plain', b'foobar'))
    assert response.content_type == 'text/plain'
    assert await response.body() == b'foobar'
    assert await response.text() == 'foobar'
示例#8
0
async def hello_world(request):
    name = request.query.get('name', 'World')
    return Response(text=f'Hello, {name}!')