Example #1
0
def test_started_when_not_started():
    resp = StreamResponse()
    assert not resp.prepared
Example #2
0
def test_get_nodelay_unprepared():
    resp = StreamResponse()
    with pytest.raises(AssertionError):
        resp.tcp_nodelay
Example #3
0
def test_set_cork_unprepared():
    resp = StreamResponse()
    with pytest.raises(AssertionError):
        resp.set_tcp_cork(True)
Example #4
0
async def test___repr__():
    req = make_request('GET', '/path/to')
    resp = StreamResponse(reason=301)
    await resp.prepare(req)
    assert "<StreamResponse 301 GET /path/to >" == repr(resp)
Example #5
0
async def test_keep_alive_http10_default():
    req = make_request('GET', '/', version=HttpVersion10)
    resp = StreamResponse()
    await resp.prepare(req)
    assert not resp.keep_alive
Example #6
0
async def test_cannot_write_eof_before_headers():
    resp = StreamResponse()

    with pytest.raises(AssertionError):
        await resp.write_eof()
Example #7
0
async def test_response_output_length():
    resp = StreamResponse()
    await resp.prepare(make_request('GET', '/'))
    with pytest.warns(DeprecationWarning):
        assert resp.output_length
Example #8
0
def test_setting_charset():
    resp = StreamResponse()

    resp.content_type = 'text/html'
    resp.charset = 'koi8-r'
    assert 'text/html; charset=koi8-r' == resp.headers['content-type']
Example #9
0
def test_default_charset():
    resp = StreamResponse()

    assert resp.charset is None
Example #10
0
def test_content_length_setter():
    resp = StreamResponse()

    resp.content_length = 234
    assert 234 == resp.content_length
Example #11
0
def test_setting_content_type():
    resp = StreamResponse()

    resp.content_type = 'text/html'
    assert 'text/html' == resp.headers['content-type']
Example #12
0
async def test_changing_status_after_prepare_raises():
    resp = StreamResponse()
    await resp.prepare(make_request('GET', '/'))
    with pytest.raises(AssertionError):
        resp.set_status(400)
Example #13
0
async def test_drain_before_start():
    resp = StreamResponse()
    with pytest.raises(AssertionError):
        await resp.drain()
Example #14
0
async def test_started_when_started():
    resp = StreamResponse()
    await resp.prepare(make_request('GET', '/'))
    assert resp.prepared
Example #15
0
async def test_write_non_byteish():
    resp = StreamResponse()
    await resp.prepare(make_request('GET', '/'))

    with pytest.raises(AssertionError):
        await resp.write(123)
Example #16
0
def test_reset_charset():
    resp = StreamResponse()

    resp.content_type = 'text/html'
    resp.charset = None
    assert resp.charset is None
Example #17
0
async def test_write_before_start():
    resp = StreamResponse()

    with pytest.raises(RuntimeError):
        await resp.write(b'data')
Example #18
0
def test_charset_without_content_type():
    resp = StreamResponse()

    with pytest.raises(RuntimeError):
        resp.charset = 'koi8-r'
Example #19
0
def test_force_close():
    resp = StreamResponse()

    assert resp.keep_alive is None
    resp.force_close()
    assert resp.keep_alive is False
Example #20
0
def test_last_modified_initial():
    resp = StreamResponse()
    assert resp.last_modified is None
Example #21
0
def test_set_status_with_reason():
    resp = StreamResponse()

    resp.set_status(200, "Everithing is fine!")
    assert 200 == resp.status
    assert "Everithing is fine!" == resp.reason
Example #22
0
def test_last_modified_string():
    resp = StreamResponse()

    dt = datetime.datetime(1990, 1, 2, 3, 4, 5, 0, datetime.timezone.utc)
    resp.last_modified = 'Mon, 2 Jan 1990 03:04:05 GMT'
    assert resp.last_modified == dt
Example #23
0
def test___repr___not_prepared():
    resp = StreamResponse(reason=301)
    assert "<StreamResponse 301 not prepared>" == repr(resp)
Example #24
0
def test_last_modified_datetime():
    resp = StreamResponse()

    dt = datetime.datetime(2001, 2, 3, 4, 5, 6, 0, datetime.timezone.utc)
    resp.last_modified = dt
    assert resp.last_modified == dt
Example #25
0
async def test_keep_alive_http09():
    headers = CIMultiDict(Connection='keep-alive')
    req = make_request('GET', '/', version=HttpVersion(0, 9), headers=headers)
    resp = StreamResponse()
    await resp.prepare(req)
    assert not resp.keep_alive
Example #26
0
def test_last_modified_reset():
    resp = StreamResponse()

    resp.last_modified = 0
    resp.last_modified = None
    assert resp.last_modified is None
Example #27
0
def test_stream_response_is_mutable_mapping():
    resp = StreamResponse()
    assert isinstance(resp, collections.MutableMapping)
    resp['key'] = 'value'
    assert 'value' == resp['key']
Example #28
0
def test_enable_chunked_encoding_with_content_length():
    resp = StreamResponse()

    resp.content_length = 234
    with pytest.raises(RuntimeError):
        resp.enable_chunked_encoding()
Example #29
0
def test_stream_response_delitem():
    resp = StreamResponse()
    resp['key'] = 'value'
    del resp['key']
    assert 'key' not in resp
Example #30
0
def test_content_length():
    resp = StreamResponse()
    assert resp.content_length is None