68 lines
2.4 KiB
Python
68 lines
2.4 KiB
Python
from types import SimpleNamespace
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from sync_state_machine.domain.project_detail.sync_strategy import ProjectDetailSyncStrategy
|
|
from sync_state_machine.sync_system.config import UpdateDirection
|
|
from sync_state_machine.sync_system.strategy_ops import BoundNodePair
|
|
|
|
|
|
def _fake_node(*, node_id: str, key: str):
|
|
data = {"id": node_id, "key": key}
|
|
return SimpleNamespace(
|
|
node_id=node_id,
|
|
data_id=node_id,
|
|
action=None,
|
|
context={},
|
|
get_data=lambda: data,
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_project_detail_update_partitions_group_production_plans_before_generic_logic():
|
|
strategy = ProjectDetailSyncStrategy("project_detail_data", MagicMock(), MagicMock(), MagicMock())
|
|
|
|
pull_pair = BoundNodePair(
|
|
local_node=_fake_node(node_id="local-pull", key="ensure_production"),
|
|
remote_node=_fake_node(node_id="remote-pull", key="ensure_production"),
|
|
)
|
|
generic_pair = BoundNodePair(
|
|
local_node=_fake_node(node_id="local-generic", key="production"),
|
|
remote_node=_fake_node(node_id="remote-generic", key="production"),
|
|
)
|
|
pull_node = SimpleNamespace(node_id="pull-update")
|
|
generic_node = SimpleNamespace(node_id="generic-update")
|
|
|
|
with patch.object(
|
|
strategy,
|
|
"collect_update_pairs",
|
|
new=AsyncMock(return_value=[pull_pair, generic_pair]),
|
|
), patch(
|
|
"sync_state_machine.domain.project_detail.sync_strategy.build_data_id_normalization_map",
|
|
new=AsyncMock(return_value={}),
|
|
), patch.object(
|
|
strategy,
|
|
"prepare_update_for_direction",
|
|
new=AsyncMock(return_value=pull_node),
|
|
) as mock_prepare, patch.object(
|
|
strategy,
|
|
"update_pair",
|
|
new=AsyncMock(return_value=[generic_node]),
|
|
) as mock_update_pair:
|
|
updated_nodes = await strategy.update()
|
|
|
|
assert updated_nodes == [pull_node, generic_node]
|
|
mock_prepare.assert_awaited_once_with(
|
|
pull_pair.local_node,
|
|
pull_pair.remote_node,
|
|
UpdateDirection.PULL,
|
|
{},
|
|
)
|
|
mock_update_pair.assert_awaited_once_with(generic_pair.local_node, generic_pair.remote_node, {})
|
|
|
|
|
|
def test_project_detail_domain_option_is_typed_schema() -> None:
|
|
strategy = ProjectDetailSyncStrategy("project_detail_data", MagicMock(), MagicMock(), MagicMock())
|
|
|
|
assert strategy.domain_option.pull_group_production_plans is True |