Beispiel #1
0
    def test_errors_while_fetching_new_version(self, mock_get):
        """Test for errors while fetching the new version."""
        mock_get.side_effect = requests.RequestException
        self.assertIsNone(updater.get_newest_version())

        mock_get.side_effect = ValueError
        self.assertIsNone(updater.get_newest_version())

        mock_get.side_effect = KeyError
        self.assertIsNone(updater.get_newest_version())
Beispiel #2
0
    def test_errors_while_fetching_new_version(  # pylint: disable=invalid-name
            self, mock_get):
        """Test for errors while fetching the new version."""
        mock_get.side_effect = requests.RequestException
        uuid = '0000'
        self.assertIsNone(updater.get_newest_version(uuid))

        mock_get.side_effect = ValueError
        self.assertIsNone(updater.get_newest_version(uuid))

        mock_get.side_effect = KeyError
        self.assertIsNone(updater.get_newest_version(uuid))
    def test_errors_while_fetching_new_version(  # pylint: disable=invalid-name
            self, mock_get):
        """Test for errors while fetching the new version."""
        mock_get.side_effect = requests.RequestException
        uuid = '0000'
        self.assertIsNone(updater.get_newest_version(uuid))

        mock_get.side_effect = ValueError
        self.assertIsNone(updater.get_newest_version(uuid))

        mock_get.side_effect = KeyError
        self.assertIsNone(updater.get_newest_version(uuid))
def test_error_fetching_new_version_timeout(hass):
    """Test we do not gather analytics when no huuid is passed in."""
    with patch('homeassistant.components.updater.get_system_info',
               Mock(return_value=mock_coro({'fake': 'bla'}))), \
            patch('async_timeout.timeout', side_effect=asyncio.TimeoutError):
        res = yield from updater.get_newest_version(hass, MOCK_HUUID)
        assert res is None
Beispiel #5
0
def test_error_fetching_new_version_timeout(hass):
    """Test we do not gather analytics when no huuid is passed in."""
    with patch('homeassistant.components.updater.get_system_info',
               Mock(return_value=mock_coro({'fake': 'bla'}))), \
            patch('async_timeout.timeout', side_effect=asyncio.TimeoutError):
        res = yield from updater.get_newest_version(hass, MOCK_HUUID, False)
        assert res is None
Beispiel #6
0
def test_disable_reporting(hass, mock_get_uuid, mock_get_newest_version):
    """Test we do not gather analytics when disable reporting is active."""
    mock_get_uuid.return_value = MOCK_HUUID
    mock_get_newest_version.return_value = mock_coro((MOCK_VERSION, ""))

    now = dt_util.utcnow()
    later = now + timedelta(hours=1)
    mock_utcnow.return_value = now

    res = yield from async_setup_component(
        hass, updater.DOMAIN, {updater.DOMAIN: {
            "reporting": False
        }})
    assert res, "Updater failed to set up"

    yield from hass.async_block_till_done()
    with patch("homeassistant.components.updater.current_version",
               MOCK_VERSION):
        async_fire_time_changed(hass, later)
        yield from hass.async_block_till_done()

    assert hass.states.is_state("binary_sensor.updater", "off")
    res = yield from updater.get_newest_version(hass, MOCK_HUUID, MOCK_CONFIG)
    call = mock_get_newest_version.mock_calls[0][1]
    assert call[0] is hass
    assert call[1] is None
def test_error_fetching_new_version_bad_json(hass, aioclient_mock):
    """Test we do not gather analytics when no huuid is passed in."""
    aioclient_mock.post(updater.UPDATER_URL, text='not json')

    with patch('homeassistant.components.updater.get_system_info',
               Mock(return_value=mock_coro({'fake': 'bla'}))):
        res = yield from updater.get_newest_version(hass, MOCK_HUUID)
        assert res is None
Beispiel #8
0
def test_error_fetching_new_version_bad_json(hass, aioclient_mock):
    """Test we do not gather analytics when no huuid is passed in."""
    aioclient_mock.post(updater.UPDATER_URL, text='not json')

    with patch('homeassistant.components.updater.get_system_info',
               Mock(return_value=mock_coro({'fake': 'bla'}))):
        res = yield from updater.get_newest_version(hass, MOCK_HUUID, False)
        assert res is None
