PayrollManagementSystem/backend/tests/unit/test_tplus_worker_stop.py
liuwenxin 108bf87225 feat(核算)!: 添加 T+ 正式核算与采集托管
补齐源快照、资料预演、正式导入及工资核算的依赖链路。
新增版本化输入、逐段 FIFO、生成锁和结构化当月调整,
并提供默认关闭的周期采集、有限重试及 Windows 托管。

原始客户资料、私有配置及首页改动不纳入本次提交。

BREAKING CHANGE: 升级前需应用新增迁移,并通过
PAYROLL_MAKER_USER_ID 绑定实际工资制作人,否则业务只读。
旧单批次核算默认关闭;历史兼容需显式启用
PAYROLL_ALLOW_LEGACY_CALCULATION。生产启用和真实金额待验收。
2026-11-02 09:42:53 +08:00

36 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""停止标记控制真实CLI领取边界,不中断正在完成的单次处理。"""
from argparse import Namespace
from contextlib import nullcontext
from types import SimpleNamespace
from unittest.mock import Mock
import pytest
from app import cli
from app.core.config import Settings
@pytest.mark.parametrize("already_stopped", [False, True])
def test_停止后不再领取下一任务(monkeypatch, tmp_path, already_stopped):
marker = tmp_path / "stop.requested"
if already_stopped:
marker.touch()
settings = Settings(_env_file=None, app_secret_key="x" * 32)
monkeypatch.setattr(cli, "get_settings", lambda: settings)
monkeypatch.setattr(cli, "get_session_factory", lambda: lambda: nullcontext(object()))
def finish(_session, **_kwargs):
marker.touch()
return "completed"
consume = Mock(side_effect=finish)
pulse = Mock()
monkeypatch.setattr(cli, "run_once", consume)
monkeypatch.setattr(cli, "get_batch", lambda *_: SimpleNamespace(status="SUCCEEDED"))
monkeypatch.setattr("app.services.tplus.automation.heartbeat", pulse)
result = cli._tplus_worker(Namespace(connection_file=None, poll_seconds=2, watch=True, stop_file=str(marker)))
assert result == 0
assert consume.call_count == (0 if already_stopped else 1)
assert pulse.call_args.args[3] == "STOPPED"