- Categorized scripts into tests/unit/, tests/integration/, tests/e2e/, and tests/tools/. - Adopted consistent naming prefixes (test_unit_*, test_int_*, test_e2e_*, tool_*). - Renamed conftest_mock.py to mock_config_helper.py for clarity. - Updated test_int_boot_diagnosis.py with sys.path setup for root-level execution.
69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
import sys
|
|
import os
|
|
import asyncio
|
|
from unittest.mock import MagicMock, AsyncMock
|
|
|
|
# --- Environment Setup ---
|
|
sys.modules['redis'] = MagicMock()
|
|
sys.modules['sqlalchemy'] = MagicMock()
|
|
sys.modules['sqlalchemy.text'] = MagicMock()
|
|
sys.modules['app.config'] = MagicMock()
|
|
sys.modules['app.log'] = MagicMock()
|
|
sys.modules['app.lib_general'] = MagicMock()
|
|
|
|
# Mock app.db_sql
|
|
mock_db_sql = MagicMock()
|
|
sys.modules['app.db_sql'] = mock_db_sql
|
|
|
|
# Add project root to path
|
|
sys.path.append(os.getcwd())
|
|
|
|
# Mock the FastAPI response/request
|
|
mock_request = AsyncMock()
|
|
mock_response = MagicMock()
|
|
|
|
async def test_router_filtering():
|
|
print("\n--- Testing Router Filtering Logic ---")
|
|
|
|
# We'll simulate the filtering logic from the router directly
|
|
# since importing the full router requires heavy FastAPI setup.
|
|
|
|
# Input data with virtual fields
|
|
raw_data = {
|
|
"given_name": "Test",
|
|
"account_id_random": "abc-123",
|
|
"person_id_random": "p-456",
|
|
"person_full_name": "Test Person", # View field
|
|
"id_random": "keep-me"
|
|
}
|
|
|
|
# Logic from create_object/patch_obj
|
|
data_to_insert = raw_data.copy()
|
|
|
|
# 1. Filter _id_random
|
|
keys_to_remove = [k for k in data_to_insert.keys() if k.endswith('_id_random') and k != 'id_random']
|
|
for k in keys_to_remove:
|
|
del data_to_insert[k]
|
|
|
|
# 2. Filter model-specific (Manual simulation)
|
|
excluded = ['person_full_name']
|
|
for k in excluded:
|
|
if k in data_to_insert:
|
|
del data_to_insert[k]
|
|
|
|
print(f"Original keys: {list(raw_data.keys())}")
|
|
print(f"Filtered keys: {list(data_to_insert.keys())}")
|
|
|
|
if 'account_id_random' not in data_to_insert and 'person_full_name' not in data_to_insert:
|
|
print("✅ Router filtering correctly removed virtual/view fields.")
|
|
else:
|
|
print("❌ Router filtering FAILED to remove some fields.")
|
|
|
|
if 'id_random' in data_to_insert:
|
|
print("✅ Router filtering correctly kept 'id_random'.")
|
|
else:
|
|
print("❌ Router filtering accidentally removed 'id_random'.")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(test_router_filtering())
|