91 lines
2.6 KiB
Python
91 lines
2.6 KiB
Python
from __future__ import annotations
|
|
|
|
from pydantic import BaseModel
|
|
|
|
from sync_state_machine.config.builder import _apply_strategy_overrides
|
|
from sync_state_machine.config.strategy_config import (
|
|
StrategyConfig,
|
|
StrategyRuntimeConfig,
|
|
resolve_domain_option_config,
|
|
)
|
|
|
|
|
|
def test_strategy_runtime_config_skip_sync_defaults_false() -> None:
|
|
runtime_config = StrategyRuntimeConfig(node_type="project")
|
|
|
|
assert runtime_config.config.skip_sync is False
|
|
assert runtime_config.config.skip_post_check is False
|
|
assert runtime_config.config.domain_option == {}
|
|
|
|
|
|
def test_apply_strategy_overrides_allows_skip_sync_override() -> None:
|
|
resolved = _apply_strategy_overrides(
|
|
node_types=["project"],
|
|
strategy_overrides={
|
|
"project": {
|
|
"skip_sync": True,
|
|
"skip_post_check": True,
|
|
}
|
|
},
|
|
)
|
|
|
|
assert len(resolved) == 1
|
|
assert resolved[0].node_type == "project"
|
|
assert resolved[0].config.skip_sync is True
|
|
assert resolved[0].config.skip_post_check is True
|
|
|
|
|
|
def test_apply_strategy_overrides_allows_domain_option_override() -> None:
|
|
resolved = _apply_strategy_overrides(
|
|
node_types=["project"],
|
|
strategy_overrides={
|
|
"project": {
|
|
"domain_option": {
|
|
"pull_group_plan_production_date": True,
|
|
}
|
|
}
|
|
},
|
|
)
|
|
|
|
assert resolved[0].config.domain_option == {"pull_group_plan_production_date": True}
|
|
|
|
|
|
def test_apply_strategy_overrides_preserves_project_detail_default_domain_option() -> None:
|
|
resolved = _apply_strategy_overrides(
|
|
node_types=["project_detail_data"],
|
|
strategy_overrides={},
|
|
)
|
|
|
|
assert resolved[0].config.domain_option == {
|
|
"pull_group_production_plans": True,
|
|
}
|
|
|
|
|
|
def test_strategy_config_supports_both_post_check_ignore_fields() -> None:
|
|
config = StrategyConfig.model_validate(
|
|
{
|
|
"post_check_ignore_fields": ["code"],
|
|
"post_check_ignore_list_item_fields": {"plan_node": ["is_audit"]},
|
|
"allow_many_to_one_auto_bind": True,
|
|
}
|
|
)
|
|
|
|
assert config.post_check_ignore_fields == ["code"]
|
|
assert config.post_check_ignore_list_item_fields == {"plan_node": ["is_audit"]}
|
|
assert config.allow_many_to_one_auto_bind is True
|
|
|
|
|
|
def test_resolve_domain_option_config_fills_schema_defaults() -> None:
|
|
class ExampleDomainOption(BaseModel):
|
|
enabled: bool = True
|
|
mode: str = "strict"
|
|
|
|
resolved = resolve_domain_option_config(
|
|
ExampleDomainOption,
|
|
{"enabled": False},
|
|
)
|
|
|
|
assert resolved == {
|
|
"enabled": False,
|
|
"mode": "strict",
|
|
} |