async def test_on_game_session_updated(preset_manager, skip_qtbot): # Setup network_client = MagicMock() network_client.current_user = User(id=12, name="Player A") network_client.session_self_update = AsyncMock() game_connection = MagicMock() game_connection.pretty_current_status = "Maybe Connected" game_connection.backend.lock_identifier = None initial_session = GameSessionEntry( id=1234, name="The Session", presets=[preset_manager.default_preset, preset_manager.default_preset], players={ 12: PlayerSessionEntry(12, "Player A", 0, True, "Online"), }, actions=[], seed_hash=None, word_hash=None, spoiler=None, permalink=None, state=GameSessionState.SETUP, generation_in_progress=None, ) second_session = GameSessionEntry( id=1234, name="The Session", presets=[preset_manager.default_preset], players={ 12: PlayerSessionEntry(12, "Player A", 0, True, "Online"), 24: PlayerSessionEntry(24, "Player B", None, False, "Online"), }, actions=[ GameSessionAction("Hello", datetime.datetime(year=2020, month=1, day=5)) ], seed_hash="AB12", word_hash="Chykka Required", spoiler=True, permalink="<permalink>", state=GameSessionState.IN_PROGRESS, generation_in_progress=None, ) network_client.current_game_session = initial_session window = await GameSessionWindow.create_and_update(network_client, game_connection, preset_manager, MagicMock(), MagicMock()) window.update_multiworld_client_status = AsyncMock() # Run await window.on_game_session_updated(second_session) window.update_multiworld_client_status.assert_awaited() network_client.session_self_update.assert_awaited_once_with( game_connection.get_current_inventory.return_value, game_connection.current_status, game_connection.backend.backend_choice, )
async def test_on_game_session_meta_update(preset_manager, skip_qtbot): # Setup network_client = MagicMock() network_client.current_user = User(id=12, name="Player A") network_client.session_self_update = AsyncMock() game_connection = MagicMock(spec=GameConnection) game_connection.executor = AsyncMock() game_connection.pretty_current_status = "Maybe Connected" game_connection.lock_identifier = None initial_session = GameSessionEntry( id=1234, name="The Session", presets=[ preset_manager.default_preset_for_game( RandovaniaGame.METROID_PRIME_ECHOES), preset_manager.default_preset ], players={ 12: PlayerSessionEntry(12, "Player A", 0, True, "Online"), }, game_details=None, state=GameSessionState.SETUP, generation_in_progress=None, allowed_games=[RandovaniaGame.METROID_PRIME_ECHOES], ) second_session = GameSessionEntry( id=1234, name="The Session", presets=[ preset_manager.default_preset_for_game( RandovaniaGame.METROID_PRIME_ECHOES) ], players={ 12: PlayerSessionEntry(12, "Player A", 0, True, "Online"), 24: PlayerSessionEntry(24, "Player B", None, False, "Online"), }, game_details=GameDetails( seed_hash="AB12", word_hash="Chykka Required", spoiler=True, ), state=GameSessionState.IN_PROGRESS, generation_in_progress=None, allowed_games=[RandovaniaGame.METROID_PRIME_ECHOES], ) network_client.current_game_session = initial_session window = await GameSessionWindow.create_and_update(network_client, game_connection, preset_manager, MagicMock(), MagicMock()) window.update_multiworld_client_status = AsyncMock() skip_qtbot.addWidget(window) # Run await window.on_game_session_meta_update(second_session) window.update_multiworld_client_status.assert_awaited() network_client.session_self_update.assert_awaited_once_with( game_connection.get_current_inventory.return_value, game_connection.current_status, game_connection.backend_choice, )