- 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>
116 lines
3.3 KiB
Python
116 lines
3.3 KiB
Python
"""
|
|
Cardset factory for generating test data.
|
|
|
|
Provides methods to create unique, valid Cardset instances for testing
|
|
without conflicts between test runs.
|
|
"""
|
|
|
|
from app.models.cardset import Cardset
|
|
from tests.conftest import generate_unique_id, generate_unique_name
|
|
|
|
|
|
class CardsetFactory:
|
|
"""Factory for creating Cardset test instances."""
|
|
|
|
@staticmethod
|
|
def build(**kwargs):
|
|
"""
|
|
Build a Cardset instance without saving to database.
|
|
|
|
Args:
|
|
**kwargs: Override default field values
|
|
|
|
Returns:
|
|
Cardset: Configured cardset instance
|
|
|
|
Example:
|
|
cardset = CardsetFactory.build(name="Custom Name")
|
|
cardset = CardsetFactory.build(ranked_legal=True)
|
|
"""
|
|
defaults = {
|
|
'id': generate_unique_id(),
|
|
'name': generate_unique_name("Cardset"),
|
|
'ranked_legal': False
|
|
}
|
|
defaults.update(kwargs)
|
|
return Cardset(**defaults)
|
|
|
|
@classmethod
|
|
def create(cls, session, **kwargs):
|
|
"""
|
|
Create and save a Cardset instance to database.
|
|
|
|
Args:
|
|
session: Database session
|
|
**kwargs: Override default field values
|
|
|
|
Returns:
|
|
Cardset: Saved cardset instance
|
|
|
|
Example:
|
|
cardset = CardsetFactory.create(session, ranked_legal=True)
|
|
"""
|
|
cardset = cls.build(**kwargs)
|
|
session.add(cardset)
|
|
session.flush() # Get ID without committing
|
|
return cardset
|
|
|
|
@classmethod
|
|
def build_batch(cls, count, **kwargs):
|
|
"""
|
|
Build multiple Cardset instances.
|
|
|
|
Args:
|
|
count: Number of cardsets to create
|
|
**kwargs: Common field values for all cardsets
|
|
|
|
Returns:
|
|
list[Cardset]: List of cardset instances
|
|
|
|
Example:
|
|
cardsets = CardsetFactory.build_batch(3, ranked_legal=True)
|
|
"""
|
|
return [cls.build(**kwargs) for _ in range(count)]
|
|
|
|
@classmethod
|
|
def create_batch(cls, session, count, **kwargs):
|
|
"""
|
|
Create and save multiple Cardset instances.
|
|
|
|
Args:
|
|
session: Database session
|
|
count: Number of cardsets to create
|
|
**kwargs: Common field values for all cardsets
|
|
|
|
Returns:
|
|
list[Cardset]: List of saved cardset instances
|
|
|
|
Example:
|
|
cardsets = CardsetFactory.create_batch(session, 3, ranked_legal=True)
|
|
"""
|
|
cardsets = cls.build_batch(count, **kwargs)
|
|
session.add_all(cardsets)
|
|
session.flush()
|
|
return cardsets
|
|
|
|
# Preset factories for common scenarios
|
|
@classmethod
|
|
def build_ranked_legal(cls, **kwargs):
|
|
"""Build a ranked legal cardset."""
|
|
defaults = {'ranked_legal': True, 'name': generate_unique_name("Ranked Set")}
|
|
defaults.update(kwargs)
|
|
return cls.build(**defaults)
|
|
|
|
@classmethod
|
|
def build_casual(cls, **kwargs):
|
|
"""Build a casual (non-ranked) cardset."""
|
|
defaults = {'ranked_legal': False, 'name': generate_unique_name("Casual Set")}
|
|
defaults.update(kwargs)
|
|
return cls.build(**defaults)
|
|
|
|
@classmethod
|
|
def build_historic(cls, **kwargs):
|
|
"""Build a historic cardset."""
|
|
defaults = {'ranked_legal': False, 'name': generate_unique_name("Historic Set")}
|
|
defaults.update(kwargs)
|
|
return cls.build(**defaults) |