|
|
@@ -0,0 +1,56 @@
|
|
|
+"""备用金撤回:仅申请人且审批中可回草稿。"""
|
|
|
+from types import SimpleNamespace
|
|
|
+from unittest.mock import MagicMock, patch
|
|
|
+
|
|
|
+from app.services.bx.advance import AdvanceService
|
|
|
+
|
|
|
+
|
|
|
+def _user(uid="u1"):
|
|
|
+ return SimpleNamespace(id=uid, name="张三", dept_id="d1")
|
|
|
+
|
|
|
+
|
|
|
+def _apply(**kwargs):
|
|
|
+ base = {
|
|
|
+ "id": "a1",
|
|
|
+ "applicant_id": "u1",
|
|
|
+ "status": "pending",
|
|
|
+ "current_node": "一级审批",
|
|
|
+ "update_by": None,
|
|
|
+ }
|
|
|
+ base.update(kwargs)
|
|
|
+ return SimpleNamespace(**base)
|
|
|
+
|
|
|
+
|
|
|
+@patch.object(AdvanceService, "_tenant_no", return_value="T1")
|
|
|
+@patch.object(AdvanceService, "get_by_id")
|
|
|
+def test_withdraw_pending_by_applicant(mock_get, _tenant):
|
|
|
+ apply_obj = _apply()
|
|
|
+ mock_get.return_value = apply_obj
|
|
|
+ db = MagicMock()
|
|
|
+ out = AdvanceService.withdraw(db, "a1", _user("u1"))
|
|
|
+ assert out is apply_obj
|
|
|
+ assert apply_obj.status == "draft"
|
|
|
+ assert apply_obj.current_node is None
|
|
|
+ assert apply_obj.update_by == "u1"
|
|
|
+ db.flush.assert_called_once()
|
|
|
+
|
|
|
+
|
|
|
+@patch.object(AdvanceService, "_tenant_no", return_value="T1")
|
|
|
+@patch.object(AdvanceService, "get_by_id")
|
|
|
+def test_withdraw_rejects_non_applicant(mock_get, _tenant):
|
|
|
+ mock_get.return_value = _apply(applicant_id="u1")
|
|
|
+ assert AdvanceService.withdraw(MagicMock(), "a1", _user("u2")) is None
|
|
|
+
|
|
|
+
|
|
|
+@patch.object(AdvanceService, "_tenant_no", return_value="T1")
|
|
|
+@patch.object(AdvanceService, "get_by_id")
|
|
|
+def test_withdraw_rejects_non_pending(mock_get, _tenant):
|
|
|
+ mock_get.return_value = _apply(status="draft")
|
|
|
+ assert AdvanceService.withdraw(MagicMock(), "a1", _user("u1")) is None
|
|
|
+
|
|
|
+
|
|
|
+@patch.object(AdvanceService, "_tenant_no", return_value="T1")
|
|
|
+@patch.object(AdvanceService, "get_by_id")
|
|
|
+def test_withdraw_missing_returns_none(mock_get, _tenant):
|
|
|
+ mock_get.return_value = None
|
|
|
+ assert AdvanceService.withdraw(MagicMock(), "a1", _user("u1")) is None
|