Skip to content

Commit ff91881

Browse files
Add unit tests for OrchestrationManager with comprehensive mocking
- Implemented unit tests for the OrchestrationManager class to ensure proper functionality. - Mocked external dependencies including Azure services and agent framework components. - Covered various scenarios including orchestration initialization, agent creation, and event processing. - Ensured error handling and edge cases are tested, including failures in client and manager creation. - Verified that orchestration runs correctly with different input types and handles WebSocket errors gracefully.
1 parent 19fd09d commit ff91881

36 files changed

Lines changed: 18079 additions & 37 deletions

.github/workflows/test.yml

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,8 @@ on:
44
push:
55
branches:
66
- main
7-
- dev
8-
- demo
9-
- hotfix
10-
paths:
11-
- 'src/backend/**/*.py'
12-
- 'src/tests/**/*.py'
13-
- 'src/mcp_server/**/*.py'
14-
- 'src/**/pyproject.toml'
15-
- 'pytest.ini'
16-
- 'conftest.py'
17-
- 'src/backend/requirements.txt'
18-
- '.github/workflows/test.yml'
7+
- dev-v4
8+
- macae-v4-unittestcases-kd
199
pull_request:
2010
types:
2111
- opened
@@ -24,18 +14,8 @@ on:
2414
- synchronize
2515
branches:
2616
- main
27-
- dev
28-
- demo
29-
- hotfix
30-
paths:
31-
- 'src/backend/**/*.py'
32-
- 'src/tests/**/*.py'
33-
- 'src/mcp_server/**/*.py'
34-
- 'pytest.ini'
35-
- 'conftest.py'
36-
- 'src/backend/requirements.txt'
37-
- 'src/**/pyproject.toml'
38-
- '.github/workflows/test.yml'
17+
- dev-v4
18+
- macae-v4-unittestcases-kd
3919

4020
jobs:
4121
test:
@@ -69,18 +49,8 @@ jobs:
6949
- name: Run tests with coverage
7050
if: env.skip_tests == 'false'
7151
run: |
72-
pytest --cov=. --cov-report=term-missing --cov-report=xml \
73-
--ignore=tests/e2e-test/tests \
74-
--ignore=src/backend/tests/test_app.py \
75-
--ignore=src/tests/agents/test_foundry_integration.py \
76-
--ignore=src/tests/mcp_server/test_factory.py \
77-
--ignore=src/tests/mcp_server/test_hr_service.py \
78-
--ignore=src/backend/tests/test_config.py \
79-
--ignore=src/tests/agents/test_human_approval_manager.py \
80-
--ignore=src/backend/tests/test_team_specific_methods.py \
81-
--ignore=src/backend/tests/models/test_messages.py \
82-
--ignore=src/backend/tests/test_otlp_tracing.py \
83-
--ignore=src/backend/tests/auth/test_auth_utils.py
52+
python -m pytest src/tests/backend/test_app.py --cov=backend --cov-config=.coveragerc
53+
python -m pytest src/tests/backend --cov=backend --cov-append --cov-report=term --cov-config=.coveragerc --ignore=src/tests/backend/test_app.py
8454
8555
# - name: Run tests with coverage
8656
# if: env.skip_tests == 'false'
@@ -90,4 +60,4 @@ jobs:
9060
- name: Skip coverage report if no tests
9161
if: env.skip_tests == 'true'
9262
run: |
93-
echo "Skipping coverage report because no tests were found."
63+
echo "Skipping coverage report because no tests were found."

src/tests/backend/auth/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
Empty __init__.py file for auth tests package.
3+
"""

src/tests/backend/auth/conftest.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
Test configuration for auth module tests.
3+
"""
4+
5+
import pytest
6+
import sys
7+
import os
8+
from unittest.mock import MagicMock, patch
9+
import base64
10+
import json
11+
12+
# Add the backend directory to the Python path for imports
13+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..', 'backend'))
14+
15+
@pytest.fixture
16+
def mock_sample_headers():
17+
"""Mock headers with EasyAuth authentication data."""
18+
return {
19+
"x-ms-client-principal-id": "12345678-1234-1234-1234-123456789012",
20+
"x-ms-client-principal-name": "testuser@example.com",
21+
"x-ms-client-principal-idp": "aad",
22+
"x-ms-token-aad-id-token": "sample.jwt.token",
23+
"x-ms-client-principal": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsInRpZCI6IjEyMzQ1Njc4LTEyMzQtMTIzNC0xMjM0LTEyMzQ1Njc4OTAxMiJ9"
24+
}
25+
26+
@pytest.fixture
27+
def mock_empty_headers():
28+
"""Mock headers without authentication data."""
29+
return {
30+
"content-type": "application/json",
31+
"user-agent": "test-agent"
32+
}
33+
34+
@pytest.fixture
35+
def mock_valid_base64_principal():
36+
"""Mock valid base64 encoded principal with tenant ID."""
37+
mock_data = {
38+
"typ": "JWT",
39+
"alg": "RS256",
40+
"tid": "87654321-4321-4321-4321-210987654321",
41+
"oid": "12345678-1234-1234-1234-123456789012",
42+
"preferred_username": "testuser@example.com",
43+
"name": "Test User"
44+
}
45+
46+
json_str = json.dumps(mock_data)
47+
return base64.b64encode(json_str.encode('utf-8')).decode('utf-8')
48+
49+
@pytest.fixture
50+
def mock_invalid_base64_principal():
51+
"""Mock invalid base64 encoded principal."""
52+
return "invalid_base64_string!"
53+
54+
@pytest.fixture
55+
def sample_user_mock():
56+
"""Mock sample_user data for testing."""
57+
return {
58+
"x-ms-client-principal-id": "00000000-0000-0000-0000-000000000000",
59+
"x-ms-client-principal-name": "testusername@contoso.com",
60+
"x-ms-client-principal-idp": "aad",
61+
"x-ms-token-aad-id-token": "your_aad_id_token",
62+
"x-ms-client-principal": "your_base_64_encoded_token"
63+
}

0 commit comments

Comments
 (0)