From 76d794424e52750a209ffe1fe59c01783c678be5 Mon Sep 17 00:00:00 2001 From: Askaholic Date: Sun, 24 Dec 2023 20:09:48 -0500 Subject: [PATCH] Only use online/offline states --- server/players.py | 14 +++++++------- tests/integration_tests/test_login.py | 8 ++++---- tests/integration_tests/test_teammatchmaker.py | 4 ++-- tests/unit_tests/test_players.py | 7 +++---- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/server/players.py b/server/players.py index 0d33d0b48..9e0a26dd7 100644 --- a/server/players.py +++ b/server/players.py @@ -15,12 +15,12 @@ @unique class PlayerState(Enum): - IDLE = "idle" - PLAYING = "playing" - HOSTING = "hosting" - JOINING = "joining" - SEARCHING_LADDER = "searching" - STARTING_AUTOMATCH = "matching" + IDLE = 1 + PLAYING = 2 + HOSTING = 3 + JOINING = 4 + SEARCHING_LADDER = 5 + STARTING_AUTOMATCH = 6 class Player: @@ -142,7 +142,7 @@ def to_dict(self) -> dict: "avatar": self.avatar, "country": self.country, "clan": self.clan, - "state": self.state.value if self.lobby_connection else "offline", + "state": "online" if self.lobby_connection else "offline", "ratings": { rating_type: { "rating": self.ratings[rating_type], diff --git a/tests/integration_tests/test_login.py b/tests/integration_tests/test_login.py index 6e1338957..3a37a5b95 100644 --- a/tests/integration_tests/test_login.py +++ b/tests/integration_tests/test_login.py @@ -62,7 +62,7 @@ async def test_server_valid_login(lobby_server): "login": "Rhiza", "clan": "123", "country": "", - "state": "idle", + "state": "online", "ratings": { "global": { "rating": [1650.0, 62.52], @@ -108,7 +108,7 @@ async def test_server_valid_login_admin(lobby_server): "login": "test", "clan": "678", "country": "", - "state": "idle", + "state": "online", "ratings": { "global": { "rating": [2000.0, 125.0], @@ -153,7 +153,7 @@ async def test_server_valid_login_moderator(lobby_server): "id": 20, "login": "moderator", "country": "", - "state": "idle", + "state": "online", "ratings": { "global": { "rating": [1500, 500], @@ -252,7 +252,7 @@ async def test_server_valid_login_with_token(lobby_server, jwk_priv_key, jwk_kid "login": "Rhiza", "clan": "123", "country": "", - "state": "idle", + "state": "online", "ratings": { "global": { "rating": [1650.0, 62.52], diff --git a/tests/integration_tests/test_teammatchmaker.py b/tests/integration_tests/test_teammatchmaker.py index 84950267b..e02810043 100644 --- a/tests/integration_tests/test_teammatchmaker.py +++ b/tests/integration_tests/test_teammatchmaker.py @@ -583,7 +583,7 @@ async def test_ratings_initialized_based_on_global(lobby_server): "login": "test", "clan": "678", "country": "", - "state": "idle", + "state": "online", "ratings": { "global": { "rating": [2000.0, 125.0], @@ -621,7 +621,7 @@ async def test_ratings_initialized_based_on_global(lobby_server): "login": "test", "clan": "678", "country": "", - "state": "searching", + "state": "online", "ratings": { "global": { "rating": [2000.0, 125.0], diff --git a/tests/unit_tests/test_players.py b/tests/unit_tests/test_players.py index 08d92e039..a544e5cab 100644 --- a/tests/unit_tests/test_players.py +++ b/tests/unit_tests/test_players.py @@ -111,11 +111,10 @@ def test_serialize(): def test_serialize_state(): conn = mock.Mock() p = Player(lobby_connection=conn) - assert p.to_dict()["state"] == "idle" + assert p.to_dict()["state"] == "online" - for state in PlayerState: - p.state = state - assert p.to_dict()["state"] == state.value + del p.lobby_connection + assert p.to_dict()["state"] == "offline" async def test_send_message():