- Overhauled README.md to serve as a unified system index and WIP tracker. - Standardized documentation filenames (ARCH__, GUIDE__, PLAN__) for better discoverability. - Archived completed project plans and scopes. - Fixed regressions in unit tests (errors, models, email) caused by V3 architectural updates. - Ensured unit tests remain non-destructive and environment-independent via mocking.
68 lines
2.3 KiB
Python
68 lines
2.3 KiB
Python
import sys
|
|
import os
|
|
from unittest.mock import MagicMock
|
|
|
|
# --- Environment Setup ---
|
|
# Mocking heavy dependencies to allow running in restricted environments
|
|
sys.modules['redis'] = MagicMock()
|
|
sys.modules['sqlalchemy'] = MagicMock()
|
|
sys.modules['sqlalchemy.exc'] = MagicMock()
|
|
sys.modules['sqlalchemy.pool'] = MagicMock()
|
|
sys.modules['fastapi'] = MagicMock()
|
|
sys.modules['app.config'] = MagicMock()
|
|
sys.modules['html2text'] = MagicMock()
|
|
sys.modules['app.lib_email'] = MagicMock()
|
|
sys.modules['app.lib_export'] = MagicMock()
|
|
sys.modules['app.lib_jwt'] = MagicMock()
|
|
sys.modules['app.lib_hash'] = MagicMock()
|
|
sys.modules['app.log'] = MagicMock()
|
|
|
|
# Mock app.lib_general (needed for log/logging)
|
|
mock_lib_general = MagicMock()
|
|
mock_lib_general.log = MagicMock()
|
|
mock_lib_general.logging = MagicMock()
|
|
sys.modules['app.lib_general'] = mock_lib_general
|
|
|
|
mock_db_sql = MagicMock()
|
|
mock_db_sql.redis_lookup_id_random.return_value = 1
|
|
mock_db_sql.get_id_random.return_value = "mock_id"
|
|
sys.modules['app.db_sql'] = mock_db_sql
|
|
|
|
# Add project root to path
|
|
sys.path.append(os.getcwd())
|
|
|
|
# --- Imports ---
|
|
try:
|
|
from app.models.person_models import Person_Base
|
|
print("✅ Person_Base model imported.")
|
|
except Exception as e:
|
|
print(f"❌ Failed to import models: {e}")
|
|
sys.exit(1)
|
|
|
|
# --- Tests ---
|
|
def test_person_null_given_name():
|
|
"""Test that given_name=None is converted to empty string."""
|
|
try:
|
|
# In Pydantic V1, we test the validator classmethod directly if instantiation is too complex with mocks
|
|
val = Person_Base.given_name_validator(None)
|
|
if val == "":
|
|
print("✅ given_name validator: None -> '' (Success)")
|
|
else:
|
|
print(f"❌ given_name validator: Expected '', got {val!r}")
|
|
except Exception as e:
|
|
print(f"❌ test_person_null_given_name failed: {e}")
|
|
|
|
def test_person_null_allow_auth_key():
|
|
"""Test that allow_auth_key=None is converted to True."""
|
|
try:
|
|
val = Person_Base.allow_auth_key_validator(None)
|
|
if val is True:
|
|
print("✅ allow_auth_key validator: None -> True (Success)")
|
|
else:
|
|
print(f"❌ allow_auth_key validator: Expected True, got {val!r}")
|
|
except Exception as e:
|
|
print(f"❌ test_person_null_allow_auth_key failed: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
test_person_null_given_name()
|
|
test_person_null_allow_auth_key() |