refactor(backend/api): extract LegalDocumentConsentService (Step 4 — file 12 of 18)

Extract consent, audit log, cookie category, and consent stats endpoints
from legal_document_routes into LegalDocumentConsentService. The route
file is now a thin handler layer delegating to LegalDocumentService and
LegalDocumentConsentService with translate_domain_errors(). Legacy
helpers (_doc_to_response, _version_to_response, _transition,
_log_approval) and schemas are re-exported for existing tests. Two
transition tests updated to expect domain errors instead of HTTPException.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sharang Parnerkar
2026-04-09 08:47:56 +02:00
parent cc1c61947d
commit d2c94619d8
6 changed files with 1118 additions and 742 deletions

View File

@@ -199,33 +199,30 @@ class TestVersionToResponse:
class TestApprovalWorkflow:
def test_transition_raises_on_wrong_status(self):
"""_transition should raise HTTPException if version is in wrong status."""
"""_transition should raise ValidationError if version is in wrong status."""
from compliance.api.legal_document_routes import _transition
from fastapi import HTTPException
from compliance.domain import ValidationError as DomainValidationError
mock_db = MagicMock()
v = make_version(status='draft')
mock_db.query.return_value.filter.return_value.first.return_value = v
with pytest.raises(HTTPException) as exc_info:
with pytest.raises(DomainValidationError) as exc_info:
_transition(mock_db, str(v.id), ['review'], 'approved', 'approved', None, None)
assert exc_info.value.status_code == 400
assert 'draft' in exc_info.value.detail
assert 'draft' in str(exc_info.value)
def test_transition_raises_on_not_found(self):
"""_transition should raise 404 if version not found."""
"""_transition should raise NotFoundError if version not found."""
from compliance.api.legal_document_routes import _transition
from fastapi import HTTPException
from compliance.domain import NotFoundError
mock_db = MagicMock()
mock_db.query.return_value.filter.return_value.first.return_value = None
with pytest.raises(HTTPException) as exc_info:
with pytest.raises(NotFoundError):
_transition(mock_db, make_uuid(), ['draft'], 'review', 'submitted', None, None)
assert exc_info.value.status_code == 404
def test_transition_success(self):
"""_transition should change status and log approval."""
from compliance.api.legal_document_routes import _transition