48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
"""车辆加油登记 Schema 单测"""
|
|
from datetime import date
|
|
from decimal import Decimal
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from app.schemas.pl.vehicle_fuel import VehicleFuelRegisterCreate
|
|
|
|
|
|
def test_create_accepts_bailian():
|
|
body = VehicleFuelRegisterCreate.model_validate(
|
|
{
|
|
"fuelCategory": "bailian",
|
|
"registerDate": "2026-09-12",
|
|
"licensePlate": "皖A12345",
|
|
"fuelLiters": "50.5",
|
|
"odometerKm": "12000.0",
|
|
}
|
|
)
|
|
assert body.fuel_category == "bailian"
|
|
assert body.fuel_liters == Decimal("50.5")
|
|
assert body.register_date == date(2026, 9, 12)
|
|
|
|
|
|
def test_create_rejects_invalid_category():
|
|
with pytest.raises(ValidationError):
|
|
VehicleFuelRegisterCreate.model_validate(
|
|
{
|
|
"fuelCategory": "etc",
|
|
"registerDate": "2026-09-12",
|
|
"licensePlate": "皖A12345",
|
|
"fuelLiters": "10",
|
|
}
|
|
)
|
|
|
|
|
|
def test_create_rejects_non_positive_liters():
|
|
with pytest.raises(ValidationError):
|
|
VehicleFuelRegisterCreate.model_validate(
|
|
{
|
|
"fuelCategory": "gas_station",
|
|
"registerDate": "2026-09-12",
|
|
"licensePlate": "皖A12345",
|
|
"fuelLiters": "0",
|
|
}
|
|
)
|