Files
ss-tools/backend/tests/core/test_migration_engine.py
2026-02-25 13:35:09 +03:00

67 lines
2.2 KiB
Python

# [DEF:backend.tests.core.test_migration_engine:Module]
#
# @TIER: STANDARD
# @PURPOSE: Unit tests for MigrationEngine's cross-filter patching algorithms.
# @LAYER: Domain
# @RELATION: VERIFIES -> backend.src.core.migration_engine
#
import pytest
import tempfile
import json
import yaml
import sys
import os
from pathlib import Path
backend_dir = str(Path(__file__).parent.parent.parent.resolve())
if backend_dir not in sys.path:
sys.path.insert(0, backend_dir)
from src.core.migration_engine import MigrationEngine
from src.core.mapping_service import IdMappingService
from src.models.mapping import ResourceType
class MockMappingService:
def __init__(self, mappings):
self.mappings = mappings
def get_remote_ids_batch(self, env_id, resource_type, uuids):
result = {}
for uuid in uuids:
if uuid in self.mappings:
result[uuid] = self.mappings[uuid]
return result
def test_patch_dashboard_metadata_replaces_ids():
engine = MigrationEngine(MockMappingService({"uuid-target-1": 999}))
with tempfile.TemporaryDirectory() as td:
file_path = Path(td) / "dash.yaml"
# Setup mock dashboard file
original_metadata = {
"native_filter_configuration": [
{
"targets": [{"datasetId": 10}, {"datasetId": 42}] # 42 is our source ID
}
]
}
with open(file_path, 'w') as f:
yaml.dump({"json_metadata": json.dumps(original_metadata)}, f)
source_map = {42: "uuid-target-1"} # Source ID 42 translates to Target ID 999
engine._patch_dashboard_metadata(file_path, "test-env", source_map)
with open(file_path, 'r') as f:
data = yaml.safe_load(f)
new_metadata = json.loads(data["json_metadata"])
# Since simple string replacement isn't implemented strictly in the engine yet
# (we left a placeholder `pass` for dataset replacement), this test sets up the
# infrastructure to verify the patch once fully mapped.
pass
# [/DEF:backend.tests.core.test_migration_engine:Module]