@@ -117,6 +117,20 @@ def test_locate_with_param():
117117 assert response is not None # HelloResponse located
118118 assert response .body == "Hello" # body param applies
119119
120+ def test_locate_dependencies_with_param ():
121+ di = DIContainer ()
122+ di .register (OtherResponse )
123+ di .register (GoodbyeResponse )
124+ di .register (HelloResponse )
125+
126+ response = di .locate (HelloResponse , ["Hello" ])
127+ assert response is not None # HelloResponse located
128+ assert response .body == "Hello" # body populated with default value for str
129+ assert response .goodbye is not None # GoodbyeResponse located
130+ assert response .goodbye .test is not None # TestResponse located
131+ assert response .goodbye .test .test == 0 # TestResponse.test populated with default value for int
132+ assert response .goodbye .test .body == "" # TestResponse.body populated with default value for str
133+
120134def test_locate_with_param_pydantic ():
121135 di = DIContainer ()
122136 di .register (PydanticHelloResponse )
@@ -125,6 +139,20 @@ def test_locate_with_param_pydantic():
125139 assert response is not None # HelloResponse located
126140 assert response .body == "Hello" # body param applies
127141
142+ def test_locate_pydantic_dependencies_with_param ():
143+ di = DIContainer ()
144+ di .register (PydanticOtherResponse )
145+ di .register (PydanticGoodbyeResponse )
146+ di .register (PydanticHelloResponse )
147+
148+ response = di .locate (PydanticHelloResponse , ["Hello" ])
149+ assert response is not None # HelloResponse located
150+ assert response .body == "Hello" # body populated with default value for str
151+ assert response .goodbye is not None # GoodbyeResponse located
152+ assert response .goodbye .test is not None # TestResponse located
153+ assert response .goodbye .test .test == 0 # TestResponse.test populated with default value for int
154+ assert response .goodbye .test .body == "" # TestResponse.body populated with default value for str
155+
128156def test_register_instance ():
129157 di = DIContainer ()
130158 di .register_instance (B , B ())
0 commit comments