Files
OSIT-AE-API-FastAPI/tests/unit/test_unit_schema_logic.py
Scott Idem b2384f2869 Tests: Reorganize test suite into functional subdirectories
- 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.
2026-01-16 10:46:19 -05:00

45 lines
1.3 KiB
Python

import sys
import os
import json
from unittest.mock import MagicMock
# Add current directory to path
sys.path.append(os.getcwd())
# 1. Mock EVERYTHING before importing the target
mock_config = MagicMock()
mock_config.settings = MagicMock()
sys.modules["app.config"] = mock_config
mock_db = MagicMock()
sys.modules["app.db_sql"] = MagicMock(db=mock_db)
# 2. Mock DESCRIBE result
mock_row = [
("created_on", "timestamp", "NO", "", "current_timestamp()", "")
]
mock_db.execute.return_value.fetchall.return_value = mock_row
# 3. Import and test
from app.lib_schema_v3 import get_object_schema_info
def test_isolated_logic():
# We need to mock obj_type_kv_li as well
import app.lib_schema_v3
app.lib_schema_v3.obj_type_kv_li = {"journal": {"tbl": "journal", "mdl": MagicMock()}}
print("Testing isolated logic for get_object_schema_info...")
info = get_object_schema_info("journal")
col = info["database"]["columns"][0]
print(f"Resulting column info: {json.dumps(col, indent=2)}")
assert col["field"] == "created_on"
assert col["db_type"] == "timestamp"
assert col["required"] is True
assert col["db_default"] == "current_timestamp()"
print("\nIsolated test passed! The logic in lib_schema_v3 is correct.")
if __name__ == "__main__":
test_isolated_logic()