diff --git a/backend/lineups/services/validator.py b/backend/lineups/services/validator.py index d6b15d4..7b77bd9 100644 --- a/backend/lineups/services/validator.py +++ b/backend/lineups/services/validator.py @@ -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 = [] diff --git a/backend/lineups/tests.py b/backend/lineups/tests.py index e538565..0eac97a 100644 --- a/backend/lineups/tests.py +++ b/backend/lineups/tests.py @@ -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."""