feat(I): I-DSGVO/I-DSAR/I-COMP-EXPORT — DSGVO data subject access export, DSAR workflow, compliance evidence export (audit, oversight, approval records, technical policies), 43 tests passing
This commit is contained in:
@@ -442,3 +442,75 @@ class TestDashboardAnalytics:
|
||||
assert "agent_runs" in result
|
||||
assert "workflow_executions" in result
|
||||
assert result["period_days"] == 7
|
||||
|
||||
|
||||
# ─── I-DSGVO/I-DSAR/I-COMP-EXPORT: DSGVO & Compliance ────────────────────────
|
||||
|
||||
|
||||
class TestDSGVOExport:
|
||||
"""Test the DSGVO export module (I-DSGVO, I-DSAR, I-COMP-EXPORT)."""
|
||||
|
||||
def test_dsgvo_functions_importable(self):
|
||||
"""All DSGVO functions are importable."""
|
||||
from app.ai.dsgvo_export import export_user_data, create_dsar_request, export_compliance_evidence
|
||||
assert callable(export_user_data)
|
||||
assert callable(create_dsar_request)
|
||||
assert callable(export_compliance_evidence)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_export_user_data_returns_dict(self):
|
||||
"""export_user_data returns structured dict with expected sections."""
|
||||
from app.ai.dsgvo_export import export_user_data
|
||||
|
||||
mock_db = AsyncMock()
|
||||
mock_db.get = AsyncMock(return_value=None)
|
||||
mock_db.execute = AsyncMock(return_value=MagicMock(scalars=MagicMock(return_value=[])))
|
||||
|
||||
result = await export_user_data(mock_db, uuid.uuid4(), uuid.uuid4())
|
||||
assert isinstance(result, dict)
|
||||
assert "export_metadata" in result
|
||||
assert "core" in result
|
||||
assert "agents" in result
|
||||
assert "audit" in result
|
||||
assert result["export_metadata"]["export_type"] == "dsgvo_data_subject_access"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_dsar_request_creates_task(self):
|
||||
"""create_dsar_request creates a Task with task_type='dsar'."""
|
||||
from app.ai.dsgvo_export import create_dsar_request
|
||||
|
||||
with patch("app.plugins.builtins.tasks.services.create_task", new_callable=AsyncMock) as mock_create:
|
||||
mock_create.return_value = {"id": "task-dsar-123", "title": "DSAR: access"}
|
||||
result = await create_dsar_request(
|
||||
db=MagicMock(), tenant_id=uuid.uuid4(), user_id=uuid.uuid4(),
|
||||
subject_user_id=uuid.uuid4(), request_type="access",
|
||||
)
|
||||
assert result["task"]["id"] == "task-dsar-123"
|
||||
assert result["request_type"] == "access"
|
||||
call_args = mock_create.call_args
|
||||
assert call_args[0][3]["task_type"] == "dsar"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_export_compliance_evidence_returns_dict(self):
|
||||
"""export_compliance_evidence returns structured evidence package."""
|
||||
from app.ai.dsgvo_export import export_compliance_evidence
|
||||
|
||||
mock_db = AsyncMock()
|
||||
mock_db.execute = AsyncMock(return_value=MagicMock(scalars=MagicMock(return_value=[])))
|
||||
|
||||
result = await export_compliance_evidence(mock_db, uuid.uuid4(), days=90)
|
||||
assert isinstance(result, dict)
|
||||
assert "export_metadata" in result
|
||||
assert "agent_definitions" in result
|
||||
assert "approval_records" in result
|
||||
assert "technical_policies" in result
|
||||
assert result["export_metadata"]["export_type"] == "compliance_evidence"
|
||||
assert result["export_metadata"]["period_days"] == 90
|
||||
|
||||
def test_technical_policies_structure(self):
|
||||
"""Technical policies have expected structure."""
|
||||
# This is tested via export_compliance_evidence but we can check the helper
|
||||
from app.ai.dsgvo_export import _get_sensitive_fields
|
||||
fields = _get_sensitive_fields()
|
||||
assert isinstance(fields, dict)
|
||||
assert len(fields) > 0
|
||||
|
||||
Reference in New Issue
Block a user