Files
ss-tools/backend/tests/services/clean_release/test_mappers.py
busya f75c15dbc6 test: massive coverage expansion — 15 new test modules + assistant tool fixes + orthogonal testing
- 10 translate plugin test files (100% coverage on 12 modules)
- assistant/handler tools: 85+ tests covering dispatch, registry, resolvers, routes, llm_planner, 13 tool handlers
- clean release: artifact_catalog_loader, mappers, approval, publication tests
- API routes: translate_helpers, validation_service extensions, datasets to 100%
- notifications: providers/service tests
- services: profile_preference_service
- docs/orthogonal-test-report.md — full speckit.tests audit
- Fixes: 3 git_base async mock failures, 4 assistant handler permission-check patches
- .gitignore: coverage artifacts
2026-06-15 15:38:59 +03:00

158 lines
5.0 KiB
Python

# #region Test.CleanRelease.Mappers [C:2] [TYPE Module]
# @RELATION BINDS_TO -> [clean_release_mappers]
# @SEMANTICS: tests, clean-release, mapper, dto, transform
# @PURPOSE: Validate domain-to-DTO mapping functions for clean release entities.
from __future__ import annotations
from datetime import UTC, datetime
from unittest.mock import MagicMock
import pytest
from src.models.clean_release import ComplianceReport, ComplianceRun, DistributionManifest, ReleaseCandidate
from src.services.clean_release.enums import CandidateStatus, ComplianceDecision, RunStatus
# #region test_map_candidate_to_dto [C:2] [TYPE Function]
def test_map_candidate_to_dto():
from src.services.clean_release.mappers import map_candidate_to_dto
candidate = ReleaseCandidate(
id="cand-1",
version="1.0.0",
source_snapshot_ref="git:sha1",
created_by="operator",
created_at=datetime.now(UTC),
status=CandidateStatus.DRAFT.value,
build_id="build-123",
)
dto = map_candidate_to_dto(candidate)
assert dto.id == "cand-1"
assert dto.version == "1.0.0"
assert dto.source_snapshot_ref == "git:sha1"
assert dto.build_id == "build-123"
assert dto.status == CandidateStatus.DRAFT
# #endregion test_map_candidate_to_dto
# #region test_map_manifest_to_dto [C:2] [TYPE Function]
def test_map_manifest_to_dto():
from src.services.clean_release.mappers import map_manifest_to_dto
manifest = DistributionManifest(
id="manifest-1",
candidate_id="cand-1",
manifest_version=1,
manifest_digest="digest-1",
artifacts_digest="art-digest-1",
created_at=datetime.now(UTC),
created_by="operator",
source_snapshot_ref="git:sha1",
content_json={"summary": {"total": 10}},
)
dto = map_manifest_to_dto(manifest)
assert dto.id == "manifest-1"
assert dto.candidate_id == "cand-1"
assert dto.manifest_version == 1
assert dto.manifest_digest == "digest-1"
assert dto.content_json == {"summary": {"total": 10}}
# #endregion test_map_manifest_to_dto
# #region test_map_run_to_dto [C:2] [TYPE Function]
def test_map_run_to_dto():
from src.services.clean_release.mappers import map_run_to_dto
run = ComplianceRun(
id="run-1",
candidate_id="cand-1",
manifest_id="manifest-1",
manifest_digest="digest-1",
policy_snapshot_id="policy-1",
registry_snapshot_id="registry-1",
requested_by="operator",
requested_at=datetime.now(UTC),
started_at=datetime.now(UTC),
status=RunStatus.SUCCEEDED.value,
final_status=ComplianceDecision.PASSED.value,
task_id="task-42",
)
dto = map_run_to_dto(run)
assert dto.run_id == "run-1"
assert dto.candidate_id == "cand-1"
assert dto.status == RunStatus.SUCCEEDED
assert dto.final_status == ComplianceDecision.PASSED
assert dto.task_id == "task-42"
# #endregion test_map_run_to_dto
# #region test_map_run_to_dto_no_final_status [C:2] [TYPE Function]
def test_map_run_to_dto_no_final_status():
from src.services.clean_release.mappers import map_run_to_dto
run = ComplianceRun(
id="run-2",
candidate_id="cand-1",
manifest_id="manifest-1",
manifest_digest="digest-1",
policy_snapshot_id="policy-1",
registry_snapshot_id="registry-1",
requested_by="operator",
requested_at=datetime.now(UTC),
started_at=datetime.now(UTC),
status=RunStatus.RUNNING.value,
)
dto = map_run_to_dto(run)
assert dto.run_id == "run-2"
assert dto.final_status is None
# #endregion test_map_run_to_dto_no_final_status
# #region test_map_report_to_dto [C:2] [TYPE Function]
def test_map_report_to_dto():
from src.services.clean_release.mappers import map_report_to_dto
report = ComplianceReport(
id="CCR-1",
run_id="run-1",
candidate_id="cand-1",
final_status=ComplianceDecision.PASSED.value,
summary_json={"operator_summary": "OK", "violations_count": 0, "blocking_violations_count": 0},
generated_at=datetime.now(UTC),
immutable=True,
)
dto = map_report_to_dto(report)
assert dto.report_id == "CCR-1"
assert dto.candidate_id == "cand-1"
assert dto.final_status == ComplianceDecision.PASSED
assert dto.generated_at is not None
# #endregion test_map_report_to_dto
# #region test_map_report_to_dto_blocked [C:2] [TYPE Function]
def test_map_report_to_dto_blocked():
from src.services.clean_release.mappers import map_report_to_dto
report = ComplianceReport(
id="CCR-2",
run_id="run-2",
candidate_id="cand-2",
final_status=ComplianceDecision.BLOCKED.value,
summary_json={"operator_summary": "BLOCKED", "violations_count": 3, "blocking_violations_count": 2},
generated_at=datetime.now(UTC),
immutable=True,
)
dto = map_report_to_dto(report)
assert dto.final_status == ComplianceDecision.BLOCKED
# #endregion test_map_report_to_dto_blocked
# #endregion Test.CleanRelease.Mappers