Prevents players who are already claimed in another team's pending transaction (frozen=false, cancelled=false) from being added to a new transaction for the same week. Changes: - Add is_player_in_pending_transaction() to TransactionService - Make TransactionBuilder.add_move() async with validation - Add check_pending_transactions flag (default True for /dropadd) - Skip validation for /ilmove and trades (check_pending_transactions=False) - Add tests/conftest.py for proper test isolation - Add 4 new tests for pending transaction validation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
"""
|
|
Pytest configuration and fixtures for Discord Bot v2.0 tests.
|
|
|
|
This file provides test isolation and shared fixtures.
|
|
"""
|
|
import asyncio
|
|
import os
|
|
import pytest
|
|
|
|
# Ensure environment is set up before any imports happen
|
|
# This is critical for tests that check GUILD_ID
|
|
os.environ.setdefault("GUILD_ID", "669356687294988350")
|
|
os.environ.setdefault("TESTING", "true")
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def reset_singleton_state():
|
|
"""
|
|
Reset any singleton/global state between tests.
|
|
|
|
This prevents test pollution from global state in services.
|
|
"""
|
|
# Import after test function starts to ensure clean state
|
|
yield # Run test
|
|
|
|
# Cleanup after test
|
|
# Reset transaction builder caches
|
|
try:
|
|
from services.transaction_builder import _transaction_builders
|
|
_transaction_builders.clear()
|
|
except ImportError:
|
|
pass
|
|
|
|
try:
|
|
from services.trade_builder import _trade_builders, _team_to_trade_key
|
|
_trade_builders.clear()
|
|
_team_to_trade_key.clear()
|
|
except ImportError:
|
|
pass
|
|
|
|
# Reset config singleton to ensure clean state
|
|
try:
|
|
from config import _config
|
|
import config as cfg
|
|
cfg._config = None
|
|
except (ImportError, AttributeError):
|
|
pass
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def event_loop_policy():
|
|
"""Use default event loop policy."""
|
|
return asyncio.DefaultEventLoopPolicy()
|