Files
OSIT-AE-API-FastAPI/tests/archive/test_int_email_live_DEBUG.py
Scott Idem 1053d8a81b fix(sql): handle record_id=0 correctly in CRUD utilities
Updated sql_select, sql_update, and sql_delete to use explicit 'is not None' checks for record_id. This prevents falsy ID values (like 0) from triggering generic table scans or failing to filter, which was causing the config bootstrap to accidentally load record ID 1 when ID 0 was requested.
2026-02-06 12:53:59 -05:00

78 lines
2.5 KiB
Python

import sys
import os
import unittest
from unittest.mock import MagicMock
# Add project root to path
sys.path.append(os.getcwd())
# 1. Mock app.log
mock_log = MagicMock()
def simple_decorator(func):
def wrapper(*args, **kwargs): return func(*args, **kwargs)
return wrapper
mock_log.logger_reset = simple_decorator
sys.modules['app.log'] = mock_log
# 2. Mock app.config with REAL DB credentials for connectivity
mock_config = MagicMock()
mock_settings = MagicMock()
# Credentials extracted from .env
DB_USER = "aether_dev"
DB_PASS = "$1sky.AE_dev.2023"
DB_SERVER = "vpn-db.oneskyit.com"
DB_PORT = "3306"
DB_NAME = "aether_dev"
mock_settings.SQLALCHEMY_DB_URI = f"mysql://{DB_USER}:{DB_PASS}@{DB_SERVER}:{DB_PORT}/{DB_NAME}"
mock_settings.DB = {
"pool_recycle": 1800,
"connect_timeout": 20
}
mock_settings.SMTP = {} # Will be populated during test
mock_config.settings = mock_settings
sys.modules['app.config'] = mock_config
# 3. Import components
from app.lib_email import send_email
from app.db_sql import sql_select
class TestLiveEmail(unittest.TestCase):
def test_live_smtp_connection(self):
"""
Verifies SMTP authentication using credentials from the CFG table.
"""
print("\n--- Testing LIVE SMTP Connection via DB Config (ID 7) ---")
# Fetch real credentials from DB (ID 7 corresponds to your dev environment)
cfg = sql_select(table_name='cfg', record_id=7, as_list=False)
if not cfg:
self.fail("Could not load CFG record 7 from database.")
print(f"SMTP Server: {cfg['smtp_server']}")
print(f"SMTP User: {cfg['smtp_username']}")
# Manually inject settings into the mocked settings object
mock_settings.SMTP = {
'server': cfg['smtp_server'],
'port': str(cfg['smtp_port']),
'username': cfg['smtp_username'],
'password': cfg['smtp_password']
}
# Attempt login validation
result = send_email(
from_email="noreply@oneskyit.com",
to_email="it+tech@oneskyit.com",
subject="Aether System Test: SMTP Validation",
body_html="<p>Validation of the Aether API SMTP configuration.</p>",
test=True # Verify LOGIN but NOT send message
)
print(f"Result: {result}")
self.assertTrue(result, "SMTP Authentication Failed. Check credentials in CFG table ID 7.")
if __name__ == '__main__':
unittest.main()