优化sync_system代码质量
This commit is contained in:
@@ -1,14 +1,21 @@
|
||||
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
|
||||
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.skip_sync is False
|
||||
assert runtime_config.skip_post_check is False
|
||||
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:
|
||||
@@ -24,8 +31,34 @@ def test_apply_strategy_overrides_allows_skip_sync_override() -> None:
|
||||
|
||||
assert len(resolved) == 1
|
||||
assert resolved[0].node_type == "project"
|
||||
assert resolved[0].skip_sync is True
|
||||
assert resolved[0].skip_post_check is True
|
||||
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:
|
||||
@@ -39,4 +72,20 @@ def test_strategy_config_supports_both_post_check_ignore_fields() -> None:
|
||||
|
||||
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
|
||||
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",
|
||||
}
|
||||
Reference in New Issue
Block a user