示例#1
0
async def test_get_subscription_seats_exceeded_invalid_data(
        api_client: Client, mocker: MockFixture,
        mock_get_token_for_install: None) -> None:
    """
    Handle invalid data gracefully.
    """
    fake_redis = create_fake_redis_reply({
        b"account_id": b"DF5C23EB-585B-4031-B082-7FF951B4DE15",
        b"subscription_blocker": b"seats_exceeded",
        b"data": b"*(invalid-data4#",
    })

    mocker.patch("kodiak.event_handlers.get_redis",
                 return_value=wrap_future(fake_redis))
    async with api_client as api_client:
        res = await api_client.get_subscription()
    assert res == Subscription(
        account_id="DF5C23EB-585B-4031-B082-7FF951B4DE15",
        subscription_blocker=SeatsExceeded(allowed_user_ids=[]),
    )
示例#2
0
async def test_get_subscription_seats_exceeded_no_seats(
        api_client: Client, mocker: MockFixture,
        mock_get_token_for_install: None) -> None:
    """
    When an account has 0 seats we will not have any allowed_user_ids.
    """
    fake_redis = create_fake_redis_reply({
        b"account_id":
        b"DF5C23EB-585B-4031-B082-7FF951B4DE15",
        b"subscription_blocker":
        b"seats_exceeded",
        b"data":
        b'{"kind":"seats_exceeded", "allowed_user_ids": []}',
    })
    mocker.patch("kodiak.event_handlers.get_redis",
                 return_value=wrap_future(fake_redis))
    async with api_client as api_client:
        res = await api_client.get_subscription()
    assert res == Subscription(
        account_id="DF5C23EB-585B-4031-B082-7FF951B4DE15",
        subscription_blocker=SeatsExceeded(allowed_user_ids=[]),
    )
示例#3
0
async def test_get_subscription_seats_exceeded_missing_data(
        api_client: Client, mocker: MockFixture,
        mock_get_token_for_install: None) -> None:
    """
    For backwards compatibility we cannot guarantee that "seats_exceeded" will
    have the data parameter.
    """
    fake_redis = create_fake_redis_reply({
        b"account_id":
        b"DF5C23EB-585B-4031-B082-7FF951B4DE15",
        b"subscription_blocker":
        b"seats_exceeded",
    })

    mocker.patch("kodiak.event_handlers.get_redis",
                 return_value=wrap_future(fake_redis))
    async with api_client as api_client:
        res = await api_client.get_subscription()
    assert res == Subscription(
        account_id="DF5C23EB-585B-4031-B082-7FF951B4DE15",
        subscription_blocker=SeatsExceeded(allowed_user_ids=[]),
    )
示例#4
0
async def test_get_subscription_seats_exceeded(
        api_client: Client, mocker: MockFixture,
        mock_get_token_for_install: None) -> None:
    """
    When a user exceeds their seat we will specify allowed users for those users
    that occupy a seat.
    """
    fake_redis = create_fake_redis_reply({
        b"account_id":
        b"DF5C23EB-585B-4031-B082-7FF951B4DE15",
        b"subscription_blocker":
        b"seats_exceeded",
        b"data":
        b'{"kind":"seats_exceeded", "allowed_user_ids": [5234234]}',
    })
    mocker.patch("kodiak.queue.get_redis",
                 return_value=wrap_future(fake_redis))
    async with api_client as api_client:
        res = await api_client.get_subscription()
    assert res == Subscription(
        account_id="DF5C23EB-585B-4031-B082-7FF951B4DE15",
        subscription_blocker=SeatsExceeded(allowed_user_ids=[5234234]),
    )
示例#5
0
async def test_get_subscription_seats_exceeded_invalid_kind(
        api_client: Client, mocker: MockFixture,
        mock_get_token_for_install: None) -> None:
    """
    Handle mismatch in subscription_blocker types between data parameter and
    subscription_blocker.
    """
    fake_redis = create_fake_redis_reply({
        b"account_id":
        b"DF5C23EB-585B-4031-B082-7FF951B4DE15",
        b"subscription_blocker":
        b"seats_exceeded",
        b"data":
        b'{"kind":"trial_expired", "allowed_user_ids": [5234234]}',
    })

    mocker.patch("kodiak.event_handlers.get_redis",
                 return_value=wrap_future(fake_redis))
    async with api_client as api_client:
        res = await api_client.get_subscription()
    assert res == Subscription(
        account_id="DF5C23EB-585B-4031-B082-7FF951B4DE15",
        subscription_blocker=SeatsExceeded(allowed_user_ids=[]),
    )