add unit tests and make flake8 happy
This commit is contained in:
parent
d5d1d3b45a
commit
80f27b1db9
@ -641,7 +641,10 @@ class Sanic:
|
|||||||
has_log=log_config is not None)
|
has_log=log_config is not None)
|
||||||
|
|
||||||
# Trigger before_start events
|
# Trigger before_start events
|
||||||
await self.trigger_events(server_settings.get('before_start', []), server_settings.get('loop'))
|
await self.trigger_events(
|
||||||
|
server_settings.get('before_start', []),
|
||||||
|
server_settings.get('loop')
|
||||||
|
)
|
||||||
|
|
||||||
return await serve(**server_settings)
|
return await serve(**server_settings)
|
||||||
|
|
||||||
|
@ -59,3 +59,20 @@ def test_all_listeners():
|
|||||||
start_stop_app(random_name_app)
|
start_stop_app(random_name_app)
|
||||||
for listener_name in AVAILABLE_LISTENERS:
|
for listener_name in AVAILABLE_LISTENERS:
|
||||||
assert random_name_app.name + listener_name == output.pop()
|
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user