11"""Tests for app.config module"""
22from unittest .mock import patch
33
4+ import app .config
5+
46
57class TestConfigFunctions :
68 """Test configuration check functions"""
@@ -9,100 +11,79 @@ def test_has_cosmos_db_config_true(self):
911 """Test has_cosmos_db_config returns True when endpoint is configured"""
1012 with patch ("app.config.settings" ) as mock_settings :
1113 mock_settings .cosmos_db_endpoint = "https://test.documents.azure.com:443/"
12- # Need to reimport to use the patched settings
13- import app .config
14- with patch .object (app .config , "settings" , mock_settings ):
15- result = app .config .has_cosmos_db_config ()
16- assert result is True
14+ result = app .config .has_cosmos_db_config ()
15+ assert result is True
1716
1817 def test_has_cosmos_db_config_false (self ):
1918 """Test has_cosmos_db_config returns False when endpoint is not configured"""
2019 with patch ("app.config.settings" ) as mock_settings :
2120 mock_settings .cosmos_db_endpoint = None
22- import app .config
23- with patch .object (app .config , "settings" , mock_settings ):
24- result = app .config .has_cosmos_db_config ()
25- assert result is False
21+ result = app .config .has_cosmos_db_config ()
22+ assert result is False
2623
2724 def test_has_entra_id_config_true (self ):
2825 """Test has_entra_id_config returns True when all Entra ID settings are configured"""
2926 with patch ("app.config.settings" ) as mock_settings :
3027 mock_settings .azure_client_id = "test-client-id"
3128 mock_settings .azure_client_secret = "test-client-secret"
3229 mock_settings .azure_tenant_id = "test-tenant-id"
33- import app .config
34- with patch .object (app .config , "settings" , mock_settings ):
35- result = app .config .has_entra_id_config ()
36- assert result is True
30+ result = app .config .has_entra_id_config ()
31+ assert result is True
3732
3833 def test_has_entra_id_config_false_missing_client_id (self ):
3934 """Test has_entra_id_config returns False when client_id is missing"""
4035 with patch ("app.config.settings" ) as mock_settings :
4136 mock_settings .azure_client_id = None
4237 mock_settings .azure_client_secret = "test-client-secret"
4338 mock_settings .azure_tenant_id = "test-tenant-id"
44- import app .config
45- with patch .object (app .config , "settings" , mock_settings ):
46- result = app .config .has_entra_id_config ()
47- assert result is False
39+ result = app .config .has_entra_id_config ()
40+ assert result is False
4841
4942 def test_has_entra_id_config_false_missing_secret (self ):
5043 """Test has_entra_id_config returns False when client_secret is missing"""
5144 with patch ("app.config.settings" ) as mock_settings :
5245 mock_settings .azure_client_id = "test-client-id"
5346 mock_settings .azure_client_secret = None
5447 mock_settings .azure_tenant_id = "test-tenant-id"
55- import app .config
56- with patch .object (app .config , "settings" , mock_settings ):
57- result = app .config .has_entra_id_config ()
58- assert result is False
48+ result = app .config .has_entra_id_config ()
49+ assert result is False
5950
6051 def test_has_entra_id_config_false_missing_tenant (self ):
6152 """Test has_entra_id_config returns False when tenant_id is missing"""
6253 with patch ("app.config.settings" ) as mock_settings :
6354 mock_settings .azure_client_id = "test-client-id"
6455 mock_settings .azure_client_secret = "test-client-secret"
6556 mock_settings .azure_tenant_id = None
66- import app .config
67- with patch .object (app .config , "settings" , mock_settings ):
68- result = app .config .has_entra_id_config ()
69- assert result is False
57+ result = app .config .has_entra_id_config ()
58+ assert result is False
7059
7160 def test_has_azure_search_config_true (self ):
7261 """Test has_azure_search_config returns True when endpoint is configured"""
7362 with patch ("app.config.settings" ) as mock_settings :
7463 mock_settings .azure_search_endpoint = "https://test.search.windows.net"
75- import app .config
76- with patch .object (app .config , "settings" , mock_settings ):
77- result = app .config .has_azure_search_config ()
78- assert result is True
64+ result = app .config .has_azure_search_config ()
65+ assert result is True
7966
8067 def test_has_azure_search_config_false (self ):
8168 """Test has_azure_search_config returns False when endpoint is not configured"""
8269 with patch ("app.config.settings" ) as mock_settings :
8370 mock_settings .azure_search_endpoint = None
84- import app .config
85- with patch .object (app .config , "settings" , mock_settings ):
86- result = app .config .has_azure_search_config ()
87- assert result is False
71+ result = app .config .has_azure_search_config ()
72+ assert result is False
8873
8974 def test_has_azure_search_endpoint_true (self ):
9075 """Test has_azure_search_endpoint returns True when endpoint is configured"""
9176 with patch ("app.config.settings" ) as mock_settings :
9277 mock_settings .azure_search_endpoint = "https://test.search.windows.net"
93- import app .config
94- with patch .object (app .config , "settings" , mock_settings ):
95- result = app .config .has_azure_search_endpoint ()
96- assert result is True
78+ result = app .config .has_azure_search_endpoint ()
79+ assert result is True
9780
9881 def test_has_azure_search_endpoint_false (self ):
9982 """Test has_azure_search_endpoint returns False when endpoint is not configured"""
10083 with patch ("app.config.settings" ) as mock_settings :
10184 mock_settings .azure_search_endpoint = None
102- import app .config
103- with patch .object (app .config , "settings" , mock_settings ):
104- result = app .config .has_azure_search_endpoint ()
105- assert result is False
85+ result = app .config .has_azure_search_endpoint ()
86+ assert result is False
10687
10788 def test_has_foundry_config_true_with_chat_agent (self ):
10889 """Test has_foundry_config returns True when endpoint and chat agent are configured"""
@@ -111,10 +92,8 @@ def test_has_foundry_config_true_with_chat_agent(self):
11192 mock_settings .foundry_chat_agent = "chat-agent-id"
11293 mock_settings .foundry_product_agent = ""
11394 mock_settings .foundry_policy_agent = ""
114- import app .config
115- with patch .object (app .config , "settings" , mock_settings ):
116- result = app .config .has_foundry_config ()
117- assert result is True
95+ result = app .config .has_foundry_config ()
96+ assert result is True
11897
11998 def test_has_foundry_config_true_with_product_agent (self ):
12099 """Test has_foundry_config returns True when endpoint and product agent are configured"""
@@ -123,10 +102,8 @@ def test_has_foundry_config_true_with_product_agent(self):
123102 mock_settings .foundry_chat_agent = ""
124103 mock_settings .foundry_product_agent = "product-agent-id"
125104 mock_settings .foundry_policy_agent = ""
126- import app .config
127- with patch .object (app .config , "settings" , mock_settings ):
128- result = app .config .has_foundry_config ()
129- assert result is True
105+ result = app .config .has_foundry_config ()
106+ assert result is True
130107
131108 def test_has_foundry_config_true_with_policy_agent (self ):
132109 """Test has_foundry_config returns True when endpoint and policy agent are configured"""
@@ -135,10 +112,8 @@ def test_has_foundry_config_true_with_policy_agent(self):
135112 mock_settings .foundry_chat_agent = ""
136113 mock_settings .foundry_product_agent = ""
137114 mock_settings .foundry_policy_agent = "policy-agent-id"
138- import app .config
139- with patch .object (app .config , "settings" , mock_settings ):
140- result = app .config .has_foundry_config ()
141- assert result is True
115+ result = app .config .has_foundry_config ()
116+ assert result is True
142117
143118 def test_has_foundry_config_false_no_endpoint (self ):
144119 """Test has_foundry_config returns False when endpoint is missing"""
@@ -147,10 +122,8 @@ def test_has_foundry_config_false_no_endpoint(self):
147122 mock_settings .foundry_chat_agent = "chat-agent-id"
148123 mock_settings .foundry_product_agent = ""
149124 mock_settings .foundry_policy_agent = ""
150- import app .config
151- with patch .object (app .config , "settings" , mock_settings ):
152- result = app .config .has_foundry_config ()
153- assert result is False
125+ result = app .config .has_foundry_config ()
126+ assert result is False
154127
155128 def test_has_foundry_config_false_no_agents (self ):
156129 """Test has_foundry_config returns False when no agents are configured"""
@@ -159,50 +132,40 @@ def test_has_foundry_config_false_no_agents(self):
159132 mock_settings .foundry_chat_agent = ""
160133 mock_settings .foundry_product_agent = ""
161134 mock_settings .foundry_policy_agent = ""
162- import app .config
163- with patch .object (app .config , "settings" , mock_settings ):
164- result = app .config .has_foundry_config ()
165- assert result is False
135+ result = app .config .has_foundry_config ()
136+ assert result is False
166137
167138 def test_has_openai_config_true (self ):
168139 """Test has_openai_config returns True when both endpoint and api_key are configured"""
169140 with patch ("app.config.settings" ) as mock_settings :
170141 mock_settings .azure_openai_endpoint = "https://test.openai.azure.com"
171142 mock_settings .azure_openai_api_key = "test-api-key"
172- import app .config
173- with patch .object (app .config , "settings" , mock_settings ):
174- result = app .config .has_openai_config ()
175- assert result is True
143+ result = app .config .has_openai_config ()
144+ assert result is True
176145
177146 def test_has_openai_config_false_no_endpoint (self ):
178147 """Test has_openai_config returns False when endpoint is missing"""
179148 with patch ("app.config.settings" ) as mock_settings :
180149 mock_settings .azure_openai_endpoint = None
181150 mock_settings .azure_openai_api_key = "test-api-key"
182- import app .config
183- with patch .object (app .config , "settings" , mock_settings ):
184- result = app .config .has_openai_config ()
185- assert result is False
151+ result = app .config .has_openai_config ()
152+ assert result is False
186153
187154 def test_has_openai_config_false_no_api_key (self ):
188155 """Test has_openai_config returns False when api_key is missing"""
189156 with patch ("app.config.settings" ) as mock_settings :
190157 mock_settings .azure_openai_endpoint = "https://test.openai.azure.com"
191158 mock_settings .azure_openai_api_key = None
192- import app .config
193- with patch .object (app .config , "settings" , mock_settings ):
194- result = app .config .has_openai_config ()
195- assert result is False
159+ result = app .config .has_openai_config ()
160+ assert result is False
196161
197162
198163class TestSettingsProperties :
199164 """Test Settings class properties"""
200165
201166 def test_allowed_origins_parses_comma_separated_string (self ):
202167 """Test allowed_origins property parses comma-separated origins"""
203- from app .config import Settings
204-
205- settings = Settings (allowed_origins_str = "http://localhost:5173,http://localhost:3000" )
168+ settings = app .config .Settings (allowed_origins_str = "http://localhost:5173,http://localhost:3000" )
206169 origins = settings .allowed_origins
207170
208171 assert len (origins ) == 2
@@ -211,9 +174,7 @@ def test_allowed_origins_parses_comma_separated_string(self):
211174
212175 def test_allowed_origins_handles_whitespace (self ):
213176 """Test allowed_origins property strips whitespace"""
214- from app .config import Settings
215-
216- settings = Settings (allowed_origins_str = " http://localhost:5173 , http://localhost:3000 " )
177+ settings = app .config .Settings (allowed_origins_str = " http://localhost:5173 , http://localhost:3000 " )
217178 origins = settings .allowed_origins
218179
219180 assert len (origins ) == 2
@@ -222,9 +183,7 @@ def test_allowed_origins_handles_whitespace(self):
222183
223184 def test_allowed_origins_handles_empty_entries (self ):
224185 """Test allowed_origins property filters empty entries"""
225- from app .config import Settings
226-
227- settings = Settings (allowed_origins_str = "http://localhost:5173,,http://localhost:3000," )
186+ settings = app .config .Settings (allowed_origins_str = "http://localhost:5173,,http://localhost:3000," )
228187 origins = settings .allowed_origins
229188
230189 assert len (origins ) == 2
@@ -233,9 +192,7 @@ def test_allowed_origins_handles_empty_entries(self):
233192
234193 def test_allowed_origins_single_origin (self ):
235194 """Test allowed_origins property with single origin"""
236- from app .config import Settings
237-
238- settings = Settings (allowed_origins_str = "http://localhost:5173" )
195+ settings = app .config .Settings (allowed_origins_str = "http://localhost:5173" )
239196 origins = settings .allowed_origins
240197
241198 assert len (origins ) == 1
0 commit comments