Change signal routing for increased consistency (#2277)

This commit is contained in:
Adam Hopkins
2021-12-24 01:27:54 +02:00
committed by GitHub
parent 8c07e388cd
commit b91ffed010
5 changed files with 88 additions and 14 deletions

View File

@@ -145,6 +145,23 @@ async def test_dispatch_signal_triggers_with_requirements(app):
assert counter == 1
@pytest.mark.asyncio
async def test_dispatch_signal_triggers_with_requirements_exclusive(app):
counter = 0
@app.signal("foo.bar.baz", condition={"one": "two"}, exclusive=False)
def sync_signal(*_):
nonlocal counter
counter += 1
app.signal_router.finalize()
await app.dispatch("foo.bar.baz")
assert counter == 1
await app.dispatch("foo.bar.baz", condition={"one": "two"})
assert counter == 2
@pytest.mark.asyncio
async def test_dispatch_signal_triggers_with_context(app):
counter = 0
@@ -204,6 +221,24 @@ async def test_dispatch_signal_triggers_on_bp(app):
assert bp_counter == 2
@pytest.mark.asyncio
async def test_dispatch_signal_triggers_on_bp_alone(app):
bp = Blueprint("bp")
bp_counter = 0
@bp.signal("foo.bar.baz")
def bp_signal():
nonlocal bp_counter
bp_counter += 1
app.blueprint(bp)
app.signal_router.finalize()
await app.dispatch("foo.bar.baz")
await bp.dispatch("foo.bar.baz")
assert bp_counter == 2
@pytest.mark.asyncio
async def test_dispatch_signal_triggers_event(app):
app_counter = 0