import pytest from sqlmodel import Session, select, func from in_game.gameplay_models import Card from in_game.gameplay_queries import get_batter_scouting_or_none, get_card_or_none, get_pitcher_scouting_or_none from tests.factory import session_fixture sample_ratings_query = { "count": 2, "ratings": [ { "id": 7673, "battingcard": { "id": 3837, "player": { "player_id": 395, "p_name": "Cedric Mullins", "cost": 256, "image": "https://pd.manticorum.com/api/v2/players/395/battingcard?d=2023-11-19", "image2": None, "mlbclub": "Baltimore Orioles", "franchise": "Baltimore Orioles", "cardset": { "id": 1, "name": "2021 Season", "description": "Cards based on the full 2021 season", "event": None, "for_purchase": True, "total_cards": 791, "in_packs": True, "ranked_legal": False }, "set_num": 395, "rarity": { "id": 2, "value": 3, "name": "All-Star", "color": "FFD700" }, "pos_1": "CF", "pos_2": None, "pos_3": None, "pos_4": None, "pos_5": None, "pos_6": None, "pos_7": None, "pos_8": None, "headshot": "https://www.baseball-reference.com/req/202206291/images/headshots/2/24bf4355_mlbam.jpg", "vanity_card": None, "strat_code": "17929", "bbref_id": "mullice01", "fangr_id": None, "description": "2021", "quantity": 999, "mlbplayer": { "id": 396, "first_name": "Cedric", "last_name": "Mullins", "key_fangraphs": 17929, "key_bbref": "mullice01", "key_retro": "mullc002", "key_mlbam": 656775, "offense_col": 1 } }, "variant": 0, "steal_low": 9, "steal_high": 12, "steal_auto": True, "steal_jump": 0.2222222222222222, "bunting": "C", "hit_and_run": "B", "running": 13, "offense_col": 1, "hand": "L" }, "vs_hand": "L", "pull_rate": 0.43888889, "center_rate": 0.32777778, "slap_rate": 0.23333333, "homerun": 2.25, "bp_homerun": 5.0, "triple": 0.0, "double_three": 0.0, "double_two": 2.4, "double_pull": 7.2, "single_two": 4.6, "single_one": 3.5, "single_center": 5.85, "bp_single": 5.0, "hbp": 2.0, "walk": 9.0, "strikeout": 23.0, "lineout": 3.0, "popout": 6.0, "flyout_a": 0.0, "flyout_bq": 0.15, "flyout_lf_b": 2.8, "flyout_rf_b": 3.75, "groundout_a": 0.0, "groundout_b": 9.0, "groundout_c": 13.5, "avg": 0.2851851851851852, "obp": 0.387037037037037, "slg": 0.5060185185185185 }, { "id": 7674, "battingcard": { "id": 3837, "player": { "player_id": 395, "p_name": "Cedric Mullins", "cost": 256, "image": "https://pd.manticorum.com/api/v2/players/395/battingcard?d=2023-11-19", "image2": None, "mlbclub": "Baltimore Orioles", "franchise": "Baltimore Orioles", "cardset": { "id": 1, "name": "2021 Season", "description": "Cards based on the full 2021 season", "event": None, "for_purchase": True, "total_cards": 791, "in_packs": True, "ranked_legal": False }, "set_num": 395, "rarity": { "id": 2, "value": 3, "name": "All-Star", "color": "FFD700" }, "pos_1": "CF", "pos_2": None, "pos_3": None, "pos_4": None, "pos_5": None, "pos_6": None, "pos_7": None, "pos_8": None, "headshot": "https://www.baseball-reference.com/req/202206291/images/headshots/2/24bf4355_mlbam.jpg", "vanity_card": None, "strat_code": "17929", "bbref_id": "mullice01", "fangr_id": None, "description": "2021", "quantity": 999, "mlbplayer": { "id": 396, "first_name": "Cedric", "last_name": "Mullins", "key_fangraphs": 17929, "key_bbref": "mullice01", "key_retro": "mullc002", "key_mlbam": 656775, "offense_col": 1 } }, "variant": 0, "steal_low": 9, "steal_high": 12, "steal_auto": True, "steal_jump": 0.2222222222222222, "bunting": "C", "hit_and_run": "B", "running": 13, "offense_col": 1, "hand": "L" }, "vs_hand": "R", "pull_rate": 0.43377483, "center_rate": 0.32119205, "slap_rate": 0.24503311, "homerun": 2.0, "bp_homerun": 7.0, "triple": 0.0, "double_three": 0.0, "double_two": 2.7, "double_pull": 7.95, "single_two": 3.3, "single_one": 0.0, "single_center": 8.6, "bp_single": 5.0, "hbp": 1.0, "walk": 12.9, "strikeout": 11.1, "lineout": 8.0, "popout": 11.0, "flyout_a": 0.0, "flyout_bq": 0.4, "flyout_lf_b": 4.05, "flyout_rf_b": 6.0, "groundout_a": 0.0, "groundout_b": 3.0, "groundout_c": 14.0, "avg": 0.2828703703703704, "obp": 0.4115740740740741, "slg": 0.5342592592592592 } ] } async def test_create_scouting(session: Session): this_card = await get_card_or_none(session, card_id=1405) assert this_card.player.id == 395 assert this_card.team.id == 31 assert this_card.batterscouting.battingcard_id == sample_ratings_query["ratings"][0]['battingcard']['id'] # this_scouting = await get_batter_scouting_or_none(session, this_card) # assert this_scouting.battingcard_id == sample_ratings_query["ratings"][0]['battingcard']['id'] # this_card = await get_card_or_none(session, card_id=1406) # assert this_card.player.id == 161 # assert this_card.team.id == 31 # this_scouting = await get_pitcher_scouting_or_none(session, this_card) # assert this_scouting.pitchingcard_id == 4294