SESSION SUMMARY: - Started at 7194 tests, 80% raw / 93.4% real - Ended at 7778 tests, 84% raw / 98.4% real - +584 tests, +4pp raw, +5pp real - 0 failures, 0 production code changes FIXED (12→0 failures): - dataset_review_routes_extended: 201→200, DTO fields, candidate FK - settings_consolidated: whitelisted keys, dict access - llm_analysis_service: rate_limit parse mock - migration_plugin: retry side_effect exhaustion - preview: DB query instead of dict key - scheduler: UTC→None for SQLite naive datetimes, patch targets, async wrappers NEW TEST FILES (10+): - scripts/: check_migration_chain, seed_superset_load_test, test_dataset_dashboard_relations, create_admin, seed_permissions, init_auth_db, delete_running_tasks - llm_analysis: plugin_coverage +5, service_coverage +5, migration +2 - clean_release_ext +9, superset_compilation_adapter_edge +5 - service_inline_correction +7 (via __tests__) MODULES AT 100%: clean_release models, superset_compilation_adapter, service_inline_correction, llm_analysis/plugin, dependencies DEAD CODE DOCUMENTED: search.py (L206-215 indentation bug), llm_analysis/service (L459 HTTPS, L594 duplicate tab, L639-697 CDP-only)
83 lines
3.1 KiB
Python
83 lines
3.1 KiB
Python
# #region TestInitAuthDb [C:2] [TYPE Module] [SEMANTICS test,auth,database,init]
|
|
# @BRIEF Tests for init_auth_db.py script (mocked dependencies).
|
|
# @RELATION BINDS_TO -> [InitAuthDbScript]
|
|
# @TEST_EDGE: run_init_calls_all_steps -> Calls ensure_encryption_key, init_db, seed_permissions
|
|
# @TEST_EDGE: run_init_exception -> Exits 1 on failure
|
|
import sys
|
|
from pathlib import Path
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent.parent / "src"))
|
|
|
|
|
|
# =============================================================================
|
|
# run_init
|
|
# =============================================================================
|
|
|
|
class TestRunInit:
|
|
"""Tests for init_auth_db.run_init()."""
|
|
|
|
@patch("src.scripts.init_auth_db.seed_permissions")
|
|
@patch("src.scripts.init_auth_db.init_db")
|
|
@patch("src.scripts.init_auth_db.ensure_encryption_key")
|
|
def test_calls_all_steps(self, mock_enc_key, mock_init_db, mock_seed):
|
|
"""Happy: all three steps called in order."""
|
|
from src.scripts.init_auth_db import run_init
|
|
|
|
run_init()
|
|
|
|
mock_enc_key.assert_called_once()
|
|
mock_init_db.assert_called_once()
|
|
mock_seed.assert_called_once()
|
|
|
|
@patch("src.scripts.init_auth_db.seed_permissions")
|
|
@patch("src.scripts.init_auth_db.init_db")
|
|
@patch("src.scripts.init_auth_db.ensure_encryption_key")
|
|
def test_init_db_failure_exits(self, mock_enc_key, mock_init_db, mock_seed):
|
|
"""Edge: init_db failure causes sys.exit(1)."""
|
|
from src.scripts.init_auth_db import run_init
|
|
|
|
mock_init_db.side_effect = Exception("DB init failed")
|
|
|
|
with pytest.raises(SystemExit) as exc:
|
|
run_init()
|
|
assert exc.value.code == 1
|
|
|
|
# seed_permissions should NOT be called if init_db fails
|
|
mock_seed.assert_not_called()
|
|
|
|
@patch("src.scripts.init_auth_db.seed_permissions")
|
|
@patch("src.scripts.init_auth_db.init_db")
|
|
@patch("src.scripts.init_auth_db.ensure_encryption_key")
|
|
def test_encryption_key_failure_exits(self, mock_enc_key, mock_init_db, mock_seed):
|
|
"""Edge: ensure_encryption_key failure causes sys.exit(1)."""
|
|
from src.scripts.init_auth_db import run_init
|
|
|
|
mock_enc_key.side_effect = Exception("Key error")
|
|
|
|
with pytest.raises(SystemExit) as exc:
|
|
run_init()
|
|
assert exc.value.code == 1
|
|
|
|
mock_init_db.assert_not_called()
|
|
mock_seed.assert_not_called()
|
|
|
|
@patch("src.scripts.init_auth_db.seed_permissions")
|
|
@patch("src.scripts.init_auth_db.init_db")
|
|
@patch("src.scripts.init_auth_db.ensure_encryption_key")
|
|
def test_seed_permissions_failure_exits(self, mock_enc_key, mock_init_db, mock_seed):
|
|
"""Edge: seed_permissions failure causes sys.exit(1)."""
|
|
from src.scripts.init_auth_db import run_init
|
|
|
|
mock_seed.side_effect = Exception("Seed error")
|
|
|
|
with pytest.raises(SystemExit) as exc:
|
|
run_init()
|
|
assert exc.value.code == 1
|
|
|
|
mock_enc_key.assert_called_once()
|
|
mock_init_db.assert_called_once()
|
|
# #endregion TestInitAuthDb
|