PayrollManagementSystem/backend/tests/unit/test_receipt_confirmation_migration.py
liuwenxin 1e53792ad6 feat(T+): 完成数据贯通与自动接入闭环
打通 T+ 快照、业务、发货、回款和核算准备链路,保留来源差异并提供待补状态。
新增业务自动接入任务、跨平台读取服务托管、权限复核、来源关联和前端核对页面。
补充迁移、隔离集成测试、浏览器模拟验收及角色授权边界修复。
2026-11-05 18:47:13 +08:00

45 lines
1.8 KiB
Python

"""V29 能识别先于迁移版本登记的兼容字段。"""
import importlib.util
from pathlib import Path
from types import SimpleNamespace
import pytest
from sqlalchemy.dialects.mysql import DATETIME, TINYINT, VARCHAR
def migration(monkeypatch, columns):
path = Path(__file__).resolve().parents[2] / "alembic/versions/29b0c1d2e3f4_receipt_manual_confirmation.py"
spec = importlib.util.spec_from_file_location("receipt_confirmation_migration", path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
statements = []
bind = SimpleNamespace(execute=lambda sql: statements.append(str(sql)))
monkeypatch.setattr(module, "op", SimpleNamespace(get_bind=lambda: bind))
monkeypatch.setattr(module, "inspect", lambda _: SimpleNamespace(get_columns=lambda table: columns))
return module, statements
def existing_columns():
return [
{"name": "confirmation_status", "type": TINYINT(), "nullable": False, "default": "'0'"},
{"name": "confirmed_by", "type": VARCHAR(64, collation="utf8mb4_general_ci"), "nullable": True},
{"name": "confirmed_at", "type": DATETIME(), "nullable": True},
{"name": "confirmed_revision", "type": VARCHAR(64), "nullable": True},
]
def test_兼容已有字段且仍执行权限和参数初始化(monkeypatch):
module, statements = migration(monkeypatch, existing_columns())
module.upgrade()
assert len(statements) == 4
assert all(not statement.startswith("ALTER TABLE") for statement in statements)
assert any("receipt.confirmation.enabled" in statement for statement in statements)
def test_已有字段不完整时拒绝迁移(monkeypatch):
module, statements = migration(monkeypatch, existing_columns()[:1])
with pytest.raises(RuntimeError, match="字段不完整"):
module.upgrade()
assert not statements