Skip to content

Commit 5b669f1

Browse files
committed
🧪 Add global test configuration and common fixtures for improved test, refactor test files to use pytest and improve mock handling
- Converted unittest test cases to pytest format across multiple test files. - Simplified mock setups using pytest-mock for better readability and maintainability. - Removed unnecessary imports and legacy code to streamline test execution. - Enhanced test coverage for utility functions in various modules.
1 parent d095ece commit 5b669f1

26 files changed

+539
-549
lines changed

‎test/backend/agents/test_create_agent_info.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from pathlib import Path
66
from unittest.mock import AsyncMock, MagicMock, patch, Mock, PropertyMock
77

8-
from test.common.env_test_utils import bootstrap_env
8+
from test.common.test_mocks import bootstrap_test_env
99

10-
env_state = bootstrap_env()
10+
env_state = bootstrap_test_env()
1111
consts_const = env_state["mock_const"]
1212
TEST_ROOT = Path(__file__).resolve().parents[2]
1313
PROJECT_ROOT = TEST_ROOT.parent

‎test/backend/app/test_image_app.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
if str(TEST_ROOT) not in sys.path:
99
sys.path.append(str(TEST_ROOT))
1010

11-
from test.common.env_test_utils import bootstrap_env
11+
from test.common.test_mocks import bootstrap_test_env
1212

13-
helpers_env = bootstrap_env()
13+
helpers_env = bootstrap_test_env()
1414

1515

1616
helpers_env["mock_const"].DATA_PROCESS_SERVICE = "http://mock-data-process-service"

‎test/backend/app/test_knowledge_summary_app.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212
if path not in sys.path:
1313
sys.path.insert(0, path)
1414

15-
# Patch environment variables before any imports that might use them
16-
os.environ.setdefault('MINIO_ENDPOINT', 'http://localhost:9000')
17-
os.environ.setdefault('MINIO_ACCESS_KEY', 'minioadmin')
18-
os.environ.setdefault('MINIO_SECRET_KEY', 'minioadmin')
19-
os.environ.setdefault('MINIO_REGION', 'us-east-1')
20-
os.environ.setdefault('MINIO_DEFAULT_BUCKET', 'test-bucket')
15+
# Environment variables are now configured in conftest.py
2116

2217
# Mock external dependencies
2318
sys.modules['boto3'] = MagicMock()

‎test/backend/app/test_mock_user_management_app.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@
77
current_dir = os.path.dirname(os.path.abspath(__file__))
88
sys.path.insert(0, os.path.join(current_dir, "../../../backend"))
99

10-
# Patch environment variables before any imports that might use them
11-
os.environ.setdefault('MINIO_ENDPOINT', 'http://localhost:9000')
12-
os.environ.setdefault('MINIO_ACCESS_KEY', 'minioadmin')
13-
os.environ.setdefault('MINIO_SECRET_KEY', 'minioadmin')
14-
os.environ.setdefault('MINIO_REGION', 'us-east-1')
15-
os.environ.setdefault('MINIO_DEFAULT_BUCKET', 'test-bucket')
10+
# Environment variables are now configured in conftest.py
1611

1712
boto3_mock = MagicMock()
1813
minio_client_mock = MagicMock()

‎test/backend/app/test_model_managment_app.py‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717
sys.path.insert(0, BACKEND_ROOT)
1818

1919
# Patch environment variables before any imports that might use them
20-
os.environ.setdefault('MINIO_ENDPOINT', 'http://localhost:9000')
21-
os.environ.setdefault('MINIO_ACCESS_KEY', 'minioadmin')
22-
os.environ.setdefault('MINIO_SECRET_KEY', 'minioadmin')
23-
os.environ.setdefault('MINIO_REGION', 'us-east-1')
24-
os.environ.setdefault('MINIO_DEFAULT_BUCKET', 'test-bucket')
20+
# Environment variables are now configured in conftest.py
2521

2622
# Patch storage factory and MinIO config validation to avoid errors during initialization
2723
# These patches must be started before any imports that use MinioClient

‎test/backend/app/test_vectordatabase_app.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@
1818
backend_dir = os.path.abspath(os.path.join(current_dir, "../../../backend"))
1919
sys.path.insert(0, backend_dir)
2020

21-
# Patch environment variables before any imports that might use them
22-
os.environ.setdefault('MINIO_ENDPOINT', 'http://localhost:9000')
23-
os.environ.setdefault('MINIO_ACCESS_KEY', 'minioadmin')
24-
os.environ.setdefault('MINIO_SECRET_KEY', 'minioadmin')
25-
os.environ.setdefault('MINIO_REGION', 'us-east-1')
26-
os.environ.setdefault('MINIO_DEFAULT_BUCKET', 'test-bucket')
21+
# Environment variables are now configured in conftest.py
2722

2823
boto3_mock = MagicMock()
2924
minio_client_mock = MagicMock()

‎test/backend/database/test_attachment_db.py‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,10 @@
1414
sys.path.insert(0, os.path.abspath(os.path.join(
1515
os.path.dirname(__file__), '..', '..', '..')))
1616

17-
# Mock environment variables before imports
18-
os.environ.setdefault('MINIO_ENDPOINT', 'http://localhost:9000')
19-
os.environ.setdefault('MINIO_ACCESS_KEY', 'minioadmin')
20-
os.environ.setdefault('MINIO_SECRET_KEY', 'minioadmin')
21-
os.environ.setdefault('MINIO_REGION', 'us-east-1')
22-
os.environ.setdefault('MINIO_DEFAULT_BUCKET', 'test-bucket')
23-
2417
# Mock consts module
2518
consts_mock = MagicMock()
2619
consts_mock.const = MagicMock()
27-
consts_mock.const.MINIO_ENDPOINT = os.environ.get('MINIO_ENDPOINT', 'http://localhost:9000')
28-
consts_mock.const.MINIO_ACCESS_KEY = os.environ.get('MINIO_ACCESS_KEY', 'minioadmin')
29-
consts_mock.const.MINIO_SECRET_KEY = os.environ.get('MINIO_SECRET_KEY', 'minioadmin')
30-
consts_mock.const.MINIO_REGION = os.environ.get('MINIO_REGION', 'us-east-1')
31-
consts_mock.const.MINIO_DEFAULT_BUCKET = os.environ.get('MINIO_DEFAULT_BUCKET', 'test-bucket')
20+
# Environment variables are now configured in conftest.py
3221

3322
sys.modules['consts'] = consts_mock
3423
sys.modules['consts.const'] = consts_mock.const

0 commit comments

Comments
 (0)