コード例 #1
0
async def test_library_settings_key(plugin):
    trove = Mock(spec=TroveGame)
    drm_free = Mock(spec=Subproduct)
    key = Mock(spec=KeyGame)
    type(key).key_val = PropertyMock(return_value='COEO23DN')
    unrevealed_key = Mock(spec=KeyGame)
    type(unrevealed_key).key_val = PropertyMock(return_value=None)

    plugin._owned_games = {
        'a': drm_free,
        'b': trove,
        'c': key,
        'd': unrevealed_key
    }

    ctx = await plugin.prepare_game_library_settings_context(
        ['b', 'c', 'd', 'a'])
    assert await plugin.get_game_library_settings('a',
                                                  ctx) == GameLibrarySettings(
                                                      'a', None, None)
    assert await plugin.get_game_library_settings('b',
                                                  ctx) == GameLibrarySettings(
                                                      'b', ['Trove'], None)
    assert await plugin.get_game_library_settings('c',
                                                  ctx) == GameLibrarySettings(
                                                      'c', ['Key'], None)
    assert await plugin.get_game_library_settings(
        'd', ctx) == GameLibrarySettings('d', ['Key', 'Unrevealed'], None)
コード例 #2
0
 async def get_game_library_settings(self, game_id: str, context: t.Any) -> GameLibrarySettings:
     gls = GameLibrarySettings(game_id, None, None)
     game = self._humble_games[game_id]
     if isinstance(game, Key):
         gls.tags = ['Key']
         if game.key_val is None:
             gls.tags.append('Unrevealed')
     if isinstance(game, TroveGame):
         gls.tags = []  # remove redundant tags since Galaxy support for subscripitons
     return gls
コード例 #3
0
 async def get_game_library_settings(self, game_id: str,
                                     context: Any) -> GameLibrarySettings:
     gls = GameLibrarySettings(game_id, None, None)
     game = self._owned_games[game_id]
     if isinstance(game, Key):
         gls.tags = ['Key']
         if game.key_val is None:
             gls.tags.append('Unrevealed')
     if isinstance(game, TroveGame):
         gls.tags = ['Trove']
     return gls
コード例 #4
0
 async def get_game_library_settings(self, game_id: str,
                                     context: Any) -> GameLibrarySettings:
     if not context:
         # Unable to retrieve context
         return GameLibrarySettings(game_id, None, None)
     game_library_settings = context.get(game_id)
     if game_library_settings is None:
         # Able to retrieve context but game is not in its values -> It doesnt have any tags or hidden status set
         return GameLibrarySettings(game_id, [], False)
     return GameLibrarySettings(
         game_id, ['favorite'] if game_library_settings['favorite'] else [],
         game_library_settings['hidden'])
コード例 #5
0
    async def get_game_library_settings(self, game_id: str, context: Any) -> GameLibrarySettings:
        if not context:
            return GameLibrarySettings(game_id, None, None)
        else:
            game_in_collections = []
            hidden = False
            for collection_name in context:
                if int(game_id) in context[collection_name]:
                    if collection_name.lower() == 'hidden':
                        hidden = True
                    else:
                        game_in_collections.append(collection_name)

            return GameLibrarySettings(game_id, game_in_collections, hidden)
コード例 #6
0
    async def get_game_library_settings(self, game_id: str,
                                        context: Any) -> GameLibrarySettings:
        if not context:
            return GameLibrarySettings(game_id, None, None)
        else:
            game_tags = context.get(game_id)
            if not game_tags:
                return GameLibrarySettings(game_id, [], False)

            hidden = False
            for tag in game_tags:
                if tag.lower() == 'hidden':
                    hidden = True
            if hidden:
                game_tags.remove('hidden')
            return GameLibrarySettings(game_id, game_tags, hidden)
コード例 #7
0
 async def get_game_library_settings(
         self, game_id: GameId,
         context: GameLibrarySettingsContext) -> GameLibrarySettings:
     normalized_id = game_id.strip("@subscription")
     return GameLibrarySettings(
         game_id,
         tags=['favorite'] if normalized_id in context.favorite else [],
         hidden=normalized_id in context.hidden)
