parent
6765d395f9
commit
27dd4ca9b3
1 changed files with 25 additions and 43 deletions
|
@ -1,13 +1,10 @@
|
||||||
"""The tests for the Ring component."""
|
"""The tests for the Ring component."""
|
||||||
from asyncio import run_coroutine_threadsafe
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import unittest
|
|
||||||
|
|
||||||
import requests_mock
|
|
||||||
|
|
||||||
import homeassistant.components.ring as ring
|
import homeassistant.components.ring as ring
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import get_test_home_assistant, load_fixture
|
from tests.common import load_fixture
|
||||||
|
|
||||||
ATTRIBUTION = "Data provided by Ring.com"
|
ATTRIBUTION = "Data provided by Ring.com"
|
||||||
|
|
||||||
|
@ -16,43 +13,28 @@ VALID_CONFIG = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class TestRing(unittest.TestCase):
|
async def test_setup(hass, requests_mock):
|
||||||
"""Tests the Ring component."""
|
"""Test the setup."""
|
||||||
|
await async_setup_component(hass, ring.DOMAIN, {})
|
||||||
|
|
||||||
def setUp(self):
|
requests_mock.post(
|
||||||
"""Initialize values for this test case class."""
|
"https://oauth.ring.com/oauth/token", text=load_fixture("ring_oauth.json")
|
||||||
self.hass = get_test_home_assistant()
|
)
|
||||||
self.config = VALID_CONFIG
|
requests_mock.post(
|
||||||
self.addCleanup(self.tear_down_cleanup)
|
"https://api.ring.com/clients_api/session",
|
||||||
|
text=load_fixture("ring_session.json"),
|
||||||
|
)
|
||||||
|
requests_mock.get(
|
||||||
|
"https://api.ring.com/clients_api/ring_devices",
|
||||||
|
text=load_fixture("ring_devices.json"),
|
||||||
|
)
|
||||||
|
requests_mock.get(
|
||||||
|
"https://api.ring.com/clients_api/chimes/999999/health",
|
||||||
|
text=load_fixture("ring_chime_health_attrs.json"),
|
||||||
|
)
|
||||||
|
requests_mock.get(
|
||||||
|
"https://api.ring.com/clients_api/doorbots/987652/health",
|
||||||
|
text=load_fixture("ring_doorboot_health_attrs.json"),
|
||||||
|
)
|
||||||
|
|
||||||
def tear_down_cleanup(self):
|
assert await ring.async_setup(hass, VALID_CONFIG)
|
||||||
"""Stop everything that was started."""
|
|
||||||
self.hass.stop()
|
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
|
||||||
def test_setup(self, mock):
|
|
||||||
"""Test the setup."""
|
|
||||||
mock.post(
|
|
||||||
"https://oauth.ring.com/oauth/token", text=load_fixture("ring_oauth.json")
|
|
||||||
)
|
|
||||||
mock.post(
|
|
||||||
"https://api.ring.com/clients_api/session",
|
|
||||||
text=load_fixture("ring_session.json"),
|
|
||||||
)
|
|
||||||
mock.get(
|
|
||||||
"https://api.ring.com/clients_api/ring_devices",
|
|
||||||
text=load_fixture("ring_devices.json"),
|
|
||||||
)
|
|
||||||
mock.get(
|
|
||||||
"https://api.ring.com/clients_api/chimes/999999/health",
|
|
||||||
text=load_fixture("ring_chime_health_attrs.json"),
|
|
||||||
)
|
|
||||||
mock.get(
|
|
||||||
"https://api.ring.com/clients_api/doorbots/987652/health",
|
|
||||||
text=load_fixture("ring_doorboot_health_attrs.json"),
|
|
||||||
)
|
|
||||||
response = run_coroutine_threadsafe(
|
|
||||||
ring.async_setup(self.hass, self.config), self.hass.loop
|
|
||||||
).result()
|
|
||||||
|
|
||||||
assert response
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue