Skip to content

Commit 219b3c1

Browse files
authored
[evaluation] adding e2e tests for red team (#42504)
* adding e2e tests for red team * address comments * fix recordings so that playback works hopefully * fix test recordings * mock service discovery url for non fdp project tests * run tox black * fix faulty test * fix faulty test pt 2 * ignore problematic config * flaky test
1 parent 7cfa774 commit 219b3c1

File tree

4 files changed

+440
-3
lines changed

4 files changed

+440
-3
lines changed

sdk/evaluation/azure-ai-evaluation/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/evaluation/azure-ai-evaluation",
5-
"Tag": "python/evaluation/azure-ai-evaluation_1bc445d16b"
5+
"Tag": "python/evaluation/azure-ai-evaluation_468882d958"
66
}

sdk/evaluation/azure-ai-evaluation/tests/conftest.py

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pathlib import Path
1414
from typing import Any, Dict, Final, Generator, Mapping, Literal, Optional
1515
from unittest.mock import patch
16+
import requests
1617

1718
import pytest
1819
from ci_tools.variables import in_ci
@@ -301,7 +302,9 @@ def redirect_openai_requests():
301302

302303

303304
@pytest.fixture
304-
def recorded_test(recorded_test, redirect_openai_requests, redirect_asyncio_requests_traffic):
305+
def recorded_test(
306+
recorded_test, redirect_openai_requests, redirect_asyncio_requests_traffic, mock_azure_management_api
307+
):
305308
return recorded_test
306309

307310

@@ -628,3 +631,58 @@ def run_from_temp_dir(tmp_path):
628631
os.chdir(tmp_path)
629632
yield
630633
os.chdir(original_cwd)
634+
635+
636+
@pytest.fixture
637+
def mock_azure_management_api(project_scope: dict):
638+
"""Mock Azure Management API calls for service discovery during playback mode."""
639+
if is_live():
640+
# In live mode, let the real API calls go through
641+
yield
642+
return
643+
644+
# Mock response for the Azure Management API workspace discovery call
645+
mock_response_data = {
646+
"id": f"/subscriptions/{project_scope['subscription_id']}/resourceGroups/{project_scope['resource_group_name']}/providers/Microsoft.MachineLearningServices/workspaces/{project_scope['project_name']}",
647+
"name": project_scope["project_name"],
648+
"type": "Microsoft.MachineLearningServices/workspaces",
649+
"location": "swedencentral",
650+
"properties": {
651+
"discoveryUrl": "https://swedencentral.api.azureml.ms",
652+
"mlFlowTrackingUri": f"https://swedencentral.api.azureml.ms/mlflow/v1.0/subscriptions/{project_scope['subscription_id']}/resourceGroups/{project_scope['resource_group_name']}/providers/Microsoft.MachineLearningServices/workspaces/{project_scope['project_name']}",
653+
"workspaceId": project_scope["subscription_id"],
654+
"friendlyName": project_scope["project_name"],
655+
"description": "Test workspace for Azure AI evaluation",
656+
"keyVault": f"/subscriptions/{project_scope['subscription_id']}/resourceGroups/{project_scope['resource_group_name']}/providers/Microsoft.KeyVault/vaults/kv-{project_scope['project_name']}",
657+
"applicationInsights": f"/subscriptions/{project_scope['subscription_id']}/resourceGroups/{project_scope['resource_group_name']}/providers/Microsoft.Insights/components/ai-{project_scope['project_name']}",
658+
"storageAccount": f"/subscriptions/{project_scope['subscription_id']}/resourceGroups/{project_scope['resource_group_name']}/providers/Microsoft.Storage/storageAccounts/st{project_scope['project_name']}",
659+
},
660+
}
661+
662+
class MockResponse:
663+
def __init__(self, json_data, status_code):
664+
self.json_data = json_data
665+
self.status_code = status_code
666+
667+
def json(self):
668+
return self.json_data
669+
670+
def mock_requests_get(url, **kwargs):
671+
# Check if this is an Azure Management API call for workspace discovery
672+
if (
673+
"management.azure.com" in url
674+
and "Microsoft.MachineLearningServices/workspaces" in url
675+
and "api-version=" in url
676+
):
677+
return MockResponse(mock_response_data, 200)
678+
679+
# For any other requests, call the original function
680+
# This preserves other functionality while only mocking the specific API we need
681+
return original_requests_get(url, **kwargs)
682+
683+
# Store the original requests.get function
684+
original_requests_get = requests.get
685+
686+
# Apply the mock
687+
with patch("requests.get", side_effect=mock_requests_get):
688+
yield

0 commit comments

Comments
 (0)