Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions models/player_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- `PlayerRequestModel`: Represents player data for Create and Update operations.
- `PlayerResponseModel`: Represents player data including UUID for Retrieve operations.

Design decision single request model vs split models:
Design decision - single request model vs split models:
A single `PlayerRequestModel` is intentionally shared by both POST (Create)
and PUT (Update). Per-operation differences are handled at the route layer
rather than by duplicating the model:
Expand All @@ -19,7 +19,7 @@

from typing import Optional
from uuid import UUID
from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel, ConfigDict, Field
from pydantic.alias_generators import to_camel


Expand Down Expand Up @@ -67,7 +67,7 @@ class PlayerRequestModel(MainModel):
middle_name: Optional[str] = None
last_name: str
date_of_birth: Optional[str] = None
squad_number: int
squad_number: int = Field(gt=0)
position: str
abbr_position: Optional[str] = None
team: Optional[str] = None
Expand Down
17 changes: 15 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,19 @@ def test_request_post_player_body_existing_response_body_detail(client):
)


def test_request_post_player_body_zero_squad_number_response_status_unprocessable(
client,
):
"""POST /players/ with squad number zero returns 422 Unprocessable Entity"""
# Arrange
player = nonexistent_player()
payload = player.__dict__ | {"squad_number": 0}
# Act
response = client.post(PATH, json=payload)
# Assert
assert response.status_code == 422


def test_request_post_player_body_nonexistent_response_status_created(client):
"""POST /players/ with nonexistent player returns 201 Created with a valid UUID"""
# Arrange
Expand All @@ -203,7 +216,7 @@ def test_request_post_player_body_nonexistent_response_status_created(client):
assert "id" in body
assert UUID(body["id"]).version == 4 # UUID v4 (API-created)
finally:
# Teardown remove the created player
# Teardown - remove the created player
client.delete(PATH + "squadnumber/" + str(player.squad_number))


Expand Down Expand Up @@ -250,7 +263,7 @@ def test_request_put_player_squadnumber_existing_response_status_no_content(clie
# Assert
assert response.status_code == 204
finally:
# Teardown restore Damián Martínez to its seeded state
# Teardown - restore Damián Martínez to its seeded state
seed = existing_player()
client.put(PATH + "squadnumber/" + str(seed.squad_number), json=seed.__dict__)

Expand Down