|
8 | 8 | delete_all_conversations, |
9 | 9 | generate_title, |
10 | 10 | init_cosmosdb_client, |
11 | | - init_openai_client, |
| 11 | + init_ai_projects_client, |
12 | 12 | stream_chat_request, |
13 | 13 | ) |
14 | 14 | from quart import Response |
@@ -78,15 +78,16 @@ def test_create_app(): |
78 | 78 | assert "routes" in app.blueprints |
79 | 79 |
|
80 | 80 |
|
81 | | -@patch("app.get_bearer_token_provider") |
82 | | -@patch("app.AsyncAzureOpenAI") |
83 | | -def test_init_openai_client(mock_async_openai, mock_token_provider): |
84 | | - mock_token_provider.return_value = MagicMock() |
85 | | - mock_async_openai.return_value = MagicMock() |
| 81 | +@patch("app.AIProjectClient") |
| 82 | +def test_init_ai_projects_client(mock_ai_projects_client): |
| 83 | + mock_project_instance = MagicMock() |
| 84 | + mock_openai_client = MagicMock() |
| 85 | + mock_project_instance.inference.get_azure_openai_client.return_value = mock_openai_client |
| 86 | + mock_ai_projects_client.return_value = mock_project_instance |
86 | 87 |
|
87 | | - client = init_openai_client() |
| 88 | + client = init_ai_projects_client() |
88 | 89 | assert client is not None |
89 | | - mock_async_openai.assert_called_once() |
| 90 | + mock_ai_projects_client.assert_called_once() |
90 | 91 |
|
91 | 92 |
|
92 | 93 | @patch("app.CosmosConversationClient") |
@@ -1179,27 +1180,27 @@ async def test_add_conversation_conversation_not_found( |
1179 | 1180 |
|
1180 | 1181 |
|
1181 | 1182 | @pytest.mark.asyncio |
1182 | | -@patch("app.init_openai_client") |
1183 | | -async def test_generate_title_success(mock_init_openai_client): |
| 1183 | +@patch("app.init_ai_projects_client") |
| 1184 | +async def test_generate_title_success(mock_init_ai_projects_client): |
1184 | 1185 | mock_openai_client = AsyncMock() |
1185 | 1186 | mock_openai_client.chat.completions.create.return_value = MagicMock( |
1186 | 1187 | choices=[ |
1187 | 1188 | MagicMock(message=MagicMock(content=json.dumps({"title": "Test Title"}))) |
1188 | 1189 | ] |
1189 | 1190 | ) |
1190 | | - mock_init_openai_client.return_value = mock_openai_client |
| 1191 | + mock_init_ai_projects_client.return_value = mock_openai_client |
1191 | 1192 |
|
1192 | 1193 | conversation_messages = [{"role": "user", "content": "Hello"}] |
1193 | 1194 | title = await generate_title(conversation_messages) |
1194 | 1195 | assert title == "Test Title" |
1195 | 1196 |
|
1196 | 1197 |
|
1197 | 1198 | @pytest.mark.asyncio |
1198 | | -@patch("app.init_openai_client") |
1199 | | -async def test_generate_title_exception(mock_init_openai_client): |
| 1199 | +@patch("app.init_ai_projects_client") |
| 1200 | +async def test_generate_title_exception(mock_init_ai_projects_client): |
1200 | 1201 | mock_openai_client = AsyncMock() |
1201 | 1202 | mock_openai_client.chat.completions.create.side_effect = Exception("API error") |
1202 | | - mock_init_openai_client.return_value = mock_openai_client |
| 1203 | + mock_init_ai_projects_client.return_value = mock_openai_client |
1203 | 1204 |
|
1204 | 1205 | conversation_messages = [{"role": "user", "content": "Hello"}] |
1205 | 1206 | title = await generate_title(conversation_messages) |
|
0 commit comments