73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
import pytest
|
|
from sqlmodel import Session, select
|
|
|
|
from in_game.gameplay_models import Game, Lineup
|
|
from in_game.gameplay_queries import get_game_lineups, get_one_lineup
|
|
from tests.factory import session_fixture
|
|
|
|
|
|
def test_create_lineup(session: Session):
|
|
all_lineups = session.exec(select(Lineup)).all()
|
|
|
|
assert len(all_lineups) == 40
|
|
|
|
query_ss = session.exec(select(Lineup).where(Lineup.game_id == 1, Lineup.position == 'SS', Lineup.active == True)).all()
|
|
lineup_id_7 = session.get(Lineup, 7)
|
|
lineup_id_21 = session.get(Lineup, 21)
|
|
|
|
assert len(query_ss) == 2
|
|
assert lineup_id_7.position == 'CF'
|
|
assert lineup_id_21.position == 'C'
|
|
|
|
|
|
def test_get_game_lineups(session: Session):
|
|
this_game = session.get(Game, 1)
|
|
all_lineups = get_game_lineups(session, this_game=this_game)
|
|
away_lineups = get_game_lineups(session, this_game=this_game, specific_team=this_game.away_team)
|
|
|
|
assert len(all_lineups) == 20
|
|
assert len(away_lineups) == 10
|
|
|
|
for count in range(5):
|
|
away_lineups[count].active = False
|
|
session.add(away_lineups[count])
|
|
|
|
session.commit()
|
|
|
|
all_lineups = get_game_lineups(session, this_game=this_game)
|
|
away_lineups = get_game_lineups(session, this_game=this_game, specific_team=this_game.away_team)
|
|
active_away_lineups = get_game_lineups(session, this_game=this_game, specific_team=this_game.away_team, is_active=True)
|
|
inactive_home_lineups = get_game_lineups(session, this_game=this_game, specific_team=this_game.home_team, is_active=False)
|
|
|
|
assert len(all_lineups) == 20
|
|
assert len(away_lineups) == 10
|
|
assert len(active_away_lineups) == 5
|
|
assert len(inactive_home_lineups) == 0
|
|
|
|
|
|
def test_get_one_lineup(session: Session):
|
|
this_game = session.get(Game, 1)
|
|
|
|
ss = get_one_lineup(session, this_game, this_game.away_team, position='SS')
|
|
assert ss.batting_order == 5
|
|
|
|
leadoff = get_one_lineup(session, this_game, this_game.away_team, batting_order=1)
|
|
assert leadoff.position == 'C'
|
|
|
|
with pytest.raises(KeyError) as exc_info:
|
|
get_one_lineup(session, session, this_game, this_game.away_team)
|
|
|
|
assert str(exc_info) == "<ExceptionInfo KeyError('Position or batting order must be provided for get_one_lineup') tblen=2>"
|
|
|
|
|
|
# def test_lineup_substitution(session: Session, new_games_with_lineups: list[Game]):
|
|
# game_1 = new_games_with_lineups[0]
|
|
# game_2 = new_games_with_lineups[1]
|
|
|
|
# session.add(game_1)
|
|
# session.add(game_2)
|
|
# session.commit()
|
|
|
|
|
|
|