Beispiel #9
0
def test_error_fetching_new_version_timeout(hass):
    """Test we handle timeout error while fetching new version."""
    with patch(
            "homeassistant.helpers.system_info.async_get_system_info",
            Mock(return_value=mock_coro({"fake": "bla"})),
    ), patch("async_timeout.timeout", side_effect=asyncio.TimeoutError):
        res = yield from updater.get_newest_version(hass, MOCK_HUUID, False)
        assert res is None
Beispiel #10
0
def test_get_newest_version_analytics_when_huuid(hass, aioclient_mock):
    """Test we do not gather analytics when no huuid is passed in."""
    aioclient_mock.post(updater.UPDATER_URL, json=MOCK_RESPONSE)

    with patch('homeassistant.components.updater.get_system_info',
               Mock(return_value=mock_coro({'fake': 'bla'}))):
        res = yield from updater.get_newest_version(hass, MOCK_HUUID)
        assert res == (MOCK_RESPONSE['version'],
                       MOCK_RESPONSE['release-notes'])
Beispiel #11
0
def test_get_newest_version_no_analytics_when_no_huuid(hass, aioclient_mock):
    """Test we do not gather analytics when no huuid is passed in."""
    aioclient_mock.post(updater.UPDATER_URL, json=MOCK_RESPONSE)

    with patch('homeassistant.components.updater.get_system_info',
               side_effect=Exception):
        res = yield from updater.get_newest_version(hass, None)
        assert res == (MOCK_RESPONSE['version'],
                       MOCK_RESPONSE['release-notes'])
Beispiel #12
0
def test_get_newest_version_no_analytics_when_no_huuid(hass, aioclient_mock):
    """Test we do not gather analytics when no huuid is passed in."""
    aioclient_mock.post(updater.UPDATER_URL, json=MOCK_RESPONSE)

    with patch('homeassistant.components.updater.get_system_info',
               side_effect=Exception):
        res = yield from updater.get_newest_version(hass, None, False)
        assert res == (MOCK_RESPONSE['version'],
                       MOCK_RESPONSE['release-notes'])
Beispiel #13
0
def test_get_newest_version_analytics_when_huuid(hass, aioclient_mock):
    """Test we do not gather analytics when no huuid is passed in."""
    aioclient_mock.post(updater.UPDATER_URL, json=MOCK_RESPONSE)

    with patch('homeassistant.components.updater.get_system_info',
               Mock(return_value=mock_coro({'fake': 'bla'}))):
        res = yield from updater.get_newest_version(hass, MOCK_HUUID, False)
        assert res == (MOCK_RESPONSE['version'],
                       MOCK_RESPONSE['release-notes'])
Beispiel #14
0
def test_error_fetching_new_version_bad_json(hass, aioclient_mock):
    """Test we handle json error while fetching new version."""
    aioclient_mock.post(updater.UPDATER_URL, text="not json")

    with patch(
            "homeassistant.helpers.system_info.async_get_system_info",
            Mock(return_value=mock_coro({"fake": "bla"})),
    ):
        res = yield from updater.get_newest_version(hass, MOCK_HUUID, False)
        assert res is None
Beispiel #15
0
def test_get_newest_version_analytics_when_huuid(hass, aioclient_mock):
    """Test we gather analytics when huuid is passed in."""
    aioclient_mock.post(updater.UPDATER_URL, json=MOCK_RESPONSE)

    with patch(
            "homeassistant.helpers.system_info.async_get_system_info",
            Mock(return_value=mock_coro({"fake": "bla"})),
    ):
        res = yield from updater.get_newest_version(hass, MOCK_HUUID, False)
        assert res == (MOCK_RESPONSE["version"],
                       MOCK_RESPONSE["release-notes"])
