Add add_signal method (#2061)
This commit is contained in:
parent
824f41d6e0
commit
d4660d0ca7
|
@ -58,5 +58,14 @@ class SignalMixin:
|
|||
|
||||
return decorator
|
||||
|
||||
def add_signal(
|
||||
self,
|
||||
handler,
|
||||
event: str,
|
||||
condition: Dict[str, Any] = None,
|
||||
):
|
||||
self.signal(event=event, condition=condition)(handler)
|
||||
return handler
|
||||
|
||||
def event(self, event: str):
|
||||
raise NotImplementedError
|
||||
|
|
|
@ -11,6 +11,15 @@ from sanic.exceptions import InvalidSignal, SanicException
|
|||
|
||||
|
||||
def test_add_signal(app):
|
||||
def sync_signal(*_):
|
||||
...
|
||||
|
||||
app.add_signal(sync_signal, "foo.bar.baz")
|
||||
|
||||
assert len(app.signal_router.routes) == 1
|
||||
|
||||
|
||||
def test_add_signal_decorator(app):
|
||||
@app.signal("foo.bar.baz")
|
||||
def sync_signal(*_):
|
||||
...
|
||||
|
|
Loading…
Reference in New Issue
Block a user