1
0
mirror of https://github.com/home-assistant/core.git synced 2025-08-12 06:50:00 +00:00
Files
.circleci
.github
docs
homeassistant
script
tests
auth
components
air_quality
alarm_control_panel
alert
alexa
ambient_station
api
api_streams
apns
arlo
asuswrt
aurora
auth
automatic
automation
awair
aws
axis
bayesian
binary_sensor
blackbird
bom
broadlink
caldav
calendar
camera
canary
cast
climate
cloud
coinmarketcap
command_line
config
__init__.py
test_area_registry.py
test_auth.py
test_auth_provider_homeassistant.py
test_automation.py
test_config_entries.py
test_core.py
test_customize.py
test_device_registry.py
test_entity_registry.py
test_group.py
test_init.py
test_zwave.py
configurator
conversation
counter
cover
daikin
darksky
datadog
deconz
default_config
demo
device_sun_light_trigger
device_tracker
dialogflow
directv
discovery
dsmr
dte_energy_bridge
duckdns
dyson
ecobee
ee_brightbox
efergy
emulated_hue
emulated_roku
esphome
everlights
facebook
facebox
fail2ban
fan
feedreader
ffmpeg
fido
file
filesize
filter
flux
folder
folder_watcher
foobot
freedns
fritzbox
frontend
generic
generic_thermostat
geo_json_events
geo_location
geo_rss_events
geofency
google
google_assistant
google_domains
google_pubsub
google_translate
google_wifi
gpslogger
graphite
group
hangouts
hassio
hddtemp
heos
history
history_graph
history_stats
homeassistant
homekit
homekit_controller
homematic
homematicip_cloud
honeywell
html5
http
huawei_lte
hue
hydroquebec
ifttt
ign_sismologia
image_processing
imap_email_content
influxdb
input_boolean
input_datetime
input_number
input_select
input_text
integration
intent_script
ios
ipma
islamic_prayer_times
jewish_calendar
kira
light
litejet
local_file
locative
lock
logbook
logentries
logger
logi_circle
london_air
lovelace
luftdaten
mailbox
mailgun
manual
manual_mqtt
marytts
media_player
melissa
meraki
mfi
mhz19
microsoft_face
microsoft_face_detect
microsoft_face_identify
min_max
mobile_app
mochad
mold_indicator
monoprice
moon
mqtt
mqtt_eventstream
mqtt_json
mqtt_room
mqtt_statestream
mythicbeastsdns
namecheapdns
ness_alarm
nest
no_ip
notify
nsw_fuel_station
nsw_rural_fire_service_feed
nuheat
nx584
onboarding
openalpr_cloud
openalpr_local
openhardwaremonitor
openuv
owntracks
panel_custom
panel_iframe
persistent_notification
person
pilight
plant
point
prometheus
proximity
ps4
push
pushbullet
python_script
qwikswitch
radarr
rainmachine
random
recorder
reddit
remember_the_milk
remote
rest
rest_command
rflink
rfxtrx
ring
rmvtransport
rss_feed_template
samsungtv
scene
script
season
sensor
shell_command
shopping_list
sigfox
simplisafe
simulated
sleepiq
smartthings
smhi
smtp
snips
sonarr
sonos
soundtouch
spaceapi
spc
splunk
sql
srp_energy
startca
statistics
statsd
stream
sun
switch
switcher_kis
system_health
system_log
tcp
teksavvy
tellduslive
template
threshold
time_date
timer
tod
tomato
toon
tplink
tradfri
transport_nsw
trend
tts
twilio
uk_transport
unifi
unifi_direct
universal
upc_connect
updater
upnp
uptime
usgs_earthquakes_feed
utility_meter
uvc
vacuum
verisure
version
voicerss
vultr
wake_on_lan
water_heater
weather
webhook
weblink
webostv
websocket_api
workday
worldclock
wsdot
wunderground
xiaomi
xiaomi_miio
yamaha
yandextts
yessssms
yr
yweather
zha
zone
zwave
__init__.py
conftest.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
.codecov.yml
.coveragerc
.dockerignore
.gitattributes
.gitignore
.hound.yml
.ignore
.readthedocs.yml
CLA.md
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile
LICENSE.md
MANIFEST.in
README.rst
mypy.ini
mypyrc
pylintrc
requirements_all.txt
requirements_docs.txt
requirements_test.txt
requirements_test_all.txt
setup.cfg
setup.py
tox.ini
core/tests/components/config/test_customize.py
Paulus Schoutsen d1a621601d No more opt-out auth ()
* No more opt-out auth

* Fix var
2018-12-02 16:32:53 +01:00

119 lines
3.4 KiB
Python

"""Test Customize config panel."""
import asyncio
import json
from unittest.mock import patch
from homeassistant.bootstrap import async_setup_component
from homeassistant.components import config
from homeassistant.config import DATA_CUSTOMIZE
@asyncio.coroutine
def test_get_entity(hass, hass_client):
"""Test getting entity."""
with patch.object(config, 'SECTIONS', ['customize']):
yield from async_setup_component(hass, 'config', {})
client = yield from hass_client()
def mock_read(path):
"""Mock reading data."""
return {
'hello.beer': {
'free': 'beer',
},
'other.entity': {
'do': 'something',
},
}
hass.data[DATA_CUSTOMIZE] = {'hello.beer': {'cold': 'beer'}}
with patch('homeassistant.components.config._read', mock_read):
resp = yield from client.get(
'/api/config/customize/config/hello.beer')
assert resp.status == 200
result = yield from resp.json()
assert result == {'local': {'free': 'beer'}, 'global': {'cold': 'beer'}}
@asyncio.coroutine
def test_update_entity(hass, hass_client):
"""Test updating entity."""
with patch.object(config, 'SECTIONS', ['customize']):
yield from async_setup_component(hass, 'config', {})
client = yield from hass_client()
orig_data = {
'hello.beer': {
'ignored': True,
},
'other.entity': {
'polling_intensity': 2,
},
}
def mock_read(path):
"""Mock reading data."""
return orig_data
written = []
def mock_write(path, data):
"""Mock writing data."""
written.append(data)
hass.states.async_set('hello.world', 'state', {'a': 'b'})
with patch('homeassistant.components.config._read', mock_read), \
patch('homeassistant.components.config._write', mock_write):
resp = yield from client.post(
'/api/config/customize/config/hello.world', data=json.dumps({
'name': 'Beer',
'entities': ['light.top', 'light.bottom'],
}))
assert resp.status == 200
result = yield from resp.json()
assert result == {'result': 'ok'}
state = hass.states.get('hello.world')
assert state.state == 'state'
assert dict(state.attributes) == {
'a': 'b', 'name': 'Beer', 'entities': ['light.top', 'light.bottom']}
orig_data['hello.world']['name'] = 'Beer'
orig_data['hello.world']['entities'] = ['light.top', 'light.bottom']
assert written[0] == orig_data
@asyncio.coroutine
def test_update_entity_invalid_key(hass, hass_client):
"""Test updating entity."""
with patch.object(config, 'SECTIONS', ['customize']):
yield from async_setup_component(hass, 'config', {})
client = yield from hass_client()
resp = yield from client.post(
'/api/config/customize/config/not_entity', data=json.dumps({
'name': 'YO',
}))
assert resp.status == 400
@asyncio.coroutine
def test_update_entity_invalid_json(hass, hass_client):
"""Test updating entity."""
with patch.object(config, 'SECTIONS', ['customize']):
yield from async_setup_component(hass, 'config', {})
client = yield from hass_client()
resp = yield from client.post(
'/api/config/customize/config/hello.beer', data='not json')
assert resp.status == 400