Skip to content

Commit 477550f

Browse files
committed
test: FastDependsConfig merging
1 parent 437f097 commit 477550f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/application/test_delayed_broker.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import pytest
22

33
from faststream._internal.application import StartAbleApplication
4+
from faststream._internal.context import ContextRepo
5+
from faststream._internal.di import FastDependsConfig
46
from faststream.exceptions import SetupError
57
from faststream.rabbit import RabbitBroker
68

@@ -45,3 +47,32 @@ async def test_di_reconfigured() -> None:
4547
app.set_broker(broker)
4648

4749
assert broker.context.get("app") is app
50+
51+
52+
def test_broker_and_app_contexts_merge() -> None:
53+
broker = RabbitBroker(
54+
context=ContextRepo({
55+
"broker_dependency": 1,
56+
"override_dependency": 2,
57+
})
58+
)
59+
60+
config = FastDependsConfig(
61+
context=ContextRepo({
62+
"application_dependency": 3,
63+
"override_dependency": 4,
64+
})
65+
)
66+
app = StartAbleApplication(config=config)
67+
application_context = app.context
68+
69+
# if the broker binds to the application,
70+
# the broker modifies the application context and uses it as its own.
71+
app.set_broker(broker)
72+
73+
assert app.context is application_context
74+
assert broker.context is application_context
75+
assert app.context.get("broker_dependency") == 1
76+
assert app.context.get("application_dependency") == 3
77+
# the broker context overwrites the application context
78+
assert app.context.get("override_dependency") == 2

0 commit comments

Comments
 (0)