Beispiel #1
0
async def test_get_subscriptions_current_month_not_unlocked_yet(
        current_subscription_plan, current_month_owned, trove_owned, api_mock,
        plugin_with_sub):
    """
    Technically only unlocked choice months are owned (locked are not already payed and can be canceled).
    But for user convenience plugin marks month as owned if it *is going to* be unloacked (if not cancelled untill last Friday).
    Without this, Galaxy won't display games until user manualy select current month as owned.
    This would be annoying as, as new subscription month happen... well every month.
    ---
    Test checks also logic for Trove ownership base on subscription status.
    """
    api_mock.had_subscription.return_value = True
    api_mock.get_choice_content_data.return_value = Mock(
        user_subscription_plan=current_subscription_plan)
    content_choice_options = [{
        'contentChoiceData': Mock(dict),
        'gamekey': Mock(str),
        'productMachineName': 'april_2020_choice',
        'isActiveContent': False
    }]
    api_mock.get_subscription_products_with_gamekeys = MagicMock(
        return_value=aiter(content_choice_options))
    res = await plugin_with_sub.get_subscriptions()
    assert sorted(res, key=lambda x: x.subscription_name) == [
        Subscription(
            "Humble Choice 2020-04", owned=True
        ),  # came from api - we're sure that choice month was unlocked
        Subscription("Humble Choice 2020-05", owned=current_month_owned),
        Subscription("Humble Trove", owned=trove_owned),
    ]
Beispiel #2
0
async def test_get_subscriptions_past_subscriber(api_mock, plugin_with_sub):
    """
    Testcase: Currently no subscriptiion but user was subscriber in the past
    Expected: Active subscription months + not owned Trove & and owned active month
    """
    api_mock.had_subscription.return_value = True
    api_mock.get_choice_content_data.return_value = Mock(
        **{'user_subscription_plan': None})
    content_choice_options = [
        {
            'contentChoiceData': Mock(dict),
            'gamekey': Mock(str),
            'productMachineName': 'march_2020_choice',
            'isActiveContent': False
        },
        {
            'contentChoiceData': Mock(dict),
            'gamekey': Mock(str),
            'productMachineName': 'february_2020_choice',
            'isActiveContent': False
        },
    ]
    api_mock.get_subscription_products_with_gamekeys = MagicMock(
        return_value=aiter(content_choice_options))

    res = await plugin_with_sub.get_subscriptions()
    assert sorted(res, key=lambda x: x.subscription_name) == [
        Subscription("Humble Choice 2020-02", owned=True),
        Subscription("Humble Choice 2020-03", owned=True),
        Subscription("Humble Choice 2020-05", owned=False),
        Subscription("Humble Trove", owned=False),
    ]
async def test_get_subscription_games_trove(api_mock, plugin):
    parsed_from_page = {
        'newlyAdded': [
            {
                'human-name': 'A',
                'machine_name': 'a'
            },
            {
                'human-name': 'Z',
                'machine_name': 'z'
            },
        ]
    }
    api_mock.get_montly_trove_data.return_value = parsed_from_page
    chunks_from_api = [
        [
            {
                'human-name': 'A',
                'machine_name': 'a'
            },
            {
                'human-name': 'B',
                'machine_name': 'b'
            },
        ],
        [
            {
                'human-name': 'C',
                'machine_name': 'c'
            },
            {
                'human-name': 'D',
                'machine_name': 'd'
            },
        ],
        [
            {
                'human-name': 'E',
                'machine_name': 'e'
            },
        ],
    ]
    api_mock.get_trove_details = MagicMock(return_value=aiter(chunks_from_api))
    ctx = None
    trove_games = []
    async for bunch in plugin.get_subscription_games('Humble Trove', ctx):
        trove_games.extend(bunch)
    assert sorted(trove_games, key=lambda x: x.game_id) \
        == sorted([
            SubscriptionGame(game_title='A', game_id='a'),
            SubscriptionGame('B', 'b'),
            SubscriptionGame('C', 'c'),
            SubscriptionGame('D', 'd'),
            SubscriptionGame('E', 'e'),
            SubscriptionGame('Z', 'z'),
            SubscriptionGame('A', 'a')  # don't mind returning 2 times the same item
        ], key=lambda x: x.game_id)
Beispiel #4
0
async def test_get_subscriptions_multiple_where_one_paused(
        api_mock, plugin_with_sub):
    api_mock.had_subscription.return_value = True
    content_choice_options = [
        {
            'contentChoiceData': Mock(dict),
            'gamekey': Mock(str),
            'productMachineName': 'may_2020_choice',
            'isActiveContent': True
        },
        {
            'contentChoiceData': Mock(dict),
            'gamekey': Mock(str),
            'productMachineName': 'april_2020_choice',
            'isActiveContent': False
        },
        {
            'contentChoiceData': Mock(dict),
            'productMachineName': 'march_2020_choice',
            'isActiveContent': False
        },  # paused month
        {
            'contentChoiceData': Mock(dict),
            'gamekey': Mock(str),
            'productMachineName': 'february_2020_choice',
            'isActiveContent': False
        },
        {
            'contentChoiceData': Mock(dict),
            'gamekey': Mock(str),
            'productMachineName': 'january_2020_choice',
            'isActiveContent': False
        },
        {
            'contentChoiceData': Mock(dict),
            'gamekey': Mock(str),
            'productMachineName': 'december_2019_choice',
            'isActiveContent': False
        },
    ]
    api_mock.get_subscription_products_with_gamekeys = MagicMock(
        return_value=aiter(content_choice_options))

    res = await plugin_with_sub.get_subscriptions()
    assert sorted(res, key=lambda x: x.subscription_name) == [
        Subscription("Humble Choice 2019-12", owned=True),
        Subscription("Humble Choice 2020-01", owned=True),
        Subscription("Humble Choice 2020-02", owned=True),
        Subscription("Humble Choice 2020-03", owned=False),  # paused month
        Subscription("Humble Choice 2020-04", owned=True),
        Subscription("Humble Choice 2020-05", owned=True),
        Subscription("Humble Trove", owned=True),
    ]
