Skip to content

Commit 3c54f6d

Browse files
fix unittestcase
1 parent 360f1e1 commit 3c54f6d

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

src/tests/api/common/config/test_config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def test_config_initialization(mock_env_vars):
5252

5353
# AI Project Client
5454
assert config.use_ai_project_client is True
55-
assert config.azure_ai_project_conn_string == "Endpoint=sb://test/"
5655

5756
# Chat history config
5857
assert config.use_chat_history_enabled is True

src/tests/api/helpers/test_chat_helper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class TestChatHelper:
1515
@patch("helpers.chat_helper.Config")
16-
@patch("helpers.chat_helper.openai.AzureOpenAI")
16+
@patch("helpers.azure_openai_helper.openai.AzureOpenAI")
1717
def test_process_rag_response_success(self, mock_azure_openai, mock_config):
1818
# Mock the Azure OpenAI client and its response
1919
mock_client = MagicMock()
@@ -47,7 +47,7 @@ def test_process_rag_response_success(self, mock_azure_openai, mock_config):
4747
assert call_args["messages"][1]["role"] == "user"
4848

4949
@patch("helpers.chat_helper.Config")
50-
@patch("helpers.chat_helper.openai.AzureOpenAI")
50+
@patch("helpers.azure_openai_helper.openai.AzureOpenAI")
5151
def test_process_rag_response_with_code_blocks(self, mock_azure_openai, mock_config):
5252
# Mock the Azure OpenAI client and its response
5353
mock_client = MagicMock()
@@ -72,7 +72,7 @@ def test_process_rag_response_with_code_blocks(self, mock_azure_openai, mock_con
7272
assert result == expected
7373

7474
@patch("helpers.chat_helper.Config")
75-
@patch("helpers.chat_helper.openai.AzureOpenAI")
75+
@patch("helpers.azure_openai_helper.openai.AzureOpenAI")
7676
def test_process_rag_response_error(self, mock_azure_openai, mock_config):
7777
# Mock the Azure OpenAI client
7878
mock_client = MagicMock()
@@ -93,7 +93,7 @@ def test_process_rag_response_error(self, mock_azure_openai, mock_config):
9393
assert result["error"] == "Chart could not be generated from this data. Please ask a different question."
9494

9595
@patch("helpers.chat_helper.Config")
96-
@patch("helpers.chat_helper.openai.AzureOpenAI")
96+
@patch("helpers.azure_openai_helper.openai.AzureOpenAI")
9797
def test_process_rag_response_invalid_json(self, mock_azure_openai, mock_config):
9898
# Mock the Azure OpenAI client
9999
mock_client = MagicMock()

src/tests/api/plugins/test_chat_with_data_plugin.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def chat_plugin(mock_config):
2626

2727
class TestChatWithDataPlugin:
2828
@patch("plugins.chat_with_data_plugin.get_bearer_token_provider")
29-
@patch("plugins.chat_with_data_plugin.openai.AzureOpenAI")
29+
@patch("helpers.azure_openai_helper.openai.AzureOpenAI")
3030
@pytest.mark.asyncio
3131
async def test_greeting(self, mock_azure_openai, mock_token_provider, chat_plugin):
3232
# Setup mock token provider
@@ -92,7 +92,7 @@ async def test_greeting_with_ai_project_client(self, mock_azure_credential, mock
9292
assert args["messages"][1]["content"] == "Hello"
9393

9494
@pytest.mark.asyncio
95-
@patch("plugins.chat_with_data_plugin.openai.AzureOpenAI")
95+
@patch("helpers.azure_openai_helper.openai.AzureOpenAI")
9696
async def test_greeting_exception(self, mock_azure_openai, chat_plugin):
9797
# Setup mock to raise exception
9898
mock_client = MagicMock()
@@ -108,7 +108,7 @@ async def test_greeting_exception(self, mock_azure_openai, chat_plugin):
108108
@pytest.mark.asyncio
109109
@patch("plugins.chat_with_data_plugin.get_bearer_token_provider")
110110
@patch("plugins.chat_with_data_plugin.execute_sql_query")
111-
@patch("plugins.chat_with_data_plugin.openai.AzureOpenAI")
111+
@patch("helpers.azure_openai_helper.openai.AzureOpenAI")
112112
async def test_get_SQL_Response(self, mock_azure_openai, mock_execute_sql, mock_token_provider, chat_plugin):
113113

114114
# Setup mocks
@@ -166,7 +166,7 @@ async def test_get_SQL_Response_with_ai_project_client(self, mock_azure_credenti
166166

167167
@pytest.mark.asyncio
168168
@patch("plugins.chat_with_data_plugin.execute_sql_query")
169-
@patch("plugins.chat_with_data_plugin.openai.AzureOpenAI")
169+
@patch("helpers.azure_openai_helper.openai.AzureOpenAI")
170170
async def test_get_SQL_Response_exception(self, mock_azure_openai, mock_execute_sql, chat_plugin):
171171
# Setup mock to raise exception
172172
mock_client = MagicMock()
@@ -182,7 +182,7 @@ async def test_get_SQL_Response_exception(self, mock_azure_openai, mock_execute_
182182

183183
@pytest.mark.asyncio
184184
@patch("plugins.chat_with_data_plugin.get_bearer_token_provider")
185-
@patch("plugins.chat_with_data_plugin.openai.AzureOpenAI")
185+
@patch("helpers.azure_openai_helper.openai.AzureOpenAI")
186186
async def test_get_answers_from_calltranscripts(self, mock_azure_openai, mock_token_provider, chat_plugin):
187187
# Setup mock
188188
mock_token_provider.return_value = lambda: "fake_token"
@@ -216,7 +216,7 @@ async def test_get_answers_from_calltranscripts(self, mock_azure_openai, mock_to
216216
assert args["extra_body"]["data_sources"][0]["type"] == "azure_search"
217217

218218
@pytest.mark.asyncio
219-
@patch("plugins.chat_with_data_plugin.openai.AzureOpenAI")
219+
@patch("helpers.azure_openai_helper.openai.AzureOpenAI")
220220
async def test_get_answers_from_calltranscripts_with_citations(self, mock_azure_openai, chat_plugin):
221221
# Setup mock with citations in context
222222
mock_client = MagicMock()
@@ -251,7 +251,7 @@ async def test_get_answers_from_calltranscripts_with_citations(self, mock_azure_
251251
assert result.message.context.citations[0]["content"].endswith("...")
252252

253253
@pytest.mark.asyncio
254-
@patch("plugins.chat_with_data_plugin.openai.AzureOpenAI")
254+
@patch("helpers.azure_openai_helper.openai.AzureOpenAI")
255255
async def test_get_answers_from_calltranscripts_exception(self, mock_azure_openai, chat_plugin):
256256
# Setup mock to raise exception
257257
mock_client = MagicMock()

src/tests/api/services/test_chat_service.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def patched_imports(mock_format_stream, mock_openai, mock_agent_exception, mock_
3131
patch("services.chat_service.AzureAIAgentThread", mock_thread), \
3232
patch("services.chat_service.TruncationObject", mock_truncation), \
3333
patch("services.chat_service.AgentException", mock_agent_exception), \
34-
patch("services.chat_service.openai.AzureOpenAI", mock_openai), \
34+
patch("helpers.azure_openai_helper.openai.AzureOpenAI", mock_openai), \
3535
patch("services.chat_service.format_stream_response", mock_format_stream):
3636
from services.chat_service import ChatService, ExpCache
3737
return ChatService, ExpCache, {
@@ -173,7 +173,7 @@ def test_init(self, mock_config_class, mock_request):
173173
assert service.agent == mock_request.app.state.agent
174174
assert ChatService.thread_cache is not None
175175

176-
@patch('services.chat_service.openai.AzureOpenAI')
176+
@patch('helpers.azure_openai_helper.openai.AzureOpenAI')
177177
def test_process_rag_response_success(self, mock_openai_class, chat_service):
178178
"""Test successful RAG response processing."""
179179
# Setup mock OpenAI client
@@ -191,7 +191,7 @@ def test_process_rag_response_success(self, mock_openai_class, chat_service):
191191
assert result["data"]["labels"] == ["A", "B"]
192192
mock_client.chat.completions.create.assert_called_once()
193193

194-
@patch('services.chat_service.openai.AzureOpenAI')
194+
@patch('helpers.azure_openai_helper.openai.AzureOpenAI')
195195
def test_process_rag_response_invalid_json(self, mock_openai_class, chat_service):
196196
"""Test RAG response processing with invalid JSON."""
197197
# Setup mock OpenAI client
@@ -207,7 +207,7 @@ def test_process_rag_response_invalid_json(self, mock_openai_class, chat_service
207207
assert "error" in result
208208
assert result["error"] == "Chart could not be generated from this data. Please ask a different question."
209209

210-
@patch('services.chat_service.openai.AzureOpenAI')
210+
@patch('helpers.azure_openai_helper.openai.AzureOpenAI')
211211
def test_process_rag_response_exception(self, mock_openai_class, chat_service):
212212
"""Test RAG response processing with exception."""
213213
# Setup mock to raise exception

0 commit comments

Comments
 (0)