From ad758b0da98c2872b70e9821ed40f14cfdb48f85 Mon Sep 17 00:00:00 2001 From: Mateusz Silaczewski Date: Mon, 23 Mar 2020 10:15:24 +0100 Subject: [PATCH] subscription settings --- setup.py | 2 +- src/galaxy/api/consts.py | 10 ++++++++++ src/galaxy/api/types.py | 14 +++++++++++++- tests/test_subscriptions.py | 15 ++++++++++----- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 08d47c1..45a616b 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name="galaxy.plugin.api", - version="0.64", + version="0.65", description="GOG Galaxy Integrations Python API", author='Galaxy team', author_email='galaxy@gog.com', diff --git a/src/galaxy/api/consts.py b/src/galaxy/api/consts.py index 4902603..e29eb98 100644 --- a/src/galaxy/api/consts.py +++ b/src/galaxy/api/consts.py @@ -152,3 +152,13 @@ class PresenceState(Enum): Online = "online" Offline = "offline" Away = "away" + + +class SubscriptionDiscovery(Flag): + """Possible capabilities which inform what methods of subscriptions ownership detection are supported. + + :param AUTOMATIC: integration can retrieve the proper status of subscription ownership. + :param USER_ENABLED: integration can handle override of ~class::`Subscription.owned` value to True + """ + AUTOMATIC = 1 + USER_ENABLED = 2 diff --git a/src/galaxy/api/types.py b/src/galaxy/api/types.py index 75fcd1c..7fd0031 100644 --- a/src/galaxy/api/types.py +++ b/src/galaxy/api/types.py @@ -1,7 +1,7 @@ from dataclasses import dataclass from typing import Dict, List, Optional -from galaxy.api.consts import LicenseType, LocalGameState, PresenceState +from galaxy.api.consts import LicenseType, LocalGameState, PresenceState, SubscriptionDiscovery @dataclass @@ -217,6 +217,7 @@ class UserPresence: in_game_status: Optional[str] = None full_status: Optional[str] = None + @dataclass class Subscription: """Information about a subscription. @@ -224,10 +225,21 @@ class Subscription: :param subscription_name: name of the subscription, will also be used as its identifier. :param owned: whether the subscription is owned or not, None if unknown. :param end_time: unix timestamp of when the subscription ends, None if unknown. + :param subscription_discovery: combination of settings that can be manually + chosen by user to determine subscription handling behaviour. For example, if the integration cannot retrieve games + for subscription when user doesn't own it, then USER_ENABLED should not be used. + If the integration cannot determine subscription ownership for a user then AUTOMATIC should not be used. + """ subscription_name: str owned: Optional[bool] = None end_time: Optional[int] = None + subscription_discovery: SubscriptionDiscovery = SubscriptionDiscovery.AUTOMATIC | \ + SubscriptionDiscovery.USER_ENABLED + + def __post_init__(self): + assert self.subscription_discovery in [SubscriptionDiscovery.AUTOMATIC, SubscriptionDiscovery.USER_ENABLED, + SubscriptionDiscovery.AUTOMATIC | SubscriptionDiscovery.USER_ENABLED] @dataclass diff --git a/tests/test_subscriptions.py b/tests/test_subscriptions.py index 368965b..474c722 100644 --- a/tests/test_subscriptions.py +++ b/tests/test_subscriptions.py @@ -1,6 +1,7 @@ import pytest from galaxy.api.types import Subscription, SubscriptionGame +from galaxy.api.consts import SubscriptionDiscovery from galaxy.api.errors import FailedParsingManifest, BackendError, UnknownError from galaxy.unittest.mock import async_return_value @@ -17,8 +18,8 @@ async def test_get_subscriptions_success(plugin, read, write): plugin.get_subscriptions.return_value = async_return_value([ Subscription("1"), - Subscription("2", False), - Subscription("3", True, 1580899100) + Subscription("2", False, subscription_discovery=SubscriptionDiscovery.AUTOMATIC), + Subscription("3", True, 1580899100, SubscriptionDiscovery.USER_ENABLED) ]) await plugin.run() plugin.get_subscriptions.assert_called_with() @@ -30,16 +31,19 @@ async def test_get_subscriptions_success(plugin, read, write): "result": { "subscriptions": [ { - "subscription_name": "1" + "subscription_name": "1", + 'subscription_discovery': 3 }, { "subscription_name": "2", - "owned": False + "owned": False, + 'subscription_discovery': 1 }, { "subscription_name": "3", "owned": True, - "end_time": 1580899100 + "end_time": 1580899100, + 'subscription_discovery': 2 } ] } @@ -77,6 +81,7 @@ async def test_get_subscriptions_failure_generic(plugin, read, write, error, cod } ] + @pytest.mark.asyncio async def test_get_subscription_games_success(plugin, read, write): plugin.prepare_subscription_games_context.return_value = async_return_value(5)