From 825db07bf02e1464869e3bdfb566e875d660d26c Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Sat, 11 Feb 2017 12:34:11 +0000 Subject: [PATCH] Fix tests and accidently removed args to serve --- examples/try_everything.py | 4 +++- sanic/utils.py | 4 ++-- tests/test_bad_request.py | 3 ++- tests/test_signal_handlers.py | 19 ++++++++++--------- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/examples/try_everything.py b/examples/try_everything.py index f386fb03..e4377e3f 100644 --- a/examples/try_everything.py +++ b/examples/try_everything.py @@ -64,12 +64,14 @@ def query_string(request): # Run Server # ----------------------------------------------- # +@app.after_start def after_start(app, loop): log.info("OH OH OH OH OHHHHHHHH") +@app.before_start def before_stop(app, loop): log.info("TRIED EVERYTHING") -app.run(host="0.0.0.0", port=8000, debug=True, after_start=after_start, before_stop=before_stop) +app.run(host="0.0.0.0", port=8000, debug=True) diff --git a/sanic/utils.py b/sanic/utils.py index 8e8f8124..4074f22d 100644 --- a/sanic/utils.py +++ b/sanic/utils.py @@ -28,6 +28,7 @@ def sanic_endpoint_test(app, method='get', uri='/', gather_request=True, results[0] = request app.request_middleware.appendleft(_collect_request) + @app.after_start async def _collect_response(sanic, loop): try: response = await local_request(method, uri, *request_args, @@ -37,8 +38,7 @@ def sanic_endpoint_test(app, method='get', uri='/', gather_request=True, exceptions.append(e) app.stop() - app.run(host=HOST, debug=debug, port=PORT, - after_start=_collect_response, **server_kwargs) + app.run(host=HOST, debug=debug, port=PORT, **server_kwargs) if exceptions: raise ValueError("Exception during request: {}".format(exceptions)) diff --git a/tests/test_bad_request.py b/tests/test_bad_request.py index 095f4ab1..89b1e60c 100644 --- a/tests/test_bad_request.py +++ b/tests/test_bad_request.py @@ -5,6 +5,7 @@ from sanic import Sanic def test_bad_request_response(): app = Sanic('test_bad_request_response') lines = [] + @app.after_start async def _request(sanic, loop): connect = asyncio.open_connection('127.0.0.1', 42101) reader, writer = await connect @@ -15,6 +16,6 @@ def test_bad_request_response(): break lines.append(line) app.stop() - app.run(host='127.0.0.1', port=42101, debug=False, after_start=_request) + app.run(host='127.0.0.1', port=42101, debug=False) assert lines[0] == b'HTTP/1.1 400 Bad Request\r\n' assert lines[-1] == b'Error: Bad Request' diff --git a/tests/test_signal_handlers.py b/tests/test_signal_handlers.py index 756df828..85f0d9ee 100644 --- a/tests/test_signal_handlers.py +++ b/tests/test_signal_handlers.py @@ -27,10 +27,11 @@ def test_register_system_signals(): async def hello_route(request): return HTTPResponse() - app.run(HOST, PORT, - before_start=set_loop, - after_start=stop, - after_stop=after) + app.after_start(stop) + app.before_start(set_loop) + app.after_stop(after) + + app.run(HOST, PORT) assert calledq.get() == True @@ -42,9 +43,9 @@ def test_dont_register_system_signals(): async def hello_route(request): return HTTPResponse() - app.run(HOST, PORT, - before_start=set_loop, - after_start=stop, - after_stop=after, - register_sys_signals=False) + app.after_start(stop) + app.before_start(set_loop) + app.after_stop(after) + + app.run(HOST, PORT, register_sys_signals=False) assert calledq.get() == False