async def test_subscription_games_cache_trove(api_mock, plugin):
    parsed_from_page = {
        'newlyAdded': [{
            'human-name': 'Z',
            'machine_name': 'z'
        }]
    }
    api_mock.get_montly_trove_data.return_value = parsed_from_page
    chunks_from_api = [
        [
            {
                'human-name': 'A',
                'machine_name': 'a'
            },
            {
                'human-name': 'B',
                'machine_name': 'b'
            },
        ],
        [
            {
                'human-name': 'C',
                'machine_name': 'c'
            },
        ],
    ]
    api_mock.get_trove_details = MagicMock(return_value=aiter(chunks_from_api))
    ctx = None
    async for bunch in plugin.get_subscription_games('Humble Trove', ctx):
        pass
    assert plugin._trove_games == {
        'a': TroveGame({
            'human-name': 'A',
            'machine_name': 'a'
        }),
        'b': TroveGame({
            'human-name': 'B',
            'machine_name': 'b'
        }),
        'c': TroveGame({
            'human-name': 'C',
            'machine_name': 'c'
        }),
        'z': TroveGame({
            'human-name': 'Z',
            'machine_name': 'z'
        }),
    }
Beispiel #6
0
async def test_get_subscriptions_subscriber_all_from_api(
        api_mock, plugin_with_sub):
    api_mock.had_subscription.return_value = True
    content_choice_options = [
        Mock(**{
            'product_machine_name': 'may_2020_choice',
            'is_active_content': True
        }),
        Mock(
            **{
                'product_machine_name': 'april_2020_choice',
                'is_active_content': False
            }),
        Mock(
            **{
                'product_machine_name': 'march_2020_choice',
                'is_active_content': False
            }),
        Mock(
            **{
                'product_machine_name': 'february_2020_choice',
                'is_active_content': False
            }),
        Mock(
            **{
                'product_machine_name': 'january_2020_choice',
                'is_active_content': False
            }),
        Mock(
            **{
                'product_machine_name': 'december_2019_choice',
                'is_active_content': False
            }),
    ]
    api_mock.get_subscription_products_with_gamekeys = MagicMock(
        return_value=aiter(content_choice_options))

    res = await plugin_with_sub.get_subscriptions()
    assert sorted(res, key=lambda x: x.subscription_name) == [
        Subscription("Humble Choice 2019-12", owned=True),
        Subscription("Humble Choice 2020-01", owned=True),
        Subscription("Humble Choice 2020-02", owned=True),
        Subscription("Humble Choice 2020-03", owned=True),
        Subscription("Humble Choice 2020-04", owned=True),
        Subscription("Humble Choice 2020-05", owned=True),
        Subscription("Humble Trove", owned=True),
    ]
Beispiel #7
0
async def test_get_subscriptions_humble_choice_and_humble_monthly(
        api_mock, plugin_with_sub):
    """
    The subscription_products_with_gamekeys API returns firstly Choice months data, then old Humble Monthly subscription data.
    Expected: Plugin should ignore Humble Montly subscription months.
    """
    api_mock.had_subscription.return_value = True
    content_choice_options = [
        {
            'contentChoiceData': Mock(dict),
            'gamekey': Mock(str),
            'productMachineName': 'january_2020_choice',
            'isActiveContent': True
        },
        {
            'contentChoiceData': Mock(dict),
            'gamekey': Mock(str),
            'productMachineName': 'december_2019_choice',
            'isActiveContent': False
        },
        {
            'machine_name': 'december_2019_monthly',
            'order_url': '/downloads?key=b6BVmZ4AuvPwfa3S',
            'short_human_name': 'December 2019'
        },  # subscribed
        {
            'machine_name': 'november_2019_monthly',
            'order_url': None,
            'short_human_name': 'November 2019'
        },  # not subscribed
    ]
    api_mock.get_subscription_products_with_gamekeys = MagicMock(
        return_value=aiter(content_choice_options))

    res = await plugin_with_sub.get_subscriptions()
    assert sorted(res, key=lambda x: x.subscription_name) == [
        Subscription("Humble Choice 2019-12", owned=True),
        Subscription("Humble Choice 2020-01", owned=True),
        Subscription("Humble Trove", owned=True),
    ]
Beispiel #8
0
async def test_get_subscriptions_current_month_not_unlocked_yet(api_mock, plugin_with_sub):
    api_mock.had_subscription.return_value = True
    subscription_plan = {
        "human_name": "Month-to-Month Classic Plan",
        "length": 1,
        "machine_name": "monthly_basic",
        "pricing|money": {
            "currency": "USD",
            "amount": 12
        }
    }
    api_mock.get_choice_content_data.return_value = Mock(**{'user_subscription_plan': subscription_plan})
    content_choice_options = [
        Mock(**{'product_machine_name': 'april_2020_choice', 'is_active_content': False}),
    ]
    api_mock.get_subscription_products_with_gamekeys = MagicMock(return_value=aiter(content_choice_options))

    res = await plugin_with_sub.get_subscriptions()
    assert sorted(res, key=lambda x: x.subscription_name) == [
        Subscription("Humble Choice 2020-04", owned=True),
        Subscription("Humble Choice 2020-05", owned=True),  # as it is going to be unlocked
        Subscription("Humble Trove", owned=True),
    ]