From 1a049cd5741c8c1df16ecc98e7ce8e47ead9cfa4 Mon Sep 17 00:00:00 2001 From: Mesco Date: Sat, 13 Feb 2021 00:25:28 +0100 Subject: [PATCH] Show tip to disconnect plugin for affected people (#153) --- src/CHANGELOG.md | 6 ++++-- src/plugin.py | 12 ++++++++++++ tests/common/test_opening_options.py | 25 +++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index c386d28f..75d7a8e6 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -1,6 +1,8 @@ -## Unreleased +## Version 0.9.4 +(!) WARNING: If you're Humble subscriber, plugin reconnection is needed to sync subscriptions again (!) + [Fixed] -- Plugin being offline for subscribers +- Plugin being offline for subscribers and no subscriptions shown in Settings->Features #151 ## Version 0.9.3 diff --git a/src/plugin.py b/src/plugin.py index f720e946..1b704a4f 100644 --- a/src/plugin.py +++ b/src/plugin.py @@ -124,6 +124,7 @@ async def _do_auth(self, auth_cookie) -> Authentication: async def authenticate(self, stored_credentials=None): show_news = self.__is_after_minor_update() + just_after_broken_sub_version = self.__is_after_broken_subscriptions_version() # remove after ~04.2021 self._save_cache('last_version', __version__) if not stored_credentials: @@ -137,6 +138,13 @@ async def authenticate(self, stored_credentials=None): logging.info('Stored credentials found') auth: Authentication = await self._do_auth(stored_credentials) + + # To be removed around 04.2021 + # After fixing bug with offline plugin for subscribers (#151), + # reconnection is need to make Galaxy recognize `get_subscriptions` feature again. + if just_after_broken_sub_version and await self._api.had_subscription(): + show_news = True + if show_news: self._open_config(OPTIONS_MODE.NEWS) return auth @@ -148,6 +156,10 @@ async def pass_login_credentials(self, step, credentials, cookies): self._open_config(OPTIONS_MODE.WELCOME) return auth + def __is_after_broken_subscriptions_version(self): + """Returns True once after update from pre 0.9.4""" + return __version__ == '0.9.4' and self._last_version is not None and __version__ != self._last_version + def __is_after_minor_update(self) -> bool: def cut_to_minor(ver: str) -> LooseVersion: """3 part version assumed""" diff --git a/tests/common/test_opening_options.py b/tests/common/test_opening_options.py index 22097b0c..d5eaa1a3 100644 --- a/tests/common/test_opening_options.py +++ b/tests/common/test_opening_options.py @@ -46,3 +46,28 @@ async def test_open_options_on_clicking_install(plugin, delayed_fn): delayed_fn(0.2, plugin.install_game) ) plugin._open_config.assert_called_once() + + +@pytest.mark.asyncio +@pytest.mark.parametrize('had_sub', [True, False]) +@pytest.mark.parametrize('curr_ver, last_ver, proper_versions', [ + ('0.9.4', '0.9.3', True), + ('0.9.4', '0.9.0', True), + ('0.9.4', '0.9.4', False), + ('0.9.5', '0.9.4', False), + ('0.10.5', '0.10.1', False), +]) +async def test_open_news_on_0_9_4_version( + had_sub, curr_ver, last_ver, proper_versions, + api_mock, plugin, auth_cookie, mocker +): + plugin._open_config = MagicMock(spec=()) + api_mock.had_subscription.return_value = had_sub + plugin._last_version = last_ver + mocker.patch('plugin.__version__', curr_ver) + await plugin.authenticate(stored_credentials=auth_cookie) + if proper_versions and had_sub: + plugin._open_config.assert_called_once_with(OPTIONS_MODE.NEWS) + api_mock.had_subscription.assert_called_once() + else: + plugin._open_config.assert_not_called()