def test_build_response_error_1(): response = Response() response.status_code = 0 response.set_header('x-app', 'blargh!') response.set_body('{"hello": "world"}') with pytest.raises(Exception, match=r'Response not well formed'): response._build_response()
def test_build_response(): response = Response() response.set_status_code(404) response.set_header('x-app', 'blargh!') response.set_body('{"hello": "world"}') check = response._build_response() assert check['statusCode'] == 404 assert check['body'] == '{"hello": "world"}' assert check['headers']['x-app'] == "blargh!"
def test_set_header(): response = Response() response.set_header('x-api', 'some_random_stuff') assert response.headers['x-api'] == 'some_random_stuff'
def test_set_header_missing_key(): response = Response() with pytest.raises(Exception, match=r"a header key"): response.set_header(None, 'some_random_stuff')