test: add failing cases for vehicle recharge apply withdraw
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
c3e1de2793
commit
388eb8cc7e
1 file changed
+109
@@ -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
|
||||
Reference in new issue
Block a user