diff options
| author | Karan Jayachandra <karan.jayachandra@nxp.com> | 2024-04-05 10:12:17 +0200 |
|---|---|---|
| committer | Karan Jayachandra <karan.jayachandra@nxp.com> | 2024-04-05 10:12:17 +0200 |
| commit | 6dcdffeea79c76436fccaad5b382af709af8c121 (patch) | |
| tree | ff3191f8fa6bdecd8f32c959d626c38aa63a5567 /src/match_up/tests/__init__.py | |
| parent | bd3bd7de2fdb6cdb181a9b02b627c98c712f3739 (diff) | |
Updated the code the be in the right place for the data model
Diffstat (limited to 'src/match_up/tests/__init__.py')
| -rw-r--r-- | src/match_up/tests/__init__.py | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/match_up/tests/__init__.py b/src/match_up/tests/__init__.py index 38e377f..4dbd883 100644 --- a/src/match_up/tests/__init__.py +++ b/src/match_up/tests/__init__.py @@ -1,4 +1,5 @@ from os import remove +from os.path import isfile from random import randint from pathlib import PurePath from names import get_first_name, get_last_name @@ -9,16 +10,32 @@ MIN_SKILL = 1 MAX_SKILL = 10 -def generate_test_database(total_players: int = 20, active_players: int = 17) -> None: - p = PlayerDatabase(TEST_DATABASE_LOCATION) - for _ in range(total_players): - p.add_player( - Player( - first_name=get_first_name(), - last_name=get_last_name(), - skill=randint(MIN_SKILL, MAX_SKILL), +def generate_test_database(total_players: int = 20) -> None: + try: + if isfile(TEST_DATABASE_LOCATION): + remove_test_database() + db = PlayerDatabase(TEST_DATABASE_LOCATION) + for _ in range(total_players): + db.add_player( + Player( + first_name=get_first_name(), + last_name=get_last_name(), + skill=randint(MIN_SKILL, MAX_SKILL), + ) ) - ) + finally: + db.close() + + +def activate_random_players(activate_players: int = 17) -> None: + try: + db = PlayerDatabase(TEST_DATABASE_LOCATION) + player_list = db.get_players() + for index, player in enumerate(player_list): + if index < activate_players: + db.activate_player(player) + finally: + db.close() def remove_test_database() -> None: |
