Beispiel #1
0
def test_ctor_with_headers_and_status():
    resp = Response(body=b'body', status=201, headers={'Age': '12'})

    assert 201 == resp.status
    assert b'body' == resp.body
    assert resp.headers['AGE'] == '12'

    resp._send_headers = mock.Mock()
    resp._start(mock.Mock())
    assert 4 == resp.content_length
    assert resp.headers['CONTENT-LENGTH'] == '4'
def test_ctor_with_headers_and_status():
    resp = Response(body=b'body', status=201, headers={'Age': '12'})

    assert 201 == resp.status
    assert b'body' == resp.body
    assert resp.headers['AGE'] == '12'

    resp._send_headers = mock.Mock()
    resp._start(mock.Mock())
    assert 4 == resp.content_length
    assert resp.headers['CONTENT-LENGTH'] == '4'
Beispiel #3
0
def test_assign_nonbyteish_body():
    resp = Response(body=b'data')

    with pytest.raises(AssertionError):
        resp.body = 123
    assert b'data' == resp.body
    assert 4 == resp.content_length

    resp._send_headers = mock.Mock()
    resp._start(mock.Mock())
    assert resp.headers['CONTENT-LENGTH'] == '4'
    assert 4 == resp.content_length
def test_assign_nonbyteish_body():
    resp = Response(body=b'data')

    with pytest.raises(AssertionError):
        resp.body = 123
    assert b'data' == resp.body
    assert 4 == resp.content_length

    resp._send_headers = mock.Mock()
    resp._start(mock.Mock())
    assert resp.headers['CONTENT-LENGTH'] == '4'
    assert 4 == resp.content_length
Beispiel #5
0
def test_ctor_text():
    resp = Response(text='test text')

    assert 200 == resp.status
    assert 'OK' == resp.reason
    assert 9 == resp.content_length
    assert (CIMultiDict([('CONTENT-TYPE', 'text/plain; charset=utf-8')
                         ]) == resp.headers)

    assert resp.body == b'test text'
    assert resp.text == 'test text'

    resp._send_headers = mock.Mock()
    resp._start(mock.Mock())
    assert resp.headers['CONTENT-LENGTH'] == '9'
def test_ctor_text():
    resp = Response(text='test text')

    assert 200 == resp.status
    assert 'OK' == resp.reason
    assert 9 == resp.content_length
    assert (CIMultiDict(
        [('CONTENT-TYPE', 'text/plain; charset=utf-8')]) == resp.headers)

    assert resp.body == b'test text'
    assert resp.text == 'test text'

    resp._send_headers = mock.Mock()
    resp._start(mock.Mock())
    assert resp.headers['CONTENT-LENGTH'] == '9'