11import logging
22
33import pytest
4- from ellar .app import App , config , current_injector
4+ from ellar .app import App
55from ellar .common import Body , post
6- from ellar .core import Config
7- from ellar .core .context import ApplicationContext
6+ from ellar .core import Config , config , current_injector , with_injector_context
87from ellar .testing import Test
98
109
@@ -24,7 +23,7 @@ async def test_current_config_fails_when_there_is_no_ellar_config_module(
2423 with caplog .at_level (logging .WARNING ):
2524 tm = Test .create_test_module ()
2625
27- async with ApplicationContext . create (tm .create_application ()):
26+ async with with_injector_context (tm .create_application (). injector ):
2827 assert current_injector .get (App ) is not None
2928 assert config .DEBUG is False
3029
@@ -43,7 +42,7 @@ async def test_current_config_fails_when_there_is_no_ellar_config_module(
4342async def test_current_injector_works (anyio_backend ):
4443 tm = Test .create_test_module ()
4544
46- async with ApplicationContext . create (tm .create_application ()):
45+ async with with_injector_context (tm .create_application (). injector ):
4746 assert current_injector .get (App ) is not None
4847
4948 with pytest .raises (RuntimeError ):
@@ -53,7 +52,7 @@ async def test_current_injector_works(anyio_backend):
5352async def test_current_app_works (anyio_backend ):
5453 tm = Test .create_test_module ()
5554
56- async with ApplicationContext . create (tm .create_application ()):
55+ async with with_injector_context (tm .create_application (). injector ):
5756 assert isinstance (current_injector .get (Config ), Config )
5857
5958 with pytest .raises (RuntimeError ):
@@ -63,7 +62,7 @@ async def test_current_app_works(anyio_backend):
6362async def test_current_config_works (anyio_backend ):
6463 tm = Test .create_test_module (config_module = {"FRAMEWORK_NAME" : "Ellar" })
6564
66- async with tm .create_application ().application_context ( ):
65+ async with with_injector_context ( tm .create_application ().injector ):
6766 app = current_injector .get (App )
6867 assert app .config .FRAMEWORK_NAME == config .FRAMEWORK_NAME
6968
@@ -72,20 +71,19 @@ async def test_current_config_works(anyio_backend):
7271
7372
7473async def test_current_config_works_ (anyio_backend ):
75- tm = Test .create_test_module (config_module = {"FRAMEWORK_NAME" : "Ellar" })
76-
7774 @post
7875 def add (a : Body [int ], b : Body [int ]):
79- from ellar .app import current_injector
76+ from ellar .core import current_injector
8077
8178 config_ = current_injector .get (Config )
8279 assert config_ .FRAMEWORK_NAME == config .FRAMEWORK_NAME
8380 return a + b
8481
85- app = tm .create_application ()
86- app .router .add_route (add )
82+ tm = Test .create_test_module (
83+ config_module = {"FRAMEWORK_NAME" : "Ellar" }, routers = [add ]
84+ )
8785
88- async with app . application_context ( ):
86+ async with with_injector_context ( tm . create_application (). injector ):
8987 res = tm .get_test_client ().post ("/" , json = {"a" : 1 , "b" : 4 })
9088 assert res .json () == 5
9189 config_ = current_injector .get (Config )
0 commit comments