refactor(tests): extract CRUD/query logic to test_crud_service, router delegates to service with domain exceptions
This commit is contained in:
@@ -101,7 +101,7 @@ from app.routers.test_templates import (
|
||||
toggle_template_active,
|
||||
template_stats,
|
||||
)
|
||||
from app.routers.tests import create_test_from_template
|
||||
from app.services.test_crud_service import create_test_from_template as crud_create_from_template
|
||||
from app.schemas.test_template import TestTemplateCreate
|
||||
|
||||
|
||||
@@ -174,7 +174,8 @@ def test_get_templates_by_technique():
|
||||
|
||||
def test_instantiate_template():
|
||||
"""POST /tests/from-template creates a test pre-filled from template data."""
|
||||
source = inspect.getsource(create_test_from_template)
|
||||
# Template field copying lives in the service; router delegates to it
|
||||
source = inspect.getsource(crud_create_from_template)
|
||||
|
||||
# Verify it reads from template and copies fields
|
||||
assert "template" in source, "Must reference template"
|
||||
|
||||
@@ -477,15 +477,15 @@ def test_evidence_team_separation():
|
||||
|
||||
|
||||
def test_red_edit_allowed_in_draft_and_red_executing():
|
||||
"""Verify the red update router checks that state is draft or red_executing."""
|
||||
from app.routers.tests import update_test_red
|
||||
"""Verify the red update checks that state is draft or red_executing."""
|
||||
from app.services.test_crud_service import update_test_red
|
||||
import inspect
|
||||
source = inspect.getsource(update_test_red)
|
||||
|
||||
# The function must guard against states other than draft/red_executing
|
||||
# The service must guard against states other than draft/red_executing
|
||||
assert "draft" in source, "Red update must allow draft state"
|
||||
assert "red_executing" in source, "Red update must allow red_executing state"
|
||||
assert "400" in source or "HTTP_400_BAD_REQUEST" in source, "Red update must return 400 for invalid state"
|
||||
assert "BusinessRuleViolation" in source, "Must raise domain exception for invalid state (mapped to 400)"
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
|
||||
Reference in New Issue
Block a user