From 28b5f965a1b68bd1fc72b368dde0354b96e1d61f Mon Sep 17 00:00:00 2001 From: emreumar Date: Sat, 18 Jul 2026 20:21:58 +0300 Subject: [PATCH] feat(profile): add max_length validation constraint on bio field Signed-off-by: emreumar --- app/models.py | 4 ++-- tests/test_profile.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models.py b/app/models.py index 9043fb4..79473c4 100644 --- a/app/models.py +++ b/app/models.py @@ -1,6 +1,6 @@ """Data models for the Workshop API.""" -from pydantic import BaseModel +from pydantic import BaseModel, Field from typing import Optional @@ -8,7 +8,7 @@ class ProfileCreate(BaseModel): """Schema for creating a new profile.""" username: str - bio: str + bio: str = Field(..., max_length=500) age: Optional[int] = None diff --git a/tests/test_profile.py b/tests/test_profile.py index 6bf5e9f..7d0099d 100644 --- a/tests/test_profile.py +++ b/tests/test_profile.py @@ -29,3 +29,11 @@ def test_get_profile(clean_store): def test_get_nonexistent_profile(clean_store): response = client.get("/profile/nobody") assert response.status_code == 404 + + +def test_create_profile_with_too_long_bio(clean_store): + response = client.post( + "/profile", + json={"username": "alice", "bio": "x" * 501, "age": 22}, + ) + assert response.status_code == 422