181 lines
8.5 KiB
Python
181 lines
8.5 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_models import Card, Cardset, Game, GameCardsetLink, Lineup, ManagerAi, Play, Team, Player
|
|
|
|
|
|
@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:
|
|
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=True
|
|
)
|
|
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
|
|
)
|
|
team_3 = Team(
|
|
id=69, abbrev='NCB3', 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_4 = Team(
|
|
id=420, abbrev='WV4', 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=True
|
|
)
|
|
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)
|
|
)
|
|
|
|
session.add(team_1)
|
|
session.add(team_2)
|
|
session.add(team_3)
|
|
session.add(team_4)
|
|
# session.add(incomplete_team)
|
|
session.add(old_cache_team)
|
|
session.commit()
|
|
|
|
game_1 = Game(away_team_id=31, home_team_id=400, channel_id=1234, season=9, ai_team='away', game_type='minor-league')
|
|
game_2 = Game(away_team_id=69, home_team_id=420, channel_id=5678, season=9, active=False, is_pd=True, 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')
|
|
game_3 = Game(away_team_id=69, home_team_id=420, channel_id=5678, season=9, active=True, is_pd=True, ranked=True, week_num=6, game_num=10, away_roster_id=69, home_roster_id=420, first_message=34567890, ai_team='home', game_type='minor-league')
|
|
|
|
session.add(game_1)
|
|
session.add(game_2)
|
|
session.add(game_3)
|
|
session.commit()
|
|
|
|
cardset_1 = Cardset(id=1, name='1969 Live')
|
|
cardset_2 = Cardset(id=2, name='2024 Season')
|
|
|
|
session.add(cardset_1)
|
|
session.add(cardset_2)
|
|
session.commit()
|
|
|
|
link_1 = GameCardsetLink(game=game_1, cardset=cardset_1, priority=1)
|
|
link_2 = GameCardsetLink(game=game_1, cardset=cardset_2, priority=1)
|
|
link_3 = GameCardsetLink(game=game_2, cardset=cardset_1, priority=1)
|
|
link_4 = GameCardsetLink(game=game_2, cardset=cardset_2, priority=2)
|
|
|
|
session.add(link_1)
|
|
session.add(link_2)
|
|
session.add(link_3)
|
|
session.add(link_4)
|
|
session.commit()
|
|
|
|
all_players = []
|
|
all_cards = []
|
|
pos_list = ['C', '1B', '2B', '3B', 'SS', 'LF', 'CF', 'RF', 'DH', 'P']
|
|
for x in range(40):
|
|
if x < 10:
|
|
mlb_team = 'Baltimore Orioles'
|
|
team_id = 31
|
|
elif x < 20:
|
|
mlb_team = 'New York Yankees'
|
|
team_id = 400
|
|
elif x < 30:
|
|
mlb_team = 'Boston Red Sox'
|
|
team_id = 69
|
|
else:
|
|
mlb_team = 'Tampa Bay Rays'
|
|
team_id = 420
|
|
|
|
all_players.append(Player(
|
|
id=x+1,
|
|
name=f'Player {x}',
|
|
cost=x * 3,
|
|
image=f'player_{x}_image_url',
|
|
mlbclub=mlb_team,
|
|
franchise=mlb_team,
|
|
cardset=cardset_1 if x % 2 == 1 else cardset_2,
|
|
set_num=x,
|
|
rarity_id=1,
|
|
pos_1=pos_list[(x % 10)],
|
|
description="Live" if x % 2 == 1 else "2024"
|
|
))
|
|
all_cards.append(Card(
|
|
player_id=x+1,
|
|
team_id=team_id
|
|
))
|
|
|
|
all_players.append(Player(
|
|
id=69, name='Player 68', cost=69*3, mlbclub='Junior All-Stars', franchise='Junior All-Stars', cardset=cardset_1, set_num=69, pos_1='DH', description='Live', created=datetime.datetime.today() - datetime.timedelta(days=60), image='player_69_image_URL', rarity_id=1
|
|
))
|
|
all_cards.append(Card(
|
|
player_id=41,
|
|
team_id=420,
|
|
created=datetime.datetime.now() - datetime.timedelta(days=60)
|
|
))
|
|
all_players.append(Player(
|
|
id=70, name='Player 69', cost=70*3, mlbclub='Junior All-Stars', franchise='Junior All-Stars', cardset=cardset_1, set_num=70, pos_1='SP', pos_2='DH', description='Live', created=datetime.datetime.today() - datetime.timedelta(days=60), image='player_69_pitchingcard', image2='player_69_battingcard', rarity_id=1
|
|
))
|
|
|
|
for player in all_players:
|
|
session.add(player)
|
|
for card in all_cards:
|
|
session.add(card)
|
|
|
|
session.commit()
|
|
|
|
all_lineups = []
|
|
player_count = 1
|
|
for team in [team_1, team_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(
|
|
position=pos,
|
|
batting_order=order,
|
|
game=game_1,
|
|
team=team,
|
|
player_id=player_count,
|
|
card_id=player_count
|
|
))
|
|
player_count += 1
|
|
for team in [team_3, team_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(
|
|
position=pos,
|
|
batting_order=order,
|
|
game=game_3,
|
|
team=team,
|
|
player_id=player_count,
|
|
card_id=player_count
|
|
))
|
|
player_count += 1
|
|
|
|
for lineup in all_lineups:
|
|
session.add(lineup)
|
|
|
|
game_1_play_1 = Play(
|
|
game=game_1,
|
|
play_num=1,
|
|
batter=all_lineups[0],
|
|
batter_pos=all_lineups[0].position,
|
|
pitcher=all_lineups[19],
|
|
catcher=all_lineups[10],
|
|
pa=1,
|
|
so=1
|
|
)
|
|
game_1_play_2 = Play(
|
|
game=game_1,
|
|
play_num=2,
|
|
batter=all_lineups[1],
|
|
batter_pos=all_lineups[1].position,
|
|
pitcher=all_lineups[19],
|
|
catcher=all_lineups[10],
|
|
starting_outs=1
|
|
)
|
|
|
|
session.add(game_1_play_1)
|
|
session.add(game_1_play_2)
|
|
|
|
session.commit()
|
|
|
|
all_ai = ManagerAi.create_ai(session)
|
|
|
|
yield session
|