基于 skill-template 脚手架开发,包含: - payroll_config(费率配置,可编辑)+ payslip_snapshots(解析历史,只读)2 张业务表 - 全国默认 + 北上广 4 套费率(社保/公积金/个税起征点/7 级税率表) - 5 个业务 Action:calculate-payslip-simple / calculate-payslip-full / explain-term / view-config / edit-config - 个税累计预扣法计算,支持多月历史累加 - 20 个薪资名词库(社保/公积金/个税/全勤/加班费等) - 完整市场文档(README/TUTORIAL/DEMO/CHANGELOG) - 296 测试全部通过
64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
import subprocess
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from service.account_client import AccountManagerError, pick_web_account
|
|
|
|
|
|
def _completed(payload: dict) -> subprocess.CompletedProcess[str]:
|
|
return subprocess.CompletedProcess(
|
|
args=["python", "account-manager"],
|
|
returncode=0,
|
|
stdout=json.dumps(payload, ensure_ascii=False),
|
|
stderr="",
|
|
)
|
|
|
|
|
|
class TestExplicitAccountLease(unittest.TestCase):
|
|
@patch("service.account_client._run_argv")
|
|
def test_explicit_account_id_is_reselected_with_lease(self, run_argv) -> None:
|
|
account = {
|
|
"id": 42,
|
|
"platform_key": "target-platform",
|
|
"account_label": "主账号",
|
|
"login_id": "user@example.com",
|
|
"profile_dir": "D:/data/profile-42",
|
|
"status": "active",
|
|
}
|
|
leased = {**account, "lease_token": "lease-42"}
|
|
run_argv.side_effect = [_completed(account), _completed(leased)]
|
|
|
|
result = pick_web_account("target-platform", account_id="42")
|
|
|
|
self.assertEqual(result["id"], 42)
|
|
self.assertEqual(result["lease_token"], "lease-42")
|
|
self.assertEqual(run_argv.call_args_list[0].args[0], ["account", "get", "42"])
|
|
pick_args = run_argv.call_args_list[1].args[0]
|
|
self.assertIn("pick-web", pick_args)
|
|
self.assertIn("--lease", pick_args)
|
|
self.assertIn("user@example.com", pick_args)
|
|
|
|
@patch("service.account_client._run_argv")
|
|
def test_missing_lease_token_is_rejected(self, run_argv) -> None:
|
|
account = {
|
|
"id": 42,
|
|
"platform_key": "target-platform",
|
|
"account_label": "主账号",
|
|
"login_id": "user@example.com",
|
|
"profile_dir": "D:/data/profile-42",
|
|
"status": "active",
|
|
}
|
|
run_argv.side_effect = [_completed(account), _completed(account)]
|
|
|
|
with self.assertRaises(AccountManagerError) as raised:
|
|
pick_web_account("target-platform", account_id="42")
|
|
|
|
self.assertEqual(raised.exception.code, "LEASE_REQUIRED")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|