80 lines
2.8 KiB
Python
80 lines
2.8 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, get_sorted_lineups
|
|
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, 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_order_lineups_by_position(session: Session):
|
|
this_game = session.get(Game, 1)
|
|
all_lineups = get_sorted_lineups(session, this_game, this_game.home_team)
|
|
|
|
assert all_lineups[0].position == 'P'
|
|
assert all_lineups[1].position == 'C'
|
|
assert all_lineups[2].position == '1B'
|
|
assert all_lineups[3].position == '2B'
|
|
assert all_lineups[4].position == '3B'
|
|
assert all_lineups[5].position == 'SS'
|
|
assert all_lineups[6].position == 'LF'
|
|
assert all_lineups[7].position == 'CF'
|
|
assert all_lineups[8].position == 'RF'
|
|
|
|
|
|
|
|
|