def test_http(): response = [] buffer = [] def start_response(status, headers): response[:] = [status, headers] return buffer.append http = HTTP(200, 'Hello World', headers={'X-Test': 'Hello Header'}, cookies={'cookie_test': 'hello cookie'}) assert http.body == [b'Hello World'] assert http.status_code == 200 assert http.headers == [('X-Test', 'Hello Header'), ('Set-Cookie', 'e')] assert http.to({'REQUEST_METHOD': 'HEAD'}, start_response) == [b''] assert http.to({'REQUEST_METHOD': 'GET'}, start_response) == [b'Hello World']
def test_http_body_list(): http = HTTP(200, body=[b'Test list']) assert http.body == [b'Test list'] assert http.status_code == 200 assert set(http.headers) == set(_get_response_headers())
def test_http_body_none(): http = HTTP(200, body=None) assert http.body == [] assert http.status_code == 200 assert set(http.headers) == set(_get_response_headers())
def test_route(): raise HTTP(404, 'Not found, dude')
def test_http_body_list(): http = HTTP(200, body=[b'Test list']) assert http.body == [b'Test list'] assert http.status_code == 200 assert http.headers == []
def test_http_body_none(): http = HTTP(200, body=None) assert http.body == [] assert http.status_code == 200 assert http.headers == []