major-domo-v2/tests/factories.py
Cal Corum c01f88e7e3 CLAUDE: Comprehensive bot improvements and test infrastructure
This commit includes various enhancements across the bot architecture:

**New Infrastructure:**
- Added tests/factories.py - Factory classes for creating test data objects
- Added PRE_LAUNCH_ROADMAP.md - Project planning and roadmap documentation

**Model Enhancements:**
- Updated models/roster.py - Enhanced roster data structures
- Updated models/team.py - Improved team model definitions

**Service Layer Improvements:**
- Enhanced services/player_service.py - Better player data handling
- Updated services/roster_service.py - Roster management improvements
- Enhanced services/team_service.py - Team data service refinements
- Updated services/transaction_service.py - Transaction processing enhancements

**Command Updates:**
- Updated commands/teams/info.py - Team information command improvements
- Enhanced commands/voice/tracker.py - Voice channel tracking refinements

**Background Tasks:**
- Updated tasks/custom_command_cleanup.py - Automated cleanup improvements

**View Components:**
- Enhanced views/transaction_embed.py - Transaction embed UI improvements

**Test Coverage Enhancements:**
- Updated tests/test_commands_voice.py - Voice command test improvements
- Enhanced tests/test_dropadd_integration.py - Integration test coverage
- Updated tests/test_services_player_service.py - Player service test coverage
- Enhanced tests/test_services_transaction_builder.py - Transaction builder tests
- Updated tests/test_transactions_integration.py - Transaction integration tests
- Enhanced tests/test_views_transaction_embed.py - UI component test coverage

These changes collectively improve the bot's reliability, maintainability, and test coverage while adding essential infrastructure for continued development.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-02 11:35:26 -05:00

208 lines
5.9 KiB
Python

"""
Test Factories for Discord Bot v2.0
Provides factory functions to create test instances of models with sensible defaults.
This eliminates the need for ad-hoc fixture creation and makes tests resilient
to model changes.
"""
from typing import Optional, Dict, Any
from models.player import Player
from models.team import Team, RosterType
from models.transaction import Transaction
class PlayerFactory:
"""Factory for creating Player test instances."""
@staticmethod
def create(
id: int = 1,
name: str = "Test Player",
wara: float = 2.0,
season: int = 12,
pos_1: str = "CF",
team_id: Optional[int] = None,
**kwargs
) -> Player:
"""Create a Player instance with sensible defaults."""
defaults = {
"id": id,
"name": name,
"wara": wara,
"season": season,
"pos_1": pos_1,
"team_id": team_id,
}
defaults.update(kwargs)
return Player(**defaults)
@staticmethod
def mike_trout(id: int = 12472, **kwargs) -> Player:
"""Create Mike Trout player for consistent testing."""
defaults = {
"id": id,
"name": "Mike Trout",
"wara": 2.5,
"season": 12,
"pos_1": "CF",
}
defaults.update(kwargs)
return PlayerFactory.create(**defaults)
@staticmethod
def ronald_acuna(id: int = 12473, **kwargs) -> Player:
"""Create Ronald Acuna Jr. player for consistent testing."""
defaults = {
"id": id,
"name": "Ronald Acuna Jr.",
"wara": 2.0,
"season": 12,
"pos_1": "OF",
}
defaults.update(kwargs)
return PlayerFactory.create(**defaults)
@staticmethod
def mookie_betts(id: int = 12474, **kwargs) -> Player:
"""Create Mookie Betts player for consistent testing."""
defaults = {
"id": id,
"name": "Mookie Betts",
"wara": 1.8,
"season": 12,
"pos_1": "RF",
}
defaults.update(kwargs)
return PlayerFactory.create(**defaults)
@staticmethod
def pitcher(id: int = 2000, name: str = "Test Pitcher", **kwargs) -> Player:
"""Create a pitcher for testing."""
defaults = {
"id": id,
"name": name,
"wara": 1.5,
"season": 12,
"pos_1": "SP",
}
defaults.update(kwargs)
return PlayerFactory.create(**defaults)
class TeamFactory:
"""Factory for creating Team test instances."""
@staticmethod
def create(
id: int = 1,
abbrev: str = "TST",
sname: str = "Test Team",
lname: str = "Test City Test Team",
season: int = 12,
**kwargs
) -> Team:
"""Create a Team instance with sensible defaults."""
defaults = {
"id": id,
"abbrev": abbrev,
"sname": sname,
"lname": lname,
"season": season,
}
defaults.update(kwargs)
return Team(**defaults)
@staticmethod
def west_virginia(id: int = 499, **kwargs) -> Team:
"""Create West Virginia Black Bears team for consistent testing."""
defaults = {
"id": id,
"abbrev": "WV",
"sname": "Black Bears",
"lname": "West Virginia Black Bears",
"season": 12,
}
defaults.update(kwargs)
return TeamFactory.create(**defaults)
@staticmethod
def new_york(id: int = 500, **kwargs) -> Team:
"""Create New York team for testing."""
defaults = {
"id": id,
"abbrev": "NY",
"sname": "Yankees",
"lname": "New York Yankees",
"season": 12,
}
defaults.update(kwargs)
return TeamFactory.create(**defaults)
class TransactionFactory:
"""Factory for creating Transaction test instances."""
@staticmethod
def create(
id: int = 1,
transaction_type: str = "Drop/Add",
player_id: int = 1,
team_id: int = 1,
season: int = 12,
week: int = 1,
**kwargs
) -> Transaction:
"""Create a Transaction instance with sensible defaults."""
defaults = {
"id": id,
"transaction_type": transaction_type,
"player_id": player_id,
"team_id": team_id,
"season": season,
"week": week,
}
defaults.update(kwargs)
return Transaction(**defaults)
# Convenience functions for common test scenarios
def create_player_list(count: int = 3, **kwargs) -> list[Player]:
"""Create a list of test players."""
players = []
for i in range(count):
player_kwargs = {
"id": i + 1,
"name": f"Test Player {i + 1}",
**kwargs
}
players.append(PlayerFactory.create(**player_kwargs))
return players
def create_team_roster(team_id: int = 1, player_count: int = 25) -> list[Player]:
"""Create a full team roster for testing."""
players = []
positions = ["C", "1B", "2B", "3B", "SS", "LF", "CF", "RF", "SP", "RP"]
for i in range(player_count):
pos = positions[i % len(positions)]
player = PlayerFactory.create(
id=i + 1,
name=f"Player {i + 1}",
team_id=team_id,
pos_1=pos
)
players.append(player)
return players
def create_pitcher_staff(team_id: int = 1) -> list[Player]:
"""Create a pitching staff for testing."""
return [
PlayerFactory.create(id=100, name="Starter 1", team_id=team_id, pos_1="SP"),
PlayerFactory.create(id=101, name="Starter 2", team_id=team_id, pos_1="SP"),
PlayerFactory.create(id=102, name="Reliever 1", team_id=team_id, pos_1="RP"),
PlayerFactory.create(id=103, name="Reliever 2", team_id=team_id, pos_1="RP"),
]