55from models .config import ModelContextProtocolServer
66
77
8+ # pylint: disable=broad-exception-caught,protected-access
9+ @pytest .fixture (autouse = True )
10+ def _reset_app_config_between_tests ():
11+ # ensure clean state before each test
12+ try :
13+ AppConfig ()._configuration = None # type: ignore[attr-defined]
14+ except Exception :
15+ pass
16+ yield
17+ # ensure clean state after each test
18+ try :
19+ AppConfig ()._configuration = None # type: ignore[attr-defined]
20+ except Exception :
21+ pass
22+
23+
824def test_default_configuration () -> None :
925 """Test that configuration attributes are not accessible for uninitialized app."""
1026 cfg = AppConfig ()
@@ -13,31 +29,45 @@ def test_default_configuration() -> None:
1329 # configuration is not loaded
1430 with pytest .raises (Exception , match = "logic error: configuration is not loaded" ):
1531 # try to read property
16- cfg .configuration # pylint: disable=pointless-statement
32+ _ = cfg .configuration # pylint: disable=pointless-statement
1733
1834 with pytest .raises (Exception , match = "logic error: configuration is not loaded" ):
1935 # try to read property
20- cfg .service_configuration # pylint: disable=pointless-statement
36+ _ = cfg .service_configuration # pylint: disable=pointless-statement
2137
2238 with pytest .raises (Exception , match = "logic error: configuration is not loaded" ):
2339 # try to read property
24- cfg .llama_stack_configuration # pylint: disable=pointless-statement
40+ _ = cfg .llama_stack_configuration # pylint: disable=pointless-statement
2541
2642 with pytest .raises (Exception , match = "logic error: configuration is not loaded" ):
2743 # try to read property
28- cfg .user_data_collection_configuration # pylint: disable=pointless-statement
44+ _ = (
45+ cfg .user_data_collection_configuration
46+ ) # pylint: disable=pointless-statement
2947
3048 with pytest .raises (Exception , match = "logic error: configuration is not loaded" ):
3149 # try to read property
32- cfg .mcp_servers # pylint: disable=pointless-statement
50+ _ = cfg .mcp_servers # pylint: disable=pointless-statement
3351
3452 with pytest .raises (Exception , match = "logic error: configuration is not loaded" ):
3553 # try to read property
36- cfg .authentication_configuration # pylint: disable=pointless-statement
54+ _ = cfg .authentication_configuration # pylint: disable=pointless-statement
3755
3856 with pytest .raises (Exception , match = "logic error: configuration is not loaded" ):
3957 # try to read property
40- cfg .customization # pylint: disable=pointless-statement
58+ _ = cfg .customization # pylint: disable=pointless-statement
59+
60+ with pytest .raises (Exception , match = "logic error: configuration is not loaded" ):
61+ # try to read property
62+ _ = cfg .authorization_configuration # pylint: disable=pointless-statement
63+
64+ with pytest .raises (Exception , match = "logic error: configuration is not loaded" ):
65+ # try to read property
66+ _ = cfg .inference # pylint: disable=pointless-statement
67+
68+ with pytest .raises (Exception , match = "logic error: configuration is not loaded" ):
69+ # try to read property
70+ _ = cfg .database_configuration # pylint: disable=pointless-statement
4171
4272
4373def test_configuration_is_singleton () -> None :
@@ -69,6 +99,9 @@ def test_init_from_dict() -> None:
6999 },
70100 "mcp_servers" : [],
71101 "customization" : None ,
102+ "authentication" : {
103+ "module" : "noop" ,
104+ },
72105 }
73106 cfg = AppConfig ()
74107 cfg .init_from_dict (config_dict )
@@ -98,6 +131,19 @@ def test_init_from_dict() -> None:
98131 # check for user data collection subsection
99132 assert cfg .user_data_collection_configuration .feedback_enabled is False
100133
134+ # check authentication_configuration
135+ assert cfg .authentication_configuration is not None
136+ assert cfg .authentication_configuration .module == "noop"
137+
138+ # check authorization configuration - default value
139+ assert cfg .authorization_configuration is not None
140+
141+ # check database configuration
142+ assert cfg .database_configuration is not None
143+
144+ # check inference configuration
145+ assert cfg .inference is not None
146+
101147
102148def test_init_from_dict_with_mcp_servers () -> None :
103149 """Test initialization with MCP servers configuration."""
@@ -144,6 +190,35 @@ def test_init_from_dict_with_mcp_servers() -> None:
144190 assert cfg .mcp_servers [1 ].url == "https://api.example.com"
145191
146192
193+ def test_init_from_dict_with_authorization_configuration () -> None :
194+ """Test initialization with authorization configuration configuration."""
195+ config_dict = {
196+ "name" : "foo" ,
197+ "service" : {
198+ "host" : "localhost" ,
199+ "port" : 8080 ,
200+ "auth_enabled" : False ,
201+ "workers" : 1 ,
202+ "color_log" : True ,
203+ "access_log" : True ,
204+ },
205+ "llama_stack" : {
206+ "api_key" : "xyzzy" ,
207+ "url" : "http://x.y.com:1234" ,
208+ "use_as_library_client" : False ,
209+ },
210+ "user_data_collection" : {
211+ "feedback_enabled" : False ,
212+ },
213+ "authorization" : {},
214+ "customization" : None ,
215+ }
216+ cfg = AppConfig ()
217+ cfg .init_from_dict (config_dict )
218+
219+ assert cfg .authorization_configuration is not None
220+
221+
147222def test_load_proper_configuration (tmpdir ) -> None :
148223 """Test loading proper configuration from YAML file."""
149224 cfg_filename = tmpdir / "config.yaml"
0 commit comments