From 74cbef8d41712c0c2ee9402fbac7568a16582840 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Fri, 11 Oct 2024 17:29:54 -0500 Subject: [PATCH] Add pytests, first Game test --- .gitignore | 2 +- .vscode/settings.json | 7 +++++ in_game/gameplay_db.py | 4 +-- requirements.txt | 1 + tests/test_gameplay_db_game.py | 56 ++++++++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 tests/test_gameplay_db_game.py diff --git a/.gitignore b/.gitignore index 374f012..7607135 100644 --- a/.gitignore +++ b/.gitignore @@ -132,4 +132,4 @@ dmypy.json .idea/ # Project Specific -storage/* \ No newline at end of file +storage* \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3e99ede --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "python.testing.pytestArgs": [ + "." + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} \ No newline at end of file diff --git a/in_game/gameplay_db.py b/in_game/gameplay_db.py index 124906b..0549410 100644 --- a/in_game/gameplay_db.py +++ b/in_game/gameplay_db.py @@ -105,7 +105,7 @@ def create_test_games(): session.commit() -def select_testing(): +def select_speed_testing(): with Session(engine) as session: game_1 = session.exec(select(Game).where(Game.id == 1)).one() ss_search_start = datetime.datetime.now() @@ -127,7 +127,7 @@ def select_testing(): def main(): # create_db_and_tables() # create_test_games() - select_testing() + select_speed_testing() if __name__ == "__main__": diff --git a/requirements.txt b/requirements.txt index 9d082ff..5fbe2d7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ bs4 peewee sqlmodel alembic +pytest diff --git a/tests/test_gameplay_db_game.py b/tests/test_gameplay_db_game.py new file mode 100644 index 0000000..ebbdddc --- /dev/null +++ b/tests/test_gameplay_db_game.py @@ -0,0 +1,56 @@ +import pytest +from sqlmodel import Session, SQLModel, create_engine +from sqlmodel.pool import StaticPool + +from in_game.gameplay_db import Game + + +@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 + + +@pytest.fixture(name='new_games') +def new_games_fixture(): + return [ + 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') + ] + + +def test_create_game(session: Session, new_games: list[Game]): + game_1 = new_games[0] + game_2 = new_games[1] + session.add(game_1) + session.add(game_2) + session.commit() + + assert game_1.away_team_id == 1 + assert game_1.home_team_id == 2 + assert game_1.channel_id == 1234 + assert game_1.season == 9 + assert game_1.active == True + assert game_1.is_pd == True + assert game_1.ranked == False + assert game_1.week_num == None + assert game_1.game_num == None + assert game_1.away_roster_id == None + assert game_1.home_roster_id == None + assert game_1.first_message == None + assert game_1.ai_team == None + assert game_1.game_type == None + assert game_2.active == False + assert game_2.is_pd == False + assert game_2.ranked == True + assert game_2.week_num == 6 + assert game_2.game_num == 9 + assert game_2.away_roster_id == 69 + assert game_2.home_roster_id == 420 + assert game_2.first_message == 12345678 + assert game_2.ai_team == 'home' + assert game_2.game_type == 'minor-league'