def test_reset_mixed(cache, removed_handler): cache.add(15) cache.update(15, ProtoUserInfo(name="Jan", state=EPersonaState.Offline)) cache.add(17) cache.update(17, ProtoUserInfo(name="Ula", state=EPersonaState.Offline)) cache.reset([17, 29]) removed_handler.assert_called_once_with(15) assert not cache.ready
def test_update_user_ready(cache, added_handler, updated_handler): user_id = 1423 expected_user_info = ProtoUserInfo(name="Jan", state=EPersonaState.Offline) cache.add(user_id) cache.update(user_id, ProtoUserInfo(name="Jan")) cache.update(user_id, ProtoUserInfo(state=EPersonaState.Offline)) assert cache.ready assert list(cache) == [(user_id, expected_user_info)] added_handler.assert_called_with(user_id, expected_user_info) updated_handler.assert_not_called()
async def _process_client_persona_state(self, body): logger.info("Processing message ClientPersonaState") if self.user_info_handler is None: return message = steammessages_clientserver_friends_pb2.CMsgClientPersonaState() message.ParseFromString(body) for user in message.friends: user_id = user.friendid if user_id == self.steam_id and int(user.game_played_app_id) != 0: await self.get_apps_info([int(user.game_played_app_id)]) user_info = ProtoUserInfo() if user.HasField("player_name"): user_info.name = user.player_name if user.HasField("avatar_hash"): user_info.avatar_hash = user.avatar_hash if user.HasField("persona_state"): user_info.state = EPersonaState(user.persona_state) if user.HasField("gameid"): user_info.game_id = user.gameid rich_presence: Dict[str, str] = {} for element in user.rich_presence: rich_presence[element.key] = element.value if element.key == 'status' and element.value: if "#" in element.value: await self.translations_handler(user.gameid) if element.key == 'steam_display' and element.value: if "#" in element.value: await self.translations_handler(user.gameid) user_info.rich_presence = rich_presence if user.HasField("game_name"): user_info.game_name = user.game_name await self.user_info_handler(user_id, user_info)
def test_add_user(cache, added_handler): user_id = 1423 cache.add(user_id) assert not cache.ready assert user_id in cache assert list(cache) == [(user_id, ProtoUserInfo())] added_handler.assert_not_called()
def test_remove_ready_user(cache, removed_handler): user_id = 1423 user_info = ProtoUserInfo(name="Jan", state=EPersonaState.Offline) cache.add(user_id) cache.update(user_id, user_info) cache.remove(user_id) assert list(cache) == [] removed_handler.assert_called_once_with(user_id)
def test_update_user_not_ready(cache, added_handler, updated_handler): user_id = 1423 user_info = ProtoUserInfo("Jan") cache.add(user_id) cache.update(user_id, user_info) assert not cache.ready assert list(cache) == [(user_id, user_info)] added_handler.assert_not_called() updated_handler.assert_not_called()
async def test_update_user_all_data(cache, added_handler, updated_handler): user_id = 1423 user_info = ProtoUserInfo(name="Jan", state=EPersonaState.Offline) cache.add(user_id) await cache.update(user_id, user_info) assert cache.ready assert list(cache) == [(user_id, user_info)] added_handler.assert_called_with(user_id, user_info) updated_handler.assert_not_called()
async def test_multiple_friends_with_nicknames(authenticated_plugin, steam_client): ids = ["76561198040630463", "76561198053830887"] steam_client.get_friends.return_value = ids steam_client.get_friends_info.return_value = { '76561198040630463': ProtoUserInfo( name='Test1', avatar_hash= b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', state=EPersonaState.Invisible, game_id=0, game_name='', rich_presence={}), '76561198053830887': ProtoUserInfo( name='Test2', avatar_hash= b'\x22\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11', state=None, game_id=None, game_name=None, rich_presence=None) } steam_client.get_friends_nicknames.return_value = { '76561198053830887': 'nickname' } result = await authenticated_plugin.get_friends() assert result == [ UserInfo( "76561198040630463", "Test1", "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/fe/fef49e7fa7e1997310d705b2a6158ff8dc1cdfeb_full.jpg", "https://steamcommunity.com/profiles/76561198040630463"), UserInfo( "76561198053830887", "Test2 (nickname)", "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/22/2200000000000000000000000000000000000011_full.jpg", "https://steamcommunity.com/profiles/76561198053830887") ] steam_client.get_friends_info.assert_called_once_with(ids)
async def test_user_info(client, protobuf_client, friends_cache): user_id = 15 user_info = ProtoUserInfo("Ola") await protobuf_client.user_info_handler(user_id, user_info) friends_cache.update.assert_called_once_with(user_id, user_info)
def _add(self, user_id): if user_id in self._info_map: return self._pending_map[user_id] = AvailableInfo() self._info_map[user_id] = ProtoUserInfo()
@dataclass class token_translations_parametrized_mock_dataclass_EN: name = "#EN" value = "_english" @dataclass class translations_cache_parametrized_mock_dataclass: tokens = [token_translations_parametrized_mock_dataclass_menu(), token_translations_parametrized_mock_dataclass_EN()] @pytest.mark.parametrize( "user_info,user_presence", [ # Empty ( ProtoUserInfo(), UserPresence(presence_state=PresenceState.Unknown) ), # Offline ( ProtoUserInfo(state=EPersonaState.Offline), UserPresence(presence_state=PresenceState.Offline) ), # User online not playing a game ( ProtoUserInfo(state=EPersonaState.Online, game_id=0, game_name="", rich_presence={}), UserPresence(presence_state=PresenceState.Online, game_id=None, game_title=None, in_game_status=None) ), # User online playing a game ( ProtoUserInfo(state=EPersonaState.Online, game_id=1512, game_name="abc", rich_presence={"status": "menu"}),
value = "english" @dataclass class translations_cache_parametrized_mock_dataclass: tokens = [ token_translations_parametrized_mock_dataclass_menu(), token_translations_parametrized_mock_dataclass_EN() ] @pytest.mark.parametrize( "user_info,user_presence", [ # Empty (ProtoUserInfo(), UserPresence(presence_state=PresenceState.Unknown)), # Offline (ProtoUserInfo(state=EPersonaState.Offline), UserPresence(presence_state=PresenceState.Offline)), # User online not playing a game (ProtoUserInfo(state=EPersonaState.Online, game_id=0, game_name="", rich_presence={}), UserPresence(presence_state=PresenceState.Online, game_id=None, game_title=None, in_game_status=None)), # User online playing a game (ProtoUserInfo(state=EPersonaState.Online, game_id=1512,
class translations_cache_parametrized_mock_dataclass: tokens = [TOKEN("#menu", "translated_menu{%param0%}"), TOKEN("#EN", "english")] @dataclass class translations_cache_values_fitting_partially_dataclass: tokens = [TOKEN("#PlayingAs", "Playing %Empire% (%Ethics1% %Ethics2%) in %Year%"), TOKEN("#PlayingAsNew", "Playing %Empire% (%Ethics%) in %Year%"), TOKEN("#PlayingAsNoEthics", "Playing %Empire% in %Year%")] @pytest.mark.parametrize( "user_info,user_presence", [ # Empty ( ProtoUserInfo(), UserPresence(presence_state=PresenceState.Unknown) ), # Offline ( ProtoUserInfo(state=EPersonaState.Offline), UserPresence(presence_state=PresenceState.Offline) ), # User online not playing a game ( ProtoUserInfo(state=EPersonaState.Online, game_id=0, game_name="", rich_presence={}), UserPresence(presence_state=PresenceState.Online, game_id=None, game_title=None, in_game_status=None) ), # User online playing a game ( ProtoUserInfo(state=EPersonaState.Online, game_id=1512, game_name="abc", rich_presence={"status": "menu"}),