Exemple #1
0
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']
Exemple #2
0
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())
Exemple #3
0
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())
Exemple #4
0
 def test_route():
     raise HTTP(404, 'Not found, dude')
Exemple #5
0
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 == []
Exemple #6
0
def test_http_body_none():
    http = HTTP(200, body=None)

    assert http.body == []
    assert http.status_code == 200
    assert http.headers == []