Merge pull request #885 from yunstanford/master

add triggers events when async create_server
This commit is contained in:
Raphael Deem
2017-08-09 15:59:44 -07:00
committed by GitHub
3 changed files with 35 additions and 0 deletions

View File

@@ -59,3 +59,20 @@ def test_all_listeners():
start_stop_app(random_name_app)
for listener_name in AVAILABLE_LISTENERS:
assert random_name_app.name + listener_name == output.pop()
async def test_trigger_before_events_create_server():
class MySanicDb:
pass
app = Sanic("test_sanic_app")
@app.listener('before_server_start')
async def init_db(app, loop):
app.db = MySanicDb()
await app.create_server()
assert hasattr(app, "db")
assert isinstance(app.db, MySanicDb)