コード例 #8
0
 async def get_game_library_settings(self, game_id: str,
                                     context: Any) -> GameLibrarySettings:
     logging.debug("Updating library " + game_id)
     my_current_game_selected = {}
     #call function to update
     for current_game_checking in self.backend.local_game_cache:
         my_escaped_id = escapejson(current_game_checking["hash_digest"])
         if (my_escaped_id == game_id):
             my_current_game_selected = current_game_checking
             break
     game_tags = my_current_game_selected["tags"]
     logging.debug(game_tags)
     game_settings = GameLibrarySettings(game_id, game_tags, False)
     return game_settings
コード例 #9
0
async def test_get_game_library_settings_subscription_external_type(
    authenticated_plugin, ):
    """ 
    The privacy settings Origin API is inconsistent about externalType:
    - for subscription games offerIds are listed in the payload without @subscription suffix
    - for other `externalType`s id full id is listed e.g. OFR:22@epic
    """
    game_ids = ["OFR:123@subscription", "OFR:001@steam"]
    context = GameLibrarySettingsContext(
        favorite=set(["OFR:123", "OFR:001@steam"]),
        hidden=set(["OFR:123", "OFR:001@steam"]))

    tags, hidden = ['favorite'], True
    for game_id in game_ids:
        assert GameLibrarySettings(
            game_id, tags,
            hidden) == await authenticated_plugin.get_game_library_settings(
                game_id, context)
コード例 #10
0
async def test_get_game_time_success(plugin, read, write):
    plugin.prepare_game_library_settings_context.return_value = async_return_value(
        "abc")
    request = {
        "jsonrpc": "2.0",
        "id": "3",
        "method": "start_game_library_settings_import",
        "params": {
            "game_ids": ["3", "5", "7"]
        }
    }
    read.side_effect = [
        async_return_value(create_message(request)),
        async_return_value(b"", 10)
    ]
    plugin.get_game_library_settings.side_effect = [
        async_return_value(GameLibrarySettings("3", None, True)),
        async_return_value(GameLibrarySettings("5", [], False)),
        async_return_value(
            GameLibrarySettings("7", ["tag1", "tag2", "tag3"], None)),
    ]
    await plugin.run()
    plugin.get_game_library_settings.assert_has_calls([
        call("3", "abc"),
        call("5", "abc"),
        call("7", "abc"),
    ])
    plugin.game_library_settings_import_complete.assert_called_once_with()

    assert get_messages(write) == [{
        "jsonrpc": "2.0",
        "id": "3",
        "result": None
    }, {
        "jsonrpc": "2.0",
        "method": "game_library_settings_import_success",
        "params": {
            "game_library_settings": {
                "game_id": "3",
                "hidden": True
            }
        }
    }, {
        "jsonrpc": "2.0",
        "method": "game_library_settings_import_success",
        "params": {
            "game_library_settings": {
                "game_id": "5",
                "tags": [],
                "hidden": False
            }
        }
    }, {
        "jsonrpc": "2.0",
        "method": "game_library_settings_import_success",
        "params": {
            "game_library_settings": {
                "game_id": "7",
                "tags": ["tag1", "tag2", "tag3"]
            }
        }
    }, {
        "jsonrpc": "2.0",
        "method": "game_library_settings_import_finished",
        "params": None
    }]
コード例 #11
0
async def test_get_game_library_settings(authenticated_plugin, game_id, hidden,
                                         favorite, game_library_context):
    tags = ['favorite'] if favorite else []
    result = await authenticated_plugin.get_game_library_settings(
        game_id, game_library_context)
    assert result == GameLibrarySettings(game_id, tags, hidden)
コード例 #12
0
    },
    'OFB-EAST:109552409': {
        'hidden': True,
        'favorite': True
    },
    'DR:119971300': {
        'hidden': False,
        'favorite': True
    },
    'Origin.OFR.50.0002694': {
        'hidden': True,
        'favorite': False
    }
}

GAME_LIBRARY_SETTINGS = GameLibrarySettings('OFB-EAST:48217', ['favorite'], False)


@pytest.mark.asyncio
async def test_not_authenticated(plugin, http_client):
    http_client.is_authenticated.return_value = False
    with pytest.raises(AuthenticationRequired):
        await plugin.prepare_game_library_settings_context([])


@pytest.mark.asyncio
async def test_prepare_library_settings_context(
        authenticated_plugin,
        backend_client,
        user_id,