Files
Aegis/backend/tests/test_template_existing_test_count.py
kitos 1c8fa436ab feat(backend): enforce campaign scheduling, add reviewer queue filter, tactic order, duplicate-test counts
- start_execution now blocks a test from starting before its campaign's
  start_date, closing a gap where the field was persisted but never
  enforced
- GET /tests gains a reviewer_id "my reviews" filter for the red_review/
  blue_review lead-gate stage, distinct from pending_validation_side
  (which only ever covered the later in_review stage and ignored
  assignment entirely)
- get_coverage_by_tactic now returns all 14 MITRE tactics in canonical
  kill-chain order instead of an alphabetical, partial list — the
  regular Dashboard and Executive Dashboard both consume this endpoint
  and previously disagreed on order/completeness
- test-template listing now includes existing_test_count per technique
  so the catalog can warn before creating a likely-duplicate test
2026-07-08 08:46:09 +02:00

42 lines
1.7 KiB
Python

"""Tests for the `existing_test_count` field on TestTemplateSummary.
Block 3 fix: the Test Catalog page had no way to know a technique already
had one or more tests, so operators could unknowingly instantiate a
duplicate from a template. list_templates now attaches a per-technique
test count so the frontend can show a warning badge.
"""
from app.models.enums import TestState
from app.models.technique import Technique
from app.models.test import Test
from app.models.test_template import TestTemplate
from app.services.test_template_service import list_templates
def test_existing_test_count_reflects_tests_for_that_technique(db, red_lead_user):
tech = Technique(mitre_id="T1055", name="Process Injection", tactic="defense-evasion", platforms=["windows"])
db.add(tech)
db.flush()
db.add(TestTemplate(mitre_technique_id="T1055", name="Injection template", source="custom"))
db.add(Test(technique_id=tech.id, name="Existing test 1", state=TestState.draft, created_by=red_lead_user.id))
db.add(Test(technique_id=tech.id, name="Existing test 2", state=TestState.validated, created_by=red_lead_user.id))
db.commit()
templates = list_templates(db, mitre_technique_id="T1055")
assert len(templates) == 1
assert templates[0].existing_test_count == 2
def test_existing_test_count_zero_when_no_tests(db):
tech = Technique(mitre_id="T1056", name="Input Capture", tactic="collection", platforms=["windows"])
db.add(tech)
db.flush()
db.add(TestTemplate(mitre_technique_id="T1056", name="Capture template", source="custom"))
db.commit()
templates = list_templates(db, mitre_technique_id="T1056")
assert len(templates) == 1
assert templates[0].existing_test_count == 0