Пример #1
0
async def test_oauth_without_sub_and_follow(hass):
    """Test state with oauth."""

    twitch_mock = MagicMock()
    twitch_mock.users.translate_usernames_to_ids.return_value = [USER_ID]
    twitch_mock.channels.get_by_id.return_value = CHANNEL_OBJECT
    twitch_mock._oauth_token = True  # A replacement for the token
    twitch_mock.users.get.return_value = OAUTH_USER_ID
    twitch_mock.users.check_subscribed_to_channel.side_effect = HTTPError()
    twitch_mock.users.check_follows_channel.side_effect = HTTPError()

    with patch(
        "homeassistant.components.twitch.sensor.TwitchClient",
        return_value=twitch_mock,
    ):
        assert await async_setup_component(hass, sensor.DOMAIN, CONFIG_WITH_OAUTH)
        await hass.async_block_till_done()

    sensor_state = hass.states.get(ENTITY_ID)
    assert sensor_state.attributes["subscribed"] is False
    assert sensor_state.attributes["following"] is False
Пример #2
0
async def test_oauth_with_sub(hass):
    """Test state with oauth and sub."""

    twitch_mock = MagicMock()
    twitch_mock.users.translate_usernames_to_ids.return_value = [USER_ID]
    twitch_mock.channels.get_by_id.return_value = CHANNEL_OBJECT
    twitch_mock._oauth_token = True  # A replacement for the token
    twitch_mock.users.get.return_value = OAUTH_USER_ID
    twitch_mock.users.check_subscribed_to_channel.return_value = SUB_ACTIVE
    twitch_mock.users.check_follows_channel.side_effect = HTTPError()

    with patch(
            "homeassistant.components.twitch.sensor.TwitchClient",
            return_value=twitch_mock,
    ):
        assert (await async_setup_component(hass, sensor.DOMAIN,
                                            CONFIG_WITH_OAUTH) is True)

    sensor_state = hass.states.get(ENTITY_ID)
    assert sensor_state.attributes["subscribed"] is True
    assert sensor_state.attributes["subscribed_since"] == "2020-01-20T21:22:42"
    assert sensor_state.attributes["subscription_is_gifted"] is False
    assert sensor_state.attributes["following"] is False