{ "verdict": "APPROVED", "rejection_reason": "NONE", "audit_details": { "target_invoked": true, "pre_conditions_tested": true, "post_conditions_tested": true, "test_data_used": true }, "feedback": "The test suite robustly verifies the
MigrationEngine contracts. It avoids Tautologies by cleanly substituting IdMappingService without mocking the engine itself. Cross-filter parsing asserts against hard-coded, predefined validation dictionaries (no Logic Mirroring). It successfully addresses @PRE negative cases (e.g. invalid zip paths, missing YAMLs) and rigorously validates @POST file transformations (e.g. in-place UUID substitutions and archive reconstruction)." }
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
import pytest
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
|
||||
|
||||
from src.services.git_service import GitService
|
||||
from src.core.superset_client import SupersetClient
|
||||
from src.core.config_models import Environment
|
||||
|
||||
@@ -35,7 +35,7 @@ class MockSupersetClient:
|
||||
def __init__(self, resources):
|
||||
self.resources = resources
|
||||
|
||||
def get_all_resources(self, endpoint):
|
||||
def get_all_resources(self, endpoint, since_dttm=None):
|
||||
return self.resources.get(endpoint, [])
|
||||
|
||||
def test_sync_environment_upserts_correctly(db_session):
|
||||
@@ -147,7 +147,7 @@ def test_sync_environment_skips_resources_without_uuid(db_session):
|
||||
def test_sync_environment_handles_api_error_gracefully(db_session):
|
||||
"""If one resource type fails, others should still sync."""
|
||||
class FailingClient:
|
||||
def get_all_resources(self, endpoint):
|
||||
def get_all_resources(self, endpoint, since_dttm=None):
|
||||
if endpoint == "chart":
|
||||
raise ConnectionError("API timeout")
|
||||
if endpoint == "dataset":
|
||||
@@ -217,4 +217,33 @@ def test_sync_environment_requires_existing_env(db_session):
|
||||
assert db_session.query(ResourceMapping).count() == 0
|
||||
|
||||
|
||||
|
||||
def test_sync_environment_deletes_stale_mappings(db_session):
|
||||
"""Verify that mappings for resources deleted from the remote environment
|
||||
are removed from the local DB on the next sync cycle."""
|
||||
service = IdMappingService(db_session)
|
||||
|
||||
# First sync: 2 charts exist
|
||||
client_v1 = MockSupersetClient({
|
||||
"chart": [
|
||||
{"id": 1, "uuid": "aaa", "slice_name": "Chart A"},
|
||||
{"id": 2, "uuid": "bbb", "slice_name": "Chart B"},
|
||||
]
|
||||
})
|
||||
service.sync_environment("env1", client_v1)
|
||||
assert db_session.query(ResourceMapping).filter_by(environment_id="env1").count() == 2
|
||||
|
||||
# Second sync: user deleted Chart B from superset
|
||||
client_v2 = MockSupersetClient({
|
||||
"chart": [
|
||||
{"id": 1, "uuid": "aaa", "slice_name": "Chart A"},
|
||||
]
|
||||
})
|
||||
service.sync_environment("env1", client_v2)
|
||||
|
||||
remaining = db_session.query(ResourceMapping).filter_by(environment_id="env1").all()
|
||||
assert len(remaining) == 1
|
||||
assert remaining[0].uuid == "aaa"
|
||||
|
||||
|
||||
# [/DEF:backend.tests.core.test_mapping_service:Module]
|
||||
|
||||
Reference in New Issue
Block a user