mirror of
https://github.com/home-assistant/core.git
synced 2025-08-13 15:30:03 +00:00
.github
docs
homeassistant
script
tests
auth
components
air_quality
alarm_control_panel
alexa
ambient_station
auth
automation
binary_sensor
calendar
camera
cast
climate
cloud
config
counter
cover
daikin
deconz
device_tracker
dialogflow
emulated_hue
emulated_roku
esphome
fan
frontend
geo_location
geofency
google_assistant
gpslogger
group
hangouts
hassio
homekit
homekit_controller
homematicip_cloud
http
hue
ifttt
image_processing
ios
light
locative
lock
lovelace
luftdaten
mailbox
mailgun
media_player
mqtt
nest
notify
onboarding
openuv
owntracks
persistent_notification
point
rainmachine
recorder
remote
scene
sensor
simplisafe
smartthings
smhi
sonos
switch
system_health
tellduslive
timer
tradfri
tts
twilio
unifi
upnp
utility_meter
vacuum
water_heater
weather
websocket_api
zha
zone
zwave
__init__.py
conftest.py
test_alert.py
test_api.py
test_canary.py
test_configurator.py
test_conversation.py
test_datadog.py
test_demo.py
test_device_sun_light_trigger.py
test_discovery.py
test_duckdns.py
test_dyson.py
test_feedreader.py
test_ffmpeg.py
test_folder_watcher.py
test_freedns.py
test_google.py
test_google_domains.py
test_graphite.py
test_history.py
test_history_graph.py
test_huawei_lte.py
test_influxdb.py
test_init.py
test_input_boolean.py
test_input_datetime.py
test_input_number.py
test_input_select.py
test_input_text.py
test_intent_script.py
test_introduction.py
test_kira.py
test_litejet.py
test_logbook.py
test_logentries.py
test_logger.py
test_melissa.py
test_microsoft_face.py
test_mqtt_eventstream.py
test_mqtt_statestream.py
test_mythicbeastsdns.py
test_namecheapdns.py
test_ness_alarm.py
test_no_ip.py
test_nuheat.py
test_panel_custom.py
test_panel_iframe.py
test_pilight.py
test_plant.py
test_prometheus.py
test_proximity.py
test_python_script.py
test_qwikswitch.py
test_remember_the_milk.py
test_rest_command.py
test_rflink.py
test_rfxtrx.py
test_ring.py
test_rss_feed_template.py
test_script.py
test_shell_command.py
test_shopping_list.py
test_sleepiq.py
test_snips.py
test_spaceapi.py
test_spc.py
test_splunk.py
test_statsd.py
test_sun.py
test_system_log.py
test_updater.py
test_vultr.py
test_wake_on_lan.py
test_webhook.py
test_weblink.py
fixtures
helpers
mock
resources
scripts
test_util
testing_config
util
__init__.py
common.py
conftest.py
test_bootstrap.py
test_config.py
test_config_entries.py
test_core.py
test_data_entry_flow.py
test_loader.py
test_main.py
test_requirements.py
test_setup.py
virtualization
.coveragerc
.dockerignore
.gitattributes
.gitignore
.hound.yml
.ignore
.readthedocs.yml
.travis.yml
CLA.md
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile
LICENSE.md
MANIFEST.in
README.rst
mypy.ini
pylintrc
requirements_all.txt
requirements_docs.txt
requirements_test.txt
requirements_test_all.txt
setup.cfg
setup.py
tox.ini

* Convert core tests
* Convert component tests to use pytest assert
* Lint 🤷♂️
* Fix test
* Fix 3 typos in docs
69 lines
2.2 KiB
Python
69 lines
2.2 KiB
Python
"""The tests for the Ring component."""
|
|
from copy import deepcopy
|
|
import os
|
|
import unittest
|
|
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)
|
|
|
|
ATTRIBUTION = 'Data provided by Ring.com'
|
|
|
|
VALID_CONFIG = {
|
|
"ring": {
|
|
"username": "foo",
|
|
"password": "bar",
|
|
}
|
|
}
|
|
|
|
|
|
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'))
|
|
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)
|