hass-core/tests/components/ring/test_init.py
Ross Dargan 5e7465a261 Change how ring polls for changes to allow more platforms to be added (#25534)
* Add in a switch to control lights and sirens

* Improve the way sensors are updated

* fixes following flake8

* remove light platform, and fix breaking test.

* Resolve issues with tests

* add tests for the switch platform

* fix up flake8 errors

* fix the long strings

* fix naming on private method.

* updates following p/r

* further fixes following pr

* removed import

* add additional tests to improve code coverage

* forgot to check this in
2019-07-31 11:08:40 -07:00

75 lines
2.6 KiB
Python

"""The tests for the Ring component."""
from copy import deepcopy
import os
import unittest
import requests_mock
from datetime import timedelta
from homeassistant import setup
import homeassistant.components.ring as ring
from tests.common import (
get_test_config_dir, get_test_home_assistant, load_fixture)
ATTRIBUTION = 'Data provided by Ring.com'
VALID_CONFIG = {
"ring": {
"username": "foo",
"password": "bar",
"scan_interval": timedelta(10)
}
}
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):
"""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 = ring.setup(self.hass, self.config)
assert response
@requests_mock.Mocker()
def test_setup_component_no_login(self, mock):
"""Test the setup when no login is configured."""
mock.post('https://api.ring.com/clients_api/session',
text=load_fixture('ring_session.json'))
conf = deepcopy(VALID_CONFIG)
del conf['ring']['username']
assert not setup.setup_component(self.hass, ring.DOMAIN, conf)
@requests_mock.Mocker()
def test_setup_component_no_pwd(self, mock):
"""Test the setup when no password is configured."""
mock.post('https://api.ring.com/clients_api/session',
text=load_fixture('ring_session.json'))
conf = deepcopy(VALID_CONFIG)
del conf['ring']['password']
assert not setup.setup_component(self.hass, ring.DOMAIN, conf)