fix(pl): allow only etc recharge type in vehicle recharge schemas
Reject fuel writes so the shared module can be narrowed to ETC-only. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
00849bd998
commit
542ecc63e7
2 files changed
+52
-3
No files matched your search
@@ -5,7 +5,7 @@ from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
|
||||
RECHARGE_TYPES = {"etc", "fuel"}
|
||||
RECHARGE_TYPES = {"etc"}
|
||||
|
||||
|
||||
class VehicleRechargeApplyCreate(BaseModel):
|
||||
@@ -23,7 +23,7 @@ class VehicleRechargeApplyCreate(BaseModel):
|
||||
@classmethod
|
||||
def validate_recharge_type(cls, v: str) -> str:
|
||||
if v not in RECHARGE_TYPES:
|
||||
raise ValueError("充值类型无效")
|
||||
raise ValueError("本期仅支持 ETC")
|
||||
return v
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class VehicleRechargeRecordCreate(BaseModel):
|
||||
@classmethod
|
||||
def validate_recharge_type(cls, v: str) -> str:
|
||||
if v not in RECHARGE_TYPES:
|
||||
raise ValueError("充值类型无效")
|
||||
raise ValueError("本期仅支持 ETC")
|
||||
return v
|
||||
|
||||
@field_validator("amount")
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
"""车辆充值模块收窄为仅 ETC。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
from app.schemas.pl.vehicle_recharge import (
|
||||
RECHARGE_TYPES,
|
||||
VehicleRechargeApplyCreate,
|
||||
VehicleRechargeRecordCreate,
|
||||
)
|
||||
|
||||
|
||||
def test_recharge_types_only_etc():
|
||||
assert RECHARGE_TYPES == {"etc"}
|
||||
|
||||
|
||||
def test_apply_create_rejects_fuel():
|
||||
with pytest.raises(ValidationError):
|
||||
VehicleRechargeApplyCreate.model_validate(
|
||||
{
|
||||
"licensePlate": "鄂A12345",
|
||||
"rechargeType": "fuel",
|
||||
"applyDate": "2026-09-12",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def test_apply_create_accepts_etc():
|
||||
obj = VehicleRechargeApplyCreate.model_validate(
|
||||
{
|
||||
"licensePlate": "鄂A12345",
|
||||
"rechargeType": "etc",
|
||||
"applyDate": "2026-09-12",
|
||||
}
|
||||
)
|
||||
assert obj.recharge_type == "etc"
|
||||
|
||||
|
||||
def test_record_create_rejects_fuel():
|
||||
with pytest.raises(ValidationError):
|
||||
VehicleRechargeRecordCreate.model_validate(
|
||||
{
|
||||
"rechargeDate": "2026-09-12",
|
||||
"rechargeType": "fuel",
|
||||
"amount": "100.00",
|
||||
"licensePlate": "鄂A12345",
|
||||
}
|
||||
)
|
||||
Reference in new issue
Block a user