Beispiel #16
0
def test_error_fetching_new_version_invalid_response(hass, aioclient_mock):
    """Test we do not gather analytics when no huuid is passed in."""
    aioclient_mock.post(updater.UPDATER_URL, json={
        'version': '0.15'
        # 'release-notes' is missing
    })

    with patch('homeassistant.components.updater.get_system_info',
               Mock(return_value=mock_coro({'fake': 'bla'}))):
        res = yield from updater.get_newest_version(hass, MOCK_HUUID)
        assert res is None
Beispiel #17
0
def test_error_fetching_new_version_invalid_response(hass, aioclient_mock):
    """Test we do not gather analytics when no huuid is passed in."""
    aioclient_mock.post(
        updater.UPDATER_URL,
        json={'version': '0.15'
              # 'release-notes' is missing
              })

    with patch('homeassistant.helpers.system_info.async_get_system_info',
               Mock(return_value=mock_coro({'fake': 'bla'}))):
        res = yield from updater.get_newest_version(hass, MOCK_HUUID, False)
        assert res is None
Beispiel #18
0
    def test_reporting_false_works(self, m):
        """Test we do not send any data."""
        m.post(updater.UPDATER_URL,
               json={'version': '0.15',
                     'release-notes': 'https://home-assistant.io'})

        response = updater.get_newest_version(None)

        assert response == ('0.15', 'https://home-assistant.io')

        history = m.request_history

        assert len(history) == 1
        assert history[0].json() == {}
    def test_reporting_false_works(self, m):
        """Test we do not send any data."""
        m.post(updater.UPDATER_URL,
               json={'version': '0.15',
                     'release-notes': 'https://home-assistant.io'})

        response = updater.get_newest_version(None)

        assert response == ('0.15', 'https://home-assistant.io')

        history = m.request_history

        assert len(history) == 1
        assert history[0].json() == {}
Beispiel #20
0
def test_error_fetching_new_version_invalid_response(hass, aioclient_mock):
    """Test we handle response error while fetching new version."""
    aioclient_mock.post(
        updater.UPDATER_URL,
        json={"version": "0.15"
              # 'release-notes' is missing
              },
    )

    with patch(
            "homeassistant.helpers.system_info.async_get_system_info",
            Mock(return_value=mock_coro({"fake": "bla"})),
    ):
        res = yield from updater.get_newest_version(hass, MOCK_HUUID, False)
        assert res is None
Beispiel #21
0
def test_disable_reporting(hass, mock_get_uuid, mock_get_newest_version):
    """Test if new entity is created if new version is available."""
    mock_get_uuid.return_value = MOCK_HUUID
    mock_get_newest_version.return_value = mock_coro((MOCK_VERSION, ''))

    res = yield from async_setup_component(
        hass, updater.DOMAIN, {updater.DOMAIN: {
            'reporting': False
        }})
    assert res, 'Updater failed to set up'

    with patch('homeassistant.components.updater.current_version',
               MOCK_VERSION):
        async_fire_time_changed(hass, dt_util.utcnow() + timedelta(hours=1))
        yield from hass.async_block_till_done()

    assert hass.states.get(updater.ENTITY_ID) is None
    res = yield from updater.get_newest_version(hass, MOCK_HUUID, MOCK_CONFIG)
    call = mock_get_newest_version.mock_calls[0][1]
    assert call[0] is hass
    assert call[1] is None
Beispiel #22
0
def test_disable_reporting(hass, mock_get_uuid, mock_get_newest_version):
    """Test if new entity is created if new version is available."""
    mock_get_uuid.return_value = MOCK_HUUID
    mock_get_newest_version.return_value = mock_coro((MOCK_VERSION, ''))

    res = yield from async_setup_component(
        hass, updater.DOMAIN, {updater.DOMAIN: {
            'reporting': False
        }})
    assert res, 'Updater failed to setup'

    with patch('homeassistant.components.updater.CURRENT_VERSION',
               MOCK_VERSION):
        async_fire_time_changed(hass, dt_util.utcnow() + timedelta(hours=1))
        yield from hass.async_block_till_done()

    assert hass.states.get(updater.ENTITY_ID) is None
    res = yield from updater.get_newest_version(hass, MOCK_HUUID, MOCK_CONFIG)
    call = mock_get_newest_version.mock_calls[0][1]
    assert call[0] is hass
    assert call[1] is None