async def test_handle_action_OperationComplete_invalid( ugame: Game, game_connection: GameConnection, database): """ Sends an OperationComplete action to handle action and verifies that the `coop_leaderboard` table is updated accordingly. Requires that the map from `game.map_file_path` exists in the database. """ ugame.map_file_path = "maps/prothyon16.v0005.zip" ugame.validity = ValidityState.OTHER_UNRANK game_connection.game = ugame secondary = 1 time_taken = '09:08:07.654321' await game_connection.handle_action('OperationComplete', ['1', secondary, time_taken]) async with database.acquire() as conn: result = await conn.execute( "SELECT secondary, gameuid from `coop_leaderboard` where gameuid=%s", ugame.id) row = await result.fetchone() assert row is None
async def test_abort(game_connection: GameConnection, game: Game, players): game_connection.player = players.hosting game_connection.game = game await game_connection.abort() game.remove_game_connection.assert_called_with(game_connection)
async def test_disconnect_all_peers(game_connection: GameConnection, real_game: Game, players): real_game.state = GameState.LOBBY game_connection.player = players.hosting game_connection.game = real_game disconnect_done = mock.Mock() async def fake_send_dc(player_id): await asyncio.sleep(1) # Take some time disconnect_done.success() return "OK" # Set up a peer that will disconnect without error ok_disconnect = asynctest.create_autospec(GameConnection) ok_disconnect.state = GameConnectionState.CONNECTED_TO_HOST ok_disconnect.send_DisconnectFromPeer = fake_send_dc # Set up a peer that will throw an exception fail_disconnect = asynctest.create_autospec(GameConnection) fail_disconnect.send_DisconnectFromPeer.return_value = Exception( "Test exception") fail_disconnect.state = GameConnectionState.CONNECTED_TO_HOST # Add the peers to the game real_game.add_game_connection(fail_disconnect) real_game.add_game_connection(ok_disconnect) await game_connection.disconnect_all_peers() disconnect_done.success.assert_called_once()
async def test_handle_action_GameState_launching_calls_launch(game_connection: GameConnection, players, game): game_connection.player = players.hosting game_connection.game = game game.launch = CoroMock() await game_connection.handle_action('GameState', ['Launching']) game.launch.assert_any_call()
async def test_handle_action_GameState_launching_calls_launch( game_connection: GameConnection, players, game): game_connection.player = players.hosting game_connection.game = game game.launch = CoroMock() await game_connection.handle_action('GameState', ['Launching']) game.launch.assert_any_call()
async def test_handle_action_GameState_idle_adds_connection( game: Game, game_connection: GameConnection, players): players.joining.game = game game_connection.player = players.hosting game_connection.game = game await game_connection.handle_action('GameState', ['Idle']) game.add_game_connection.assert_called_with(game_connection)
async def test_handle_action_GameState_launching_calls_launch( game: Game, game_connection: GameConnection, players): game_connection.player = players.hosting game_connection.game = game game.launch = CoroutineMock() await game_connection.handle_action("GameState", ["Launching"]) game.launch.assert_any_call()
def make_connection(player, connectivity): lc = LobbyConnection(loop) lc.protocol = mock.Mock() conn = GameConnection(loop=loop, lobby_connection=lc, player_service=player_service, games=game_service) conn.player = player conn.game = game conn._transport = transport conn._connectivity_state.set_result(connectivity) return conn
async def test_handle_lobby_state_handles_GameError( real_game: Game, game_connection: GameConnection, event_loop, players): game_connection.abort = CoroutineMock() game_connection.connect_to_host = CoroutineMock() game_connection.player = players.joining game_connection.game = real_game players.joining.game = real_game real_game.host = players.hosting real_game.state = GameState.ENDED await game_connection.handle_action('GameState', ['Lobby']) await exhaust_callbacks(event_loop) game_connection.abort.assert_called_once()
def game_connection(request, game, loop, player_service, players, game_service, transport): from server import GameConnection, LobbyConnection conn = GameConnection(loop=loop, lobby_connection=mock.create_autospec(LobbyConnection(loop)), player_service=player_service, games=game_service) conn._transport = transport conn.player = players.hosting conn.game = game conn.lobby = mock.Mock(spec=LobbyConnection) def fin(): conn.abort() request.addfinalizer(fin) return conn
def game_connection(request, game, loop, player_service, players, game_service, transport): from server import GameConnection, LobbyConnection conn = GameConnection(loop=loop, lobby_connection=mock.create_autospec( LobbyConnection(loop)), player_service=player_service, games=game_service) conn._transport = transport conn.player = players.hosting conn.game = game conn.lobby = mock.Mock(spec=LobbyConnection) def fin(): conn.abort() request.addfinalizer(fin) return conn