- Fix TypeError in check_steal_opportunity by properly mocking catcher defense - Correct tag_from_third test calculation to account for all adjustment conditions - Fix pitcher replacement test by setting appropriate allowed runners threshold - Add comprehensive test coverage for AI service business logic - Implement VS Code testing panel configuration with pytest integration - Create pytest.ini for consistent test execution and warning management - Add test isolation guidelines and factory pattern implementation - Establish 102 passing tests with zero failures 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
138 lines
3.7 KiB
Python
138 lines
3.7 KiB
Python
"""
|
|
Team factory for generating test data.
|
|
|
|
Provides methods to create unique, valid Team instances for testing
|
|
without conflicts between test runs.
|
|
"""
|
|
|
|
from app.models.team import Team
|
|
from tests.conftest import generate_unique_id, generate_unique_name
|
|
|
|
|
|
class TeamFactory:
|
|
"""Factory for creating Team test instances."""
|
|
|
|
@staticmethod
|
|
def build(**kwargs):
|
|
"""
|
|
Build a Team instance without saving to database.
|
|
|
|
Args:
|
|
**kwargs: Override default field values
|
|
|
|
Returns:
|
|
Team: Configured team instance
|
|
|
|
Example:
|
|
team = TeamFactory.build(abbrev="LAD")
|
|
team = TeamFactory.build(is_ai=True, wallet=50000)
|
|
"""
|
|
defaults = {
|
|
'id': generate_unique_id(),
|
|
'abbrev': 'TST',
|
|
'sname': 'Test',
|
|
'lname': 'Test Team',
|
|
'gmid': generate_unique_id(),
|
|
'gmname': 'Test GM',
|
|
'gsheet': 'test-sheet-url',
|
|
'wallet': 25000,
|
|
'team_value': 100000,
|
|
'collection_value': 75000,
|
|
'logo': 'https://example.com/test-logo.png',
|
|
'color': 'ff0000',
|
|
'season': 9,
|
|
'career': 1,
|
|
'ranking': 50,
|
|
'has_guide': False,
|
|
'is_ai': False,
|
|
}
|
|
|
|
# Override defaults with provided kwargs
|
|
defaults.update(kwargs)
|
|
return Team(**defaults)
|
|
|
|
@staticmethod
|
|
def create(session, **kwargs):
|
|
"""
|
|
Create and save a Team instance to the database.
|
|
|
|
Args:
|
|
session: Database session
|
|
**kwargs: Override default field values
|
|
|
|
Returns:
|
|
Team: Saved team instance
|
|
|
|
Example:
|
|
team = TeamFactory.create(session, abbrev="LAD")
|
|
"""
|
|
team = TeamFactory.build(**kwargs)
|
|
session.add(team)
|
|
session.commit()
|
|
session.refresh(team)
|
|
return team
|
|
|
|
@staticmethod
|
|
def build_ai_team(**kwargs):
|
|
"""
|
|
Build an AI team with appropriate defaults.
|
|
|
|
Args:
|
|
**kwargs: Override default field values
|
|
|
|
Returns:
|
|
Team: AI team instance
|
|
"""
|
|
ai_defaults = {
|
|
'is_ai': True,
|
|
'abbrev': 'AI',
|
|
'lname': 'AI Team',
|
|
'gmname': 'AI Manager',
|
|
}
|
|
ai_defaults.update(kwargs)
|
|
return TeamFactory.build(**ai_defaults)
|
|
|
|
@staticmethod
|
|
def build_human_team(**kwargs):
|
|
"""
|
|
Build a human team with appropriate defaults.
|
|
|
|
Args:
|
|
**kwargs: Override default field values
|
|
|
|
Returns:
|
|
Team: Human team instance
|
|
"""
|
|
human_defaults = {
|
|
'is_ai': False,
|
|
'abbrev': 'HUM',
|
|
'lname': 'Human Team',
|
|
'gmname': 'Human Manager',
|
|
'wallet': 50000,
|
|
}
|
|
human_defaults.update(kwargs)
|
|
return TeamFactory.build(**human_defaults)
|
|
|
|
@staticmethod
|
|
def build_multiple(count=3, **kwargs):
|
|
"""
|
|
Build multiple Team instances with unique IDs.
|
|
|
|
Args:
|
|
count: Number of teams to create
|
|
**kwargs: Base field values for all teams
|
|
|
|
Returns:
|
|
list[Team]: List of team instances
|
|
"""
|
|
teams = []
|
|
for i in range(count):
|
|
team_kwargs = kwargs.copy()
|
|
team_kwargs['id'] = generate_unique_id()
|
|
team_kwargs['gmid'] = generate_unique_id()
|
|
if 'abbrev' not in team_kwargs:
|
|
team_kwargs['abbrev'] = f'T{i+1:02d}'
|
|
if 'lname' not in team_kwargs:
|
|
team_kwargs['lname'] = f'Team {i+1}'
|
|
teams.append(TeamFactory.build(**team_kwargs))
|
|
return teams |