Skip to content

Commit fbce334

Browse files
fix unittestcase test_greeting_with_ai_project_client
1 parent 8e38c2e commit fbce334

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/tests/api/plugins/test_chat_with_data_plugin.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,39 @@ async def test_greeting(self, mock_azure_openai, mock_token_provider, mock_confi
6565
assert args["messages"][1]["content"] == "Hello"
6666

6767
@pytest.mark.asyncio
68+
@patch("plugins.chat_with_data_plugin.Config")
6869
@patch("plugins.chat_with_data_plugin.AIProjectClient")
6970
@patch("plugins.chat_with_data_plugin.DefaultAzureCredential")
70-
async def test_greeting_with_ai_project_client(self, mock_azure_credential, mock_ai_project_client, chat_plugin):
71+
async def test_greeting_with_ai_project_client(self, mock_azure_credential, mock_ai_project_client, mock_config, chat_plugin):
7172
# Setup AIProjectClient
7273
chat_plugin.use_ai_project_client = True
7374

7475
# Setup mock
75-
mock_project = MagicMock()
76-
mock_ai_project_client.from_connection_string.return_value = mock_project
77-
mock_client = MagicMock()
78-
mock_project.inference.get_chat_completions_client.return_value = mock_client
76+
mock_config_instance = MagicMock()
77+
mock_config_instance.ai_project_endpoint = "https://test-openai.azure.com/"
78+
mock_config.return_value = mock_config_instance
79+
mock_credential_instance = MagicMock()
80+
mock_azure_credential.return_value = mock_credential_instance
81+
mock_project_instance = MagicMock()
82+
mock_ai_project_client.return_value = mock_project_instance
83+
mock_chat_client = MagicMock()
84+
mock_project_instance.inference.get_chat_completions_client.return_value = mock_chat_client
7985
mock_completion = MagicMock()
8086
mock_completion.choices = [MagicMock()]
8187
mock_completion.choices[0].message.content = "Hello from AI Project Client"
82-
mock_client.complete.return_value = mock_completion
88+
mock_chat_client.complete.return_value = mock_completion
8389

8490
# Call the method
8591
result = await chat_plugin.greeting("Hello")
8692

8793
# Assertions
8894
assert result == "Hello from AI Project Client"
89-
mock_ai_project_client.from_connection_string.assert_called_once()
90-
mock_client.complete.assert_called_once()
91-
args = mock_client.complete.call_args[1]
95+
mock_ai_project_client.assert_called_once_with(
96+
endpoint=chat_plugin.ai_project_endpoint,
97+
credential=mock_credential_instance
98+
)
99+
mock_chat_client.complete.assert_called_once()
100+
args = mock_chat_client.complete.call_args[1]
92101
assert args["model"] == "gpt-4"
93102
assert args["temperature"] == 0
94103
assert len(args["messages"]) == 2

0 commit comments

Comments
 (0)