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