paper-dynasty-discord/tests/factory.py
2024-10-12 02:08:05 -05:00

62 lines
3.1 KiB
Python

import datetime
import pytest
from sqlmodel import Session, SQLModel, create_engine
from sqlmodel.pool import StaticPool
from typing import Literal
from in_game.gameplay_db import Game, Lineup, Team
@pytest.fixture(name='session')
def session_fixture():
engine = create_engine(
'sqlite://', connect_args={'check_same_thread': False}, poolclass=StaticPool
)
SQLModel.metadata.create_all(engine)
with Session(engine) as session:
yield session
RAW_GAMES = [
Game(away_team_id=1, home_team_id=2, channel_id=1234, season=9),
Game(away_team_id=3, home_team_id=4, channel_id=5678, season=9, active=False, is_pd=False, ranked=True, week_num=6, game_num=9, away_roster_id=69, home_roster_id=420, first_message=12345678, ai_team='home', game_type='minor-league')
]
@pytest.fixture(name='new_games')
def new_games_fixture():
return RAW_GAMES
@pytest.fixture(name='new_games_with_lineups')
def new_games_with_lineups_fixture():
game_1 = RAW_GAMES[0]
game_2 = RAW_GAMES[1]
all_lineups = []
for team_id in [1, 2]:
for (order, pos) in [(1, 'C'), (2, '1B'), (3, '2B'), (4, '3B'), (5, 'SS'), (6, 'LF'), (7, 'CF'), (8, 'RF'), (9, 'DH'), (10, 'P')]:
all_lineups.append(Lineup(team_id=team_id, card_id=order, player_id=68+order, position=pos, batting_order=order, game=game_1))
for team_id in [3, 4]:
for (order, pos) in [(1, 'C'), (2, '1B'), (3, '2B'), (4, '3B'), (5, 'SS'), (6, 'LF'), (7, 'CF'), (8, 'RF'), (9, 'DH'), (10, 'P')]:
all_lineups.append(Lineup(team_id=team_id, card_id=order, player_id=100+order, position=pos, batting_order=order, game=game_2))
return [game_1, game_2]
@pytest.fixture(name='new_teams')
def new_teams_fixture():
team_1 = Team(
id=31, abbrev='NCB', sname='CornBelters', lname='Normal CornBelters', gmid=1234, gmname='Cal', gsheet='asdf1234', wallet=6969, team_value=69420, collection_value=169420, color='006900', season=7, event=False, career=1234, ranking=1337, has_guide=True, is_ai=False
)
team_2 = Team(
id=400, abbrev='WV', sname='Black Bears', lname='West Virginia Black Bears', gmid=5678, gmname='Evil Cal', gsheet='https://i.postimg.cc/HjDc8bBF/blackbears-transparent.png', wallet=350, team_value=420, collection_value=169, color='6699FF', season=7, event=False, career=2, ranking=969, has_guide=False, is_ai=False
)
incomplete_team = Team(
id=446, abbrev='CLS', sname='Macho Men', lname='Columbus Macho Men', gmid=181818, gmname='Mason Socc', gsheet='asdf1234', wallet=6969, team_value=69420, collection_value=169420, color='https://i.postimg.cc/8kLZCYXh/S10CLS.png', season=7, event=False, career=0
)
old_cache_team = Team(
id=3, abbrev='BAL', sname='Orioles', lname='Baltimore Orioles', gmid=181818, gmname='Brandon Hyde', gsheet='asdf1234', wallet=6969, team_value=69420, collection_value=169420, color='https://i.postimg.cc/8kLZCYXh/S10CLS.png', season=7, event=False, career=0, ranking=500, has_guide=False, is_ai=False, created=datetime.datetime.today() - datetime.timedelta(days=60))
return [team_1, team_2, incomplete_team, old_cache_team]