77from configuration import AppConfig
88
99
10- def test_config_endpoint_handler_configuration_not_loaded (mocker ):
10+ @pytest .mark .asyncio
11+ async def test_config_endpoint_handler_configuration_not_loaded (mocker ):
1112 """Test the config endpoint handler."""
13+ # Mock authorization resolvers
14+ mock_resolvers = mocker .patch (
15+ "authorization.middleware.get_authorization_resolvers"
16+ )
17+ mock_role_resolver = mocker .AsyncMock ()
18+ mock_access_resolver = mocker .AsyncMock ()
19+ mock_role_resolver .resolve_roles .return_value = []
20+ mock_access_resolver .check_access .return_value = True
21+ mock_resolvers .return_value = (mock_role_resolver , mock_access_resolver )
22+
1223 mocker .patch (
1324 "app.endpoints.config.configuration._configuration" ,
1425 new = None ,
@@ -20,14 +31,27 @@ def test_config_endpoint_handler_configuration_not_loaded(mocker):
2031 "type" : "http" ,
2132 }
2233 )
23- with pytest .raises (HTTPException ) as e :
24- config_endpoint_handler (request )
25- assert e .status_code == status .HTTP_500_INTERNAL_SERVER_ERROR
26- assert e .detail ["response" ] == "Configuration is not loaded"
34+ auth = ("test_user" , "token" , {})
35+ with pytest .raises (HTTPException ) as exc_info :
36+ await config_endpoint_handler (auth = auth , _request = request )
2737
38+ assert exc_info .value .status_code == status .HTTP_500_INTERNAL_SERVER_ERROR
39+ assert exc_info .value .detail ["response" ] == "Configuration is not loaded"
2840
29- def test_config_endpoint_handler_configuration_loaded ():
41+
42+ @pytest .mark .asyncio
43+ async def test_config_endpoint_handler_configuration_loaded (mocker ):
3044 """Test the config endpoint handler."""
45+ # Mock authorization resolvers
46+ mock_resolvers = mocker .patch (
47+ "authorization.middleware.get_authorization_resolvers"
48+ )
49+ mock_role_resolver = mocker .AsyncMock ()
50+ mock_access_resolver = mocker .AsyncMock ()
51+ mock_role_resolver .resolve_roles .return_value = []
52+ mock_access_resolver .check_access .return_value = True
53+ mock_resolvers .return_value = (mock_role_resolver , mock_access_resolver )
54+
3155 config_dict = {
3256 "name" : "foo" ,
3357 "service" : {
@@ -49,15 +73,21 @@ def test_config_endpoint_handler_configuration_loaded():
4973 "authentication" : {
5074 "module" : "noop" ,
5175 },
76+ "authorization" : {"access_rules" : []},
5277 "customization" : None ,
5378 }
5479 cfg = AppConfig ()
5580 cfg .init_from_dict (config_dict )
81+
82+ # Mock configuration
83+ mocker .patch ("app.endpoints.config.configuration" , cfg )
84+
5685 request = Request (
5786 scope = {
5887 "type" : "http" ,
5988 }
6089 )
61- response = config_endpoint_handler (request )
90+ auth = ("test_user" , "token" , {})
91+ response = await config_endpoint_handler (auth = auth , _request = request )
6292 assert response is not None
6393 assert response == cfg .configuration
0 commit comments