Skip to content

Commit 49a54da

Browse files
Merge pull request #790 from microsoft/macae-v4-unittestcases-kd
test: Macae v4 unittestcases kd
2 parents d8a4ef7 + bdd15df commit 49a54da

39 files changed

Lines changed: 20019 additions & 24 deletions

.github/workflows/test.yml

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ on:
44
push:
55
branches:
66
- main
7-
- dev
8-
- demo
9-
- hotfix
7+
- demo-v4
8+
- dev-v4
109
paths:
1110
- 'src/backend/**/*.py'
1211
- 'src/tests/**/*.py'
@@ -24,9 +23,8 @@ on:
2423
- synchronize
2524
branches:
2625
- main
27-
- dev
28-
- demo
29-
- hotfix
26+
- demo-v4
27+
- dev-v4
3028
paths:
3129
- 'src/backend/**/*.py'
3230
- 'src/tests/**/*.py'
@@ -69,25 +67,22 @@ jobs:
6967
- name: Run tests with coverage
7068
if: env.skip_tests == 'false'
7169
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
70+
if python -m pytest src/tests/backend/test_app.py --cov=backend --cov-config=.coveragerc -q > /dev/null 2>&1 && \
71+
python -m pytest src/tests/backend --cov=backend --cov-append --cov-report=term --cov-report=xml --cov-config=.coveragerc --ignore=src/tests/backend/test_app.py; then
72+
echo "Tests completed, checking coverage."
73+
if [ -f coverage.xml ]; then
74+
COVERAGE=$(python -c "import xml.etree.ElementTree as ET; tree = ET.parse('coverage.xml'); root = tree.getroot(); print(float(root.attrib.get('line-rate', 0)) * 100)")
75+
echo "Overall coverage: $COVERAGE%"
76+
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
77+
echo "Coverage is below 80%, failing the job."
78+
exit 1
79+
fi
80+
fi
81+
else
82+
echo "No tests found, skipping coverage check."
83+
fi
8484
85-
# - name: Run tests with coverage
86-
# if: env.skip_tests == 'false'
87-
# run: |
88-
# pytest --cov=. --cov-report=term-missing --cov-report=xml --ignore=tests/e2e-test/tests
89-
9085
- name: Skip coverage report if no tests
9186
if: env.skip_tests == 'true'
9287
run: |
93-
echo "Skipping coverage report because no tests were found."
88+
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)