Skip to content

Commit

Permalink
Only use online/offline states
Browse files Browse the repository at this point in the history
  • Loading branch information
Askaholic committed Dec 25, 2023
1 parent 289e273 commit 76d7944
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
14 changes: 7 additions & 7 deletions server/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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],
Expand Down
8 changes: 4 additions & 4 deletions tests/integration_tests/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests/test_teammatchmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down
7 changes: 3 additions & 4 deletions tests/unit_tests/test_players.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 76d7944

Please sign in to comment.