fix: CameraRecord — reject negative entries/exits via Pydantic Field(ge=0)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,14 +11,14 @@ import sqlite3
|
||||
from typing import List
|
||||
|
||||
from fastapi import Depends
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class CameraRecord(BaseModel):
|
||||
period_start: int
|
||||
period_end: int
|
||||
entries: int
|
||||
exits: int
|
||||
entries: int = Field(ge=0)
|
||||
exits: int = Field(ge=0)
|
||||
|
||||
|
||||
class CameraEventsRequest(BaseModel):
|
||||
|
||||
@@ -89,3 +89,12 @@ def test_entries_exits_stored_correctly():
|
||||
assert row[0] == 42
|
||||
assert row[1] == 39
|
||||
assert row[2] == "retailer-123"
|
||||
|
||||
|
||||
def test_negative_counts_rejected():
|
||||
"""Pydantic should reject negative entries/exits."""
|
||||
from pydantic import ValidationError
|
||||
from server.camera_endpoint import CameraRecord
|
||||
with pytest.raises(ValidationError):
|
||||
CameraRecord(period_start=1712000000, period_end=1712003600,
|
||||
entries=-1, exits=0)
|
||||
|
||||
Reference in New Issue
Block a user