Skip to content

Commit a1ec196

Browse files
Testcases
1 parent 70db478 commit a1ec196

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed

src/backend/tests/agents/test_tech_support.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import sys
3-
import pytest
43
from unittest.mock import MagicMock, AsyncMock, patch
4+
import pytest
55
from autogen_core.components.tools import FunctionTool
66

77
# Mock the azure.monitor.events.extension module globally
@@ -18,8 +18,6 @@
1818
os.environ["AZURE_OPENAI_API_VERSION"] = "2023-01-01"
1919
os.environ["AZURE_OPENAI_ENDPOINT"] = "https://mock-openai-endpoint"
2020

21-
22-
# Import the functions under test
2321
from src.backend.agents.tech_support import (
2422
send_welcome_email,
2523
set_up_office_365_account,
@@ -67,6 +65,7 @@
6765
get_tech_support_tools,
6866
)
6967

68+
7069
# Mock Azure DefaultAzureCredential
7170
@pytest.fixture(autouse=True)
7271
def mock_azure_credentials():

src/backend/tests/context/test_cosmos_memory.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
import os
21
import pytest
32
from unittest.mock import AsyncMock, patch
43
from azure.cosmos.partition_key import PartitionKey
5-
6-
# Set environment variables before importing modules that depend on them
7-
os.environ["COSMOSDB_ENDPOINT"] = "https://mock-endpoint"
8-
os.environ["COSMOSDB_KEY"] = "mock-key"
9-
os.environ["COSMOSDB_DATABASE"] = "mock-database"
10-
os.environ["COSMOSDB_CONTAINER"] = "mock-container"
11-
os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"] = "mock-deployment-name"
12-
os.environ["AZURE_OPENAI_API_VERSION"] = "2023-01-01"
13-
os.environ["AZURE_OPENAI_ENDPOINT"] = "https://mock-openai-endpoint"
14-
154
from src.backend.context.cosmos_memory import CosmosBufferedChatCompletionContext
165

6+
177
# Helper to create async iterable
188
async def async_iterable(mock_items):
199
"""Helper to create an async iterable."""
@@ -47,7 +37,9 @@ def mock_cosmos_client():
4737
# Mocking context methods
4838
mock_context = AsyncMock()
4939
mock_context.store_message = AsyncMock()
50-
mock_context.retrieve_messages = AsyncMock(return_value=async_iterable([{"id": "test_id", "content": "test_content"}]))
40+
mock_context.retrieve_messages = AsyncMock(
41+
return_value=async_iterable([{"id": "test_id", "content": "test_content"}])
42+
)
5143

5244
return mock_client, mock_container, mock_context
5345

@@ -74,4 +66,3 @@ async def test_initialize(mock_config, mock_cosmos_client):
7466
id="mock-container", partition_key=PartitionKey(path="/session_id")
7567
)
7668
assert context._container == mock_container
77-

src/backend/tests/test_app.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import os
22
import sys
3-
import pytest
43
from unittest.mock import MagicMock, patch
4+
import pytest
55
from fastapi.testclient import TestClient
66

7-
# Ensure the `src` folder is included in the Python path
8-
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../..")))
9-
107
# Mock Azure dependencies to prevent import errors
118
sys.modules["azure.monitor"] = MagicMock()
129
sys.modules["azure.monitor.events.extension"] = MagicMock()
@@ -17,16 +14,16 @@
1714
os.environ["COSMOSDB_KEY"] = "mock-key"
1815
os.environ["COSMOSDB_DATABASE"] = "mock-database"
1916
os.environ["COSMOSDB_CONTAINER"] = "mock-container"
20-
os.environ["APPLICATIONINSIGHTS_INSTRUMENTATION_KEY"] = "mock-instrumentation-key"
17+
os.environ[
18+
"APPLICATIONINSIGHTS_INSTRUMENTATION_KEY"
19+
] = "InstrumentationKey=mock-instrumentation-key;IngestionEndpoint=https://mock-ingestion-endpoint"
2120
os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"] = "mock-deployment-name"
2221
os.environ["AZURE_OPENAI_API_VERSION"] = "2023-01-01"
2322
os.environ["AZURE_OPENAI_ENDPOINT"] = "https://mock-openai-endpoint"
2423

2524
# Mock telemetry initialization to prevent errors
26-
patch("src.backend.app.configure_azure_monitor", MagicMock()).start()
27-
28-
# Import the FastAPI app after mocking dependencies
29-
from src.backend.app import app
25+
with patch("azure.monitor.opentelemetry.configure_azure_monitor", MagicMock()):
26+
from src.backend.app import app
3027

3128
# Initialize FastAPI test client
3229
client = TestClient(app)

0 commit comments

Comments
 (0)