From 388eb8cc7e87c187915a8baa9eb30d81a88bf1ee Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Tue, 29 Sep 2026 12:06:12 +0800 Subject: [PATCH] test: add failing cases for vehicle recharge apply withdraw Co-authored-by: Cursor --- .../test_pl_vehicle_recharge_workflow.py | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/backend/tests/test_pl_vehicle_recharge_workflow.py b/backend/tests/test_pl_vehicle_recharge_workflow.py index 69fae306f..dda525f62 100644 --- a/backend/tests/test_pl_vehicle_recharge_workflow.py +++ b/backend/tests/test_pl_vehicle_recharge_workflow.py @@ -353,3 +353,112 @@ def test_approve_forbidden_on_disburse_node(monkeypatch): db, "t1", _user("u-fin", "财务"), "apply-1", opinion="ok" ) assert exc.value.status_code == 400 + + +def test_withdraw_in_approval_to_draft_keeps_round_and_approvals(monkeypatch): + from app.services import pl_vehicle_recharge_service as svc + + db = _make_session() + _seed_vehicle(db) + wf_id, node_gm, _node_fin = _seed_workflow(db) + db.add( + PlVehicleRechargeApply( + id="a-wd", + apply_no="SXSQWD001", + license_plate="鄂A00001", + recharge_type="etc", + apply_date=date.today(), + applicant_id="u-applicant", + status="in_approval", + wf_id=wf_id, + current_node=node_gm, + approval_round=1, + tenant_no="t1", + create_dept_id="d1", + ) + ) + db.add( + PlVehicleRechargeApproval( + id="ap1", + apply_id="a-wd", + node_id=node_gm, + node_name="总经理审批", + approval_round=1, + approval_status="approved", + approver_id="u-gm", + approver_name="总经理", + approval_time=datetime.now(), + tenant_no="t1", + create_dept_id="d1", + ) + ) + db.commit() + _patch_scope(monkeypatch, svc) + + out = svc.withdraw_apply(db, "t1", _user("u-applicant"), "a-wd") + assert out.status == "draft" + assert out.currentNode in (None, "") + row = db.query(PlVehicleRechargeApply).filter_by(id="a-wd").one() + assert row.status == "draft" + assert row.current_node is None + assert row.approval_round == 1 + assert ( + db.query(PlVehicleRechargeApproval) + .filter_by(apply_id="a-wd", del_flag=0) + .count() + == 1 + ) + + +def test_withdraw_rejects_non_applicant(monkeypatch): + from fastapi import HTTPException + from app.services import pl_vehicle_recharge_service as svc + + db = _make_session() + _seed_vehicle(db) + db.add( + PlVehicleRechargeApply( + id="a-wd2", + apply_no="SXSQWD002", + license_plate="鄂A00001", + recharge_type="etc", + apply_date=date.today(), + applicant_id="u-applicant", + status="in_approval", + tenant_no="t1", + create_dept_id="d1", + ) + ) + db.commit() + _patch_scope(monkeypatch, svc) + + with pytest.raises(HTTPException) as ei: + svc.withdraw_apply(db, "t1", _user("u-other"), "a-wd2") + assert ei.value.status_code == 403 + + +def test_withdraw_rejects_non_in_approval(monkeypatch): + from fastapi import HTTPException + from app.services import pl_vehicle_recharge_service as svc + + db = _make_session() + _seed_vehicle(db) + db.add( + PlVehicleRechargeApply( + id="a-wd3", + apply_no="SXSQWD003", + license_plate="鄂A00001", + recharge_type="etc", + apply_date=date.today(), + applicant_id="u-applicant", + status="draft", + tenant_no="t1", + create_dept_id="d1", + ) + ) + db.commit() + _patch_scope(monkeypatch, svc) + + with pytest.raises(HTTPException) as ei: + svc.withdraw_apply(db, "t1", _user("u-applicant"), "a-wd3") + assert ei.value.status_code == 400