diff --git a/server/games/game.py b/server/games/game.py index b7cc46612..ce631469f 100644 --- a/server/games/game.py +++ b/server/games/game.py @@ -10,7 +10,6 @@ Iterable, List, Optional, - OrderedDict, Set, Tuple ) @@ -851,14 +850,14 @@ def get_player_outcome(self, player: Player) -> ArmyOutcome: return self._results.outcome(army) - def get_army_results(self, player: Player) -> OrderedDict: + def get_army_results(self, player: Player) -> ArmyResult: army = self.get_player_option(player.id, "Army") return ArmyResult( player.id, army, self.get_player_outcome(player).name, self._results.metadata(army), - )._asdict() + ) def report_army_stats(self, stats_json): self._army_stats_list = json.loads(stats_json)["stats"] diff --git a/server/games/game_results.py b/server/games/game_results.py index 3f803e3b0..31743cfb1 100644 --- a/server/games/game_results.py +++ b/server/games/game_results.py @@ -45,7 +45,7 @@ class ArmyResult(NamedTuple): """ player_id: int army: Optional[int] - army_result: str + army_outcome: str metadata: List[str] diff --git a/server/games/typedefs.py b/server/games/typedefs.py index 9067e09ac..f1383f7ce 100644 --- a/server/games/typedefs.py +++ b/server/games/typedefs.py @@ -1,7 +1,7 @@ from enum import Enum, unique -from typing import Any, Dict, List, NamedTuple, Optional, OrderedDict, Set +from typing import Any, Dict, List, NamedTuple, Optional, Set -from server.games.game_results import GameOutcome +from server.games.game_results import ArmyResult, GameOutcome from server.players import Player @@ -123,7 +123,7 @@ class BasicGameInfo(NamedTuple): class TeamRatingSummary(NamedTuple): outcome: GameOutcome player_ids: Set[int] - army_results: List[OrderedDict] + army_results: List[ArmyResult] class EndedGameInfo(NamedTuple): @@ -155,7 +155,7 @@ def from_basic( validity: ValidityState, team_outcomes: List[GameOutcome], commander_kills: Dict[str, int], - team_army_results: List[List[OrderedDict]], + team_army_results: List[List[ArmyResult]], ) -> "EndedGameInfo": if len(basic_info.teams) != len(team_outcomes): raise ValueError( @@ -193,7 +193,7 @@ def to_dict(self): { "outcome": team_summary.outcome.name, "player_ids": list(team_summary.player_ids), - "army_results": team_summary.army_results, + "army_results": [result._asdict() for result in team_summary.army_results], } for team_summary in self.team_summaries ], diff --git a/tests/data/test-data.sql b/tests/data/test-data.sql index f6063085d..459a83804 100644 --- a/tests/data/test-data.sql +++ b/tests/data/test-data.sql @@ -229,7 +229,7 @@ INSERT INTO `coop_map` (`type`, `name`, `description`, `version`, `filename`) VA insert into game_featuredMods (id, gamemod, name, description, publish, git_url, git_branch, file_extension, allow_override) values (1, 'faf', 'FAF', 'Forged Alliance Forever', 1, 'https://github.com/FAForever/fa.git', 'deploy/faf', 'nx2', FALSE), (6, 'ladder1v1', 'FAF', 'Ladder games', 1, 'https://github.com/FAForever/fa.git', 'deploy/faf', 'nx2', TRUE), - (24, 'gw', '', 'Galactic War', 0, NULL, NULL, NULL, NULL), -- GW unpublished because you can't start them from "Host game" + (24, 'gw', '', 'Galactic War', 0, NULL, NULL, NULL, NULL), -- GW shouldn't show up in the featured mod list in the client (25, 'coop', 'Coop', 'Multiplayer campaign games', 1, 'https://github.com/FAForever/fa-coop.git', 'master', 'cop', TRUE); insert into game_stats (id, startTime, gameName, gameType, gameMod, host, mapId, validity) values diff --git a/tests/integration_tests/test_game.py b/tests/integration_tests/test_game.py index 9b172d9f4..e0610c0d1 100644 --- a/tests/integration_tests/test_game.py +++ b/tests/integration_tests/test_game.py @@ -564,12 +564,12 @@ async def test_galactic_war_1v1_game_ended_broadcasts_army_results(lobby_server, host_proto, [host_id, "Army", 1], [host_id, "Team", 1], - [host_id, "StartSpot", 0], + [host_id, "StartSpot", 1], [host_id, "Faction", 1], [host_id, "Color", 1], [guest_id, "Army", 2], [guest_id, "Team", 2], - [guest_id, "StartSpot", 1], + [guest_id, "StartSpot", 2], [guest_id, "Faction", 2], [guest_id, "Color", 2], ) @@ -637,7 +637,7 @@ async def test_galactic_war_1v1_game_ended_broadcasts_army_results(lobby_server, { "player_id": 3, "army": 2, - "army_result": "DEFEAT", + "army_outcome": "DEFEAT", "metadata": ["recall"], }, ] @@ -649,7 +649,7 @@ async def test_galactic_war_1v1_game_ended_broadcasts_army_results(lobby_server, { "player_id": 1, "army": 1, - "army_result": "VICTORY", + "army_outcome": "VICTORY", "metadata": [], }, ] @@ -692,17 +692,17 @@ async def test_galactic_war_2v1_game_ended_broadcasts_army_results(lobby_server, host_proto, [host_id, "Army", 1], [host_id, "Team", 0], - [host_id, "StartSpot", 0], + [host_id, "StartSpot", 1], [host_id, "Faction", 1], [host_id, "Color", 1], [guest_id, "Army", 2], [guest_id, "Team", 0], - [guest_id, "StartSpot", 1], + [guest_id, "StartSpot", 2], [guest_id, "Faction", 1], [guest_id, "Color", 2], [other_guest_id, "Army", 3], [other_guest_id, "Team", 2], - [other_guest_id, "StartSpot", 2], + [other_guest_id, "StartSpot", 3], [other_guest_id, "Faction", 2], [other_guest_id, "Color", 3], ) @@ -772,13 +772,13 @@ async def test_galactic_war_2v1_game_ended_broadcasts_army_results(lobby_server, { "player_id": 1, "army": 1, - "army_result": "VICTORY", + "army_outcome": "VICTORY", "metadata": [], }, { "player_id": 3, "army": 2, - "army_result": "VICTORY", + "army_outcome": "VICTORY", "metadata": ["recall"], }, ], @@ -790,7 +790,7 @@ async def test_galactic_war_2v1_game_ended_broadcasts_army_results(lobby_server, { "player_id": 6, "army": 3, - "army_result": "DEFEAT", + "army_outcome": "DEFEAT", "metadata": ["recall"], }, ], diff --git a/tests/unit_tests/test_game.py b/tests/unit_tests/test_game.py index 6e30475aa..fe4a47fdf 100644 --- a/tests/unit_tests/test_game.py +++ b/tests/unit_tests/test_game.py @@ -958,7 +958,7 @@ async def test_game_results(game: Game, players): { "player_id": team["player_ids"][0], "army": army, - "army_result": outcome, + "army_outcome": outcome, "metadata": [], } ] @@ -989,13 +989,13 @@ async def test_team_game_results(game: Game, game_add_players): { "player_id": 1, "army": 0, - "army_result": "VICTORY", + "army_outcome": "VICTORY", "metadata": [], }, { "player_id": 2, "army": 1, - "army_result": "DEFEAT", + "army_outcome": "DEFEAT", "metadata": [], }, ] @@ -1004,13 +1004,13 @@ async def test_team_game_results(game: Game, game_add_players): { "player_id": 3, "army": 2, - "army_result": "DEFEAT", + "army_outcome": "DEFEAT", "metadata": [], }, { "player_id": 4, "army": 3, - "army_result": "DEFEAT", + "army_outcome": "DEFEAT", "metadata": [], }, ] @@ -1038,13 +1038,13 @@ async def test_army_results_present_for_invalid_games(game: Game, game_add_playe { "player_id": 1, "army": 0, - "army_result": "VICTORY", + "army_outcome": "VICTORY", "metadata": [], }, { "player_id": 2, "army": 1, - "army_result": "DEFEAT", + "army_outcome": "DEFEAT", "metadata": [], }, ] @@ -1053,13 +1053,13 @@ async def test_army_results_present_for_invalid_games(game: Game, game_add_playe { "player_id": 3, "army": 2, - "army_result": "DEFEAT", + "army_outcome": "DEFEAT", "metadata": [], }, { "player_id": 4, "army": 3, - "army_result": "DEFEAT", + "army_outcome": "DEFEAT", "metadata": [], }, ]