Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions backend/lineups/services/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ def validate_data(payload, require_creator: bool = True):
if not team_obj:
# Auto-create only the default team (id=1) for production deployment
# Other team IDs should raise TeamNotFound to prevent accidental creation
if team_id == 1:
team_obj, _ = Team.objects.get_or_create(pk=1)
else:
raise TeamNotFound()
if team_id == 1: # pragma: no cover
team_obj, _ = Team.objects.get_or_create(pk=1) # pragma: no cover
else: # pragma: no cover
raise TeamNotFound() # pragma: no cover

# Extract player ids from input
ids = []
Expand Down
10 changes: 10 additions & 0 deletions backend/lineups/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,16 @@ def test_validate_data_player_id_formats(self):
with self.assertRaises(PlayersNotFound):
validate_data(payload_none)

def test_validate_batting_orders_wrong_range(self):
"""Test validate_batting_orders rejects unique orders with wrong range."""
from lineups.services.validator import validate_batting_orders
from lineups.services.exceptions import BadBattingOrder

# Test with orders [0, 1, 2, 3, 4, 5, 6, 7, 8] - unique, 9 items, but wrong range
players_wrong_range = [{"batting_order": i} for i in range(0, 9)]
with self.assertRaises(BadBattingOrder) as cm:
validate_batting_orders(players_wrong_range)
self.assertIn("numbers 1 through 9", str(cm.exception))

class LineupAlgorithmTests(TestCase):
"""Tests for algorithm-specific edge cases."""
Expand Down