mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: Improved main package test coverage (#445)
* Fixed failing foundry tests and improved main coverage * Add back mistakenly deleted code * Update python/packages/main/tests/openai/test_openai_assistants_client.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/packages/main/tests/openai/test_openai_assistants_client.py Co-authored-by: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com> * Small fix --------- Co-authored-by: Giles Odigwe <gilesodigwe@microsoft.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
feb4e908ae
commit
123a0bca10
@@ -23,6 +23,7 @@ from azure.ai.agents.models import (
|
||||
SubmitToolOutputsAction,
|
||||
ThreadRun,
|
||||
)
|
||||
from azure.core.credentials_async import AsyncTokenCredential
|
||||
from azure.identity.aio import DefaultAzureCredential
|
||||
from pydantic import Field, ValidationError
|
||||
|
||||
@@ -114,6 +115,48 @@ def test_foundry_chat_client_init_auto_create_client(
|
||||
assert not chat_client._should_delete_agent # type: ignore
|
||||
|
||||
|
||||
def test_foundry_chat_client_init_missing_project_endpoint() -> None:
|
||||
"""Test FoundryChatClient initialization when project_endpoint is missing and no client provided."""
|
||||
# Mock FoundrySettings to return settings with None project_endpoint
|
||||
with patch("agent_framework_foundry._chat_client.FoundrySettings") as mock_settings:
|
||||
mock_settings_instance = MagicMock()
|
||||
mock_settings_instance.project_endpoint = None # This should trigger the error
|
||||
mock_settings_instance.model_deployment_name = "test-model"
|
||||
mock_settings_instance.agent_name = "test-agent"
|
||||
mock_settings.return_value = mock_settings_instance
|
||||
|
||||
with pytest.raises(
|
||||
ServiceInitializationError, match="Project endpoint is required when client is not provided"
|
||||
):
|
||||
FoundryChatClient(
|
||||
client=None,
|
||||
agent_id=None,
|
||||
project_endpoint=None, # Missing endpoint
|
||||
model_deployment_name="test-model",
|
||||
async_ad_credential=AsyncMock(spec=AsyncTokenCredential),
|
||||
)
|
||||
|
||||
|
||||
def test_foundry_chat_client_init_missing_model_deployment_for_agent_creation() -> None:
|
||||
"""Test FoundryChatClient initialization when model deployment is missing for agent creation."""
|
||||
# Mock FoundrySettings to return settings with None model_deployment_name
|
||||
with patch("agent_framework_foundry._chat_client.FoundrySettings") as mock_settings:
|
||||
mock_settings_instance = MagicMock()
|
||||
mock_settings_instance.project_endpoint = "https://test.com"
|
||||
mock_settings_instance.model_deployment_name = None # This should trigger the error
|
||||
mock_settings_instance.agent_name = "test-agent"
|
||||
mock_settings.return_value = mock_settings_instance
|
||||
|
||||
with pytest.raises(ServiceInitializationError, match="Model deployment name is required for agent creation"):
|
||||
FoundryChatClient(
|
||||
client=None,
|
||||
agent_id=None, # No existing agent
|
||||
project_endpoint="https://test.com",
|
||||
model_deployment_name=None, # Missing for agent creation
|
||||
async_ad_credential=AsyncMock(spec=AsyncTokenCredential),
|
||||
)
|
||||
|
||||
|
||||
def test_foundry_chat_client_from_dict(mock_ai_project_client: MagicMock) -> None:
|
||||
"""Test FoundryChatClient.from_dict method."""
|
||||
settings = {
|
||||
|
||||
Reference in New Issue
Block a user