Upgrade Ring to new version (#30666)

* Upgrade Ring to new version

* Move legacy cleanup down

* Fix test
This commit is contained in:
Paulus Schoutsen committed 2020-01-11 16:16:58 -08:00
1 parent 86bdba2ea2
commit 718f3438ea
16 files changed
+121 -123

No files matched your search

+3 -1
View File
@@ -9,7 +9,9 @@ from tests.common import MockConfigEntry
async def setup_platform(hass, platform):
"""Set up the ring platform and prerequisites."""
MockConfigEntry(domain=DOMAIN, data={"username": "foo"}).add_to_hass(hass)
MockConfigEntry(domain=DOMAIN, data={"username": "foo", "token": {}}).add_to_hass(
hass
)
with patch("homeassistant.components.ring.PLATFORMS", [platform]):
assert await async_setup_component(hass, DOMAIN, {})
await hass.async_block_till_done()
+1 -10
View File
@@ -1,21 +1,12 @@
"""Configuration for Ring tests."""
from asynctest import patch
import pytest
import requests_mock
from tests.common import load_fixture
@pytest.fixture(name="ring_mock")
def ring_save_mock():
"""Fixture to mock a ring."""
with patch("ring_doorbell._exists_cache", return_value=False):
with patch("ring_doorbell._save_cache", return_value=True) as save_mock:
yield save_mock
@pytest.fixture(name="requests_mock")
def requests_mock_fixture(ring_mock):
def requests_mock_fixture():
"""Fixture to provide a requests mocker."""
with requests_mock.mock() as mock:
# Note all devices have an id of 987652, but a different device_id.
+1 -14
View File
@@ -1,6 +1,5 @@
"""The tests for the Ring binary sensor platform."""
from asyncio import run_coroutine_threadsafe
import os
import unittest
from unittest.mock import patch
@@ -9,12 +8,7 @@ import requests_mock
from homeassistant.components import ring as base_ring
from homeassistant.components.ring import binary_sensor as ring
from tests.common import (
get_test_config_dir,
get_test_home_assistant,
load_fixture,
mock_storage,
)
from tests.common import get_test_home_assistant, load_fixture, mock_storage
from tests.components.ring.test_init import ATTRIBUTION, VALID_CONFIG
@@ -28,15 +22,9 @@ class TestRingBinarySensorSetup(unittest.TestCase):
for device in devices:
self.DEVICES.append(device)
def cleanup(self):
"""Cleanup any data created from the tests."""
if os.path.isfile(self.cache):
os.remove(self.cache)
def setUp(self):
"""Initialize values for this testcase class."""
self.hass = get_test_home_assistant()
self.cache = get_test_config_dir(base_ring.DEFAULT_CACHEDB)
self.config = {
"username": "foo",
"password": "bar",
@@ -46,7 +34,6 @@ class TestRingBinarySensorSetup(unittest.TestCase):
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.cleanup()
@requests_mock.Mocker()
def test_binary_sensor(self, mock):
+7 -3
View File
@@ -18,8 +18,10 @@ async def test_form(hass):
assert result["errors"] == {}
with patch(
"homeassistant.components.ring.config_flow.Ring",
return_value=Mock(is_connected=True),
"homeassistant.components.ring.config_flow.Auth",
return_value=Mock(
fetch_token=Mock(return_value={"access_token": "mock-token"})
),
), patch(
"homeassistant.components.ring.async_setup", return_value=mock_coro(True)
) as mock_setup, patch(
@@ -34,6 +36,7 @@ async def test_form(hass):
assert result2["title"] == "hello@home-assistant.io"
assert result2["data"] == {
"username": "hello@home-assistant.io",
"token": {"access_token": "mock-token"},
}
await hass.async_block_till_done()
assert len(mock_setup.mock_calls) == 1
@@ -47,7 +50,8 @@ async def test_form_invalid_auth(hass):
)
with patch(
"homeassistant.components.ring.config_flow.Ring", side_effect=InvalidAuth,
"homeassistant.components.ring.config_flow.Auth.fetch_token",
side_effect=InvalidAuth,
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
+1 -9
View File
@@ -2,7 +2,6 @@
from asyncio import run_coroutine_threadsafe
from copy import deepcopy
from datetime import timedelta
import os
import unittest
import requests_mock
@@ -10,7 +9,7 @@ import requests_mock
from homeassistant import setup
import homeassistant.components.ring as ring
from tests.common import get_test_config_dir, get_test_home_assistant, load_fixture
from tests.common import get_test_home_assistant, load_fixture
ATTRIBUTION = "Data provided by Ring.com"
@@ -22,21 +21,14 @@ VALID_CONFIG = {
class TestRing(unittest.TestCase):
"""Tests the Ring component."""
def cleanup(self):
"""Cleanup any data created from the tests."""
if os.path.isfile(self.cache):
os.remove(self.cache)
def setUp(self):
"""Initialize values for this test case class."""
self.hass = get_test_home_assistant()
self.cache = get_test_config_dir(ring.DEFAULT_CACHEDB)
self.config = VALID_CONFIG
def tearDown(self): # pylint: disable=invalid-name
"""Stop everything that was started."""
self.hass.stop()
self.cleanup()
@requests_mock.Mocker()
def test_setup(self, mock):
+8 -20
View File
@@ -1,6 +1,5 @@
"""The tests for the Ring sensor platform."""
from asyncio import run_coroutine_threadsafe
import os
import unittest
from unittest.mock import patch
@@ -10,12 +9,7 @@ from homeassistant.components import ring as base_ring
import homeassistant.components.ring.sensor as ring
from homeassistant.helpers.icon import icon_for_battery_level
from tests.common import (
get_test_config_dir,
get_test_home_assistant,
load_fixture,
mock_storage,
)
from tests.common import get_test_home_assistant, load_fixture, mock_storage
from tests.components.ring.test_init import ATTRIBUTION, VALID_CONFIG
@@ -29,15 +23,9 @@ class TestRingSensorSetup(unittest.TestCase):
for device in devices:
self.DEVICES.append(device)
def cleanup(self):
"""Cleanup any data created from the tests."""
if os.path.isfile(self.cache):
os.remove(self.cache)
def setUp(self):
"""Initialize values for this testcase class."""
self.hass = get_test_home_assistant()
self.cache = get_test_config_dir(base_ring.DEFAULT_CACHEDB)
self.config = {
"username": "foo",
"password": "bar",
@@ -55,7 +43,6 @@ class TestRingSensorSetup(unittest.TestCase):
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.cleanup()
@requests_mock.Mocker()
def test_sensor(self, mock):
@@ -97,6 +84,13 @@ class TestRingSensorSetup(unittest.TestCase):
).result()
for device in self.DEVICES:
# Mimick add to hass
device.hass = self.hass
run_coroutine_threadsafe(
device.async_added_to_hass(), self.hass.loop,
).result()
# Entity update data from ring data
device.update()
if device.name == "Front Battery":
expected_icon = icon_for_battery_level(
@@ -104,18 +98,12 @@ class TestRingSensorSetup(unittest.TestCase):
)
assert device.icon == expected_icon
assert 80 == device.state
assert "hp_cam_v1" == device.device_state_attributes["kind"]
assert "stickup_cams" == device.device_state_attributes["type"]
if device.name == "Front Door Battery":
assert 100 == device.state
assert "lpd_v1" == device.device_state_attributes["kind"]
assert "chimes" != device.device_state_attributes["type"]
if device.name == "Downstairs Volume":
assert 2 == device.state
assert "1.2.3" == device.device_state_attributes["firmware"]
assert "ring_mock_wifi" == device.device_state_attributes["wifi_name"]
assert "mdi:bell-ring" == device.icon
assert "chimes" == device.device_state_attributes["type"]
if device.name == "Front Door Last Activity":
assert not device.device_state_attributes["answered"]
assert "America/New_York" == device.device_state_attributes["timezone"]