def test_event_on_bp_not_registered(): bp = Blueprint("bp") @bp.signal("foo.bar.baz") def bp_signal(): ... with pytest.raises( SanicException, match="<Blueprint bp> has not yet been registered to an app", ): bp.event("foo.bar.baz")
async def test_dispatch_signal_triggers_event_on_bp(app): bp = Blueprint("bp") bp_counter = 0 @bp.signal("foo.bar.baz") def bp_signal(): ... async def do_wait(): nonlocal bp_counter await bp.event("foo.bar.baz") bp_counter += 1 app.blueprint(bp) app.signal_router.finalize() signal, *_ = app.signal_router.get("foo.bar.baz", condition={"blueprint": "bp"}) await bp.dispatch("foo.bar.baz") waiter = bp.event("foo.bar.baz") assert isawaitable(waiter) fut = asyncio.ensure_future(do_wait()) signal.ctx.event.set() await fut assert bp_counter == 1
def test_event_not_exist_on_bp(app): bp = Blueprint("bp") app.blueprint(bp) with pytest.raises(NotFound, match="Could not find signal does.not.exist"): bp.event("does.not.exist")