Added targeted integration tests to cover previously uncovered conditional branches and edge cases in AI decision-making logic: - test_ai_service_focused_coverage.py: 11 tests for key missing branches * Steal opportunity conditions (lines 91, 93, 98-99, 108) * Steal to third/home scenarios (lines 129, 157, 161) * Defensive alignment logic (lines 438, 480) * Tag decision branches (lines 204, 253) - test_ai_service_final_coverage.py: 10 tests for remaining gaps * Complex steal conditions (lines 95, 118-119, 132, 136-137, 141) * Late inning steal logic (lines 159, 163) * Uncapped advance bounds checking (lines 382-388) * Complex defensive scenarios (lines 440-449) - test_ai_service_coverage.py: Comprehensive coverage tests (unused due to complexity) Fixed: - Player model relationship syntax (removed unsupported cascade_delete parameter) - Existing test assertion in test_ai_service_simple.py for steal to home scenario Coverage improvement: 369 statements, 147→105 missed lines (60%→72% coverage) All 49 AI Service tests now pass with comprehensive integration testing. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
67 lines
2.6 KiB
Python
67 lines
2.6 KiB
Python
"""
|
|
Player Model
|
|
|
|
Pure data model for player information, migrated from Discord app.
|
|
All business logic extracted to PlayerService.
|
|
"""
|
|
import datetime
|
|
from typing import TYPE_CHECKING, Optional
|
|
|
|
from pydantic import field_validator
|
|
from sqlalchemy import BigInteger, Column
|
|
from sqlmodel import Field, Relationship, SQLModel
|
|
|
|
if TYPE_CHECKING:
|
|
from .cardset import Cardset
|
|
# from .card import Card # Will be uncommented when Card model is created
|
|
# from .lineup import Lineup # Will be uncommented when Lineup model is created
|
|
from .position_rating import PositionRating
|
|
|
|
|
|
class PlayerBase(SQLModel):
|
|
"""Base player model with core data fields."""
|
|
|
|
id: Optional[int] = Field(sa_column=Column(BigInteger(), primary_key=True, autoincrement=False))
|
|
name: str
|
|
cost: int
|
|
image: str
|
|
mlbclub: str
|
|
franchise: str
|
|
cardset_id: Optional[int] = Field(default=None, foreign_key='cardset.id')
|
|
set_num: int
|
|
rarity_id: Optional[int] = Field(default=None)
|
|
pos_1: str
|
|
description: str
|
|
quantity: Optional[int] = Field(default=999)
|
|
image2: Optional[str] = Field(default=None)
|
|
pos_2: Optional[str] = Field(default=None)
|
|
pos_3: Optional[str] = Field(default=None)
|
|
pos_4: Optional[str] = Field(default=None)
|
|
pos_5: Optional[str] = Field(default=None)
|
|
pos_6: Optional[str] = Field(default=None)
|
|
pos_7: Optional[str] = Field(default=None)
|
|
pos_8: Optional[str] = Field(default=None)
|
|
headshot: Optional[str] = Field(default=None)
|
|
vanity_card: Optional[str] = Field(default=None)
|
|
strat_code: Optional[str] = Field(default=None)
|
|
bbref_id: Optional[str] = Field(default=None)
|
|
fangr_id: Optional[str] = Field(default=None)
|
|
mlbplayer_id: Optional[int] = Field(default=None)
|
|
created: datetime.datetime = Field(default_factory=datetime.datetime.now, nullable=True)
|
|
|
|
@field_validator('pos_1', 'pos_2', 'pos_3', 'pos_4', 'pos_5', 'pos_6', 'pos_7', 'pos_8')
|
|
def uppercase_strings(cls, value: str) -> str:
|
|
"""Ensure position strings are uppercase."""
|
|
if value is not None:
|
|
return value.upper()
|
|
else:
|
|
return value
|
|
|
|
|
|
class Player(PlayerBase, table=True):
|
|
"""Player model with database relationships."""
|
|
|
|
cardset: "Cardset" = Relationship(back_populates='players')
|
|
# cards: list["Card"] = Relationship(back_populates='player', cascade_delete=True) # Will be uncommented when Card model is created
|
|
# lineups: list["Lineup"] = Relationship(back_populates='player', cascade_delete=True) # Will be uncommented when Lineup model is created
|
|
positions: list["PositionRating"] = Relationship(back_populates='player') |