Ejemplo n.º 1
0
async def test_choice_month_no_remained_choices(api_mock, plugin, cco,
                                                choice_data):
    """Show only chosen games if no more choices left."""
    cco.remained_choices = 0
    cco.content_choices_made = ['c']
    cco.content_choices = [
        Mock(**{
            'id': 'a',
            'title': 'A'
        }),
        Mock(**{
            'id': 'b',
            'title': 'B'
        }),
        Mock(**{
            'id': 'c',
            'title': 'C'
        }),
    ]
    cco.extrases = [Mock(**{'machine_name': 'e', 'human_name': 'E'})]
    api_mock.get_choice_content_data = AsyncMock(return_value=choice_data)
    ctx = None
    async for one_month_games in plugin.get_subscription_games(
            'Humble Choice 2020-05', ctx):
        assert one_month_games == [
            SubscriptionGame(game_title='C', game_id='c'),
            SubscriptionGame(game_title='E', game_id='e'),
        ]
    assert plugin._choice_games == {  # cache
        'c': ChoiceGame(id='c', title='C', slug='may-2020', is_extras=False),
        'e': ChoiceGame(id='e', title='E', slug='may-2020', is_extras=True),
    }
Ejemplo n.º 2
0
    async def get_subscription_games(self, subscription_name, context):
        if subscription_name == TROVE_SUBSCRIPTION_NAME:
            async for troves in self._get_trove_games():
                yield troves
            return

        choice_slug = self._choice_name_to_slug(subscription_name)
        choice_data = await self._api.get_choice_content_data(choice_slug)
        cco = choice_data.content_choice_options
        show_all = cco.remained_choices > 0

        choice_games: t.Dict[str, ChoiceGame] = {
            ch.id: ChoiceGame(ch.id, ch.title, choice_slug)
            for ch in cco.content_choices
            if show_all or ch.id in cco.content_choices_made
        }
        choice_games.update({
            extr.machine_name: ChoiceGame(extr.machine_name,
                                          extr.human_name,
                                          choice_slug,
                                          is_extras=True)
            for extr in cco.extrases
        })
        self._choice_games.update(choice_games)
        yield [game.in_galaxy_format() for game in choice_games.values()]
Ejemplo n.º 3
0
async def test_choice_load_from_persistent_cache(plugin):
    plugin.persistent_cache['choice_games'] = '[' \
        '{"id": "c", "title": "C", "slug": "may-2020", "is_extras": false}, ' \
        '{"id": "e", "title": "E", "slug": "may-2020", "is_extras": true}' \
    ']'
    plugin.handshake_complete()
    assert plugin._choice_games == {
        'c': ChoiceGame(id='c', title='C', slug='may-2020', is_extras=False),
        'e': ChoiceGame(id='e', title='E', slug='may-2020', is_extras=True),
    }
Ejemplo n.º 4
0
async def test_choice_store_in_presistent_cache(plugin):
    plugin.push_cache.reset_mock()
    plugin._choice_games = {
        'c': ChoiceGame(id='c', title='C', slug='may-2020', is_extras=False),
        'e': ChoiceGame(id='e', title='E', slug='may-2020', is_extras=True),
    }
    plugin.subscription_games_import_complete()
    assert plugin.persistent_cache['choice_games'] == '[' \
        '{"id": "c", "title": "C", "slug": "may-2020", "is_extras": false}, ' \
        '{"id": "e", "title": "E", "slug": "may-2020", "is_extras": true}' \
    ']'
    plugin.push_cache.assert_called()
Ejemplo n.º 5
0
async def test_install_game_choice(plugin):
    id_ = 'game_id'
    game = ChoiceGame(id_, 'The Game', 'may_2020')
    plugin._choice_games = {id_: game}
    expected_url = 'https://www.humblebundle.com/subscription/may_2020/game_id'
    with patch('webbrowser.open') as browser_open:
        await plugin.install_game(id_)
        browser_open.assert_called_once_with(expected_url)
 def handshake_complete(self):
     self._library_resolver = LibraryResolver(
         api=self._api,
         settings=self._settings.library,
         cache=self._load_cache('library', {}),
         save_cache_callback=partial(self._save_cache, 'library')
     )
     self._last_version = self._load_cache('last_version', default=None)
     self._trove_games = {g['machine_name']: TroveGame(g) for g in self._load_cache('trove_games', [])}
     self._choice_games = {g['id']: ChoiceGame(**g) for g in self._load_cache('choice_games', [])}
Ejemplo n.º 7
0
async def test_install_game_choice_extras(plugin):
    """
    For extrases we just show subscription month url.
    If extras comes from unlocked month, it should be in owned_games as well in form of Key or Subproduct.
    In such case direct download is possible from different game page view.
    """
    id_ = 'game_id'
    game = ChoiceGame(id_, 'The Game DLC1', 'may_2020', is_extras=True)
    plugin._choice_games = {id_: game}
    expected_url = 'https://www.humblebundle.com/subscription/may_2020'
    with patch('webbrowser.open') as browser_open:
        await plugin.install_game(id_)
        browser_open.assert_called_once_with(expected_url)