def test_update_user_ready(cache, added_handler, updated_handler):
    user_id = 1423
    expected_user_info = UserInfo(name="Jan", state=EPersonaState.Offline)
    cache.add(user_id)
    cache.update(user_id, UserInfo(name="Jan"))
    cache.update(user_id, UserInfo(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()
def test_reset_mixed(cache, removed_handler):
    cache.add(15)
    cache.update(15, UserInfo(name="Jan", state=EPersonaState.Offline))

    cache.add(17)
    cache.update(17, UserInfo(name="Ula", state=EPersonaState.Offline))

    cache.reset([17, 29])
    removed_handler.assert_called_once_with(15)
    assert not cache.ready
async def test_get_friends_info(client, friends_cache):
    friends_cache.wait_ready.return_value = async_return_value(None)
    friends_cache.get.side_effect = [
        UserInfo("Franek"), None, UserInfo("Janek")
    ]
    assert await client.get_friends_info(["1", "5", "7"]) == {
        "1": UserInfo("Franek"),
        "7": UserInfo("Janek")
    }
    friends_cache.wait_ready.assert_called_once_with()
    friends_cache.get.assert_has_calls([call(1), call(5), call(7)])
    async def _process_client_persona_state(self, body):
        logger.debug("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 = UserInfo()
            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
                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, UserInfo())]
    added_handler.assert_not_called()
def test_remove_ready_user(cache, removed_handler):
    user_id = 1423
    user_info = UserInfo(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 = UserInfo("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_user_info(client, protobuf_client, friends_cache):
    user_id = 15
    user_info = UserInfo("Ola")
    await protobuf_client.user_info_handler(user_id, user_info)
    friends_cache.update.assert_called_once_with(user_id, user_info)
import pytest

from protocol.consts import EPersonaState
from protocol.types import UserInfo
from presence import from_user_info

from galaxy.api.errors import AuthenticationRequired, UnknownError
from galaxy.api.consts import PresenceState
from galaxy.api.types import UserPresence


@pytest.mark.parametrize(
    "user_info,user_presence",
    [
        # Empty
        (UserInfo(), UserPresence(presence_state=PresenceState.Unknown)),
        # Offline
        (UserInfo(state=EPersonaState.Offline),
         UserPresence(presence_state=PresenceState.Offline)),
        # User online not playing a game
        (UserInfo(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
        (UserInfo(state=EPersonaState.Online,
                  game_id=1512,
Пример #10
0
 def _add(self, user_id):
     if user_id in self._info_map:
         return
     self._pending_map[user_id] = AvailableInfo()
     self._info_map[user_id] = UserInfo()
import pytest

from protocol.consts import EPersonaState
from protocol.types import UserInfo
from presence import from_user_info

from galaxy.api.errors import AuthenticationRequired, UnknownError
from galaxy.api.consts import PresenceState
from galaxy.api.types import UserPresence


@pytest.mark.parametrize(
    "user_info,user_presence",
    [
        # Empty
        (UserInfo(), UserPresence(presence_state=PresenceState.Unknown)),
        # Offline
        (UserInfo(state=EPersonaState.Offline),
         UserPresence(presence_state=PresenceState.Offline)),
        # User online not playing a game
        (UserInfo(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
        (UserInfo(state=EPersonaState.Online,
                  game_id=1512,