test: add TestEntity tests and fix test infrastructure (222 green)

- Add test_test_entity.py with 46 pure unit tests covering the full domain entity

- Fix _FakeSettings in 11 test files (REPORT_TEMPLATES_DIR, JIRA, TEMPO)

- Fix stale db.commit assertions to db.flush after UoW refactor

- Add missing mock fields for TestEntity.from_orm compatibility

- Make database.py skip pool args for SQLite in test environment

- Disable slowapi rate limiter in test client fixture

- Inject test engine into app.database to fix threading errors

- Update role assertions to match current require_any_role policy

- Mark 6 legacy V1 endpoint tests as xfail (replaced by V2 workflow)
This commit is contained in:
2026-02-18 15:29:24 +01:00
parent bc8025ffcf
commit 9e204b78ec
17 changed files with 774 additions and 47 deletions

View File

@@ -56,6 +56,23 @@ class _FakeSettings:
SCORING_WEIGHT_D3FEND = 15
SCORING_WEIGHT_FRESHNESS = 15
SCORING_WEIGHT_PLATFORM_DIVERSITY = 10
REPORT_TEMPLATES_DIR = "app/templates/reports"
REPORT_OUTPUT_DIR = "/tmp/aegis_reports"
COMPANY_NAME = "Test Org"
COMPANY_LOGO_PATH = "app/templates/reports/assets/logo.png"
JIRA_ENABLED = False
JIRA_URL = ""
JIRA_USERNAME = ""
JIRA_API_TOKEN = ""
JIRA_IS_CLOUD = True
JIRA_DEFAULT_PROJECT = ""
JIRA_ISSUE_TYPE_TEST = "Task"
JIRA_ISSUE_TYPE_CAMPAIGN = "Epic"
TEMPO_ENABLED = False
TEMPO_API_TOKEN = ""
TEMPO_DEFAULT_WORK_TYPE = "Red Team"
NVD_API_KEY = ""
STALE_THRESHOLD_DAYS = 365
config_mod.settings = _FakeSettings()
@@ -137,6 +154,11 @@ def _make_test(state: TestState = TestState.draft, **kwargs) -> MagicMock:
t.blue_validated_at = None
t.blue_validation_notes = None
t.execution_date = None
t.red_started_at = None
t.blue_started_at = None
t.paused_at = None
t.red_paused_seconds = 0
t.blue_paused_seconds = 0
return t
@@ -166,7 +188,7 @@ def test_draft_to_red_executing(mock_log):
assert result.state == TestState.red_executing
assert result.execution_date is not None
db.commit.assert_called()
db.flush.assert_called()
mock_log.assert_called()
print(" [PASS] Transition draft -> red_executing works")
@@ -206,7 +228,7 @@ def test_red_executing_to_blue_evaluating(mock_log):
result = submit_red_evidence(db, test, user)
assert result.state == TestState.blue_evaluating
db.commit.assert_called()
db.flush.assert_called()
mock_log.assert_called()
print(" [PASS] Transition red_executing -> blue_evaluating works")
@@ -273,7 +295,7 @@ def test_reopen_clears_validation(mock_log):
assert result.blue_validated_by is None
assert result.blue_validated_at is None
assert result.blue_validation_notes is None
db.commit.assert_called()
db.flush.assert_called()
print(" [PASS] reopen_test clears validation fields and moves to draft")