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
alert
alexa
ambient_station
api
arlo
auth
automation
binary_sensor
calendar
camera
canary
cast
climate
cloud
config
configurator
conversation
counter
cover
daikin
datadog
deconz
default_config
demo
device_sun_light_trigger
device_tracker
dialogflow
discovery
duckdns
dyson
ecobee
emulated_hue
emulated_roku
esphome
fan
feedreader
ffmpeg
folder_watcher
freedns
fritzbox
frontend
geo_location
geofency
google
google_assistant
google_domains
google_pubsub
gpslogger
graphite
group
hangouts
hassio
history
history_graph
homekit
homekit_controller
homematicip_cloud
http
huawei_lte
hue
ifttt
image_processing
influxdb
init
input_boolean
input_datetime
input_number
input_select
input_text
intent_script
introduction
ios
ipma
kira
light
litejet
locative
lock
logbook
logentries
logger
lovelace
luftdaten
mailbox
mailgun
media_player
melissa
microsoft_face
mochad
mqtt
mqtt_eventstream
mqtt_statestream
mythicbeastsdns
namecheapdns
ness_alarm
nest
no_ip
notify
__init__.py
common.py
test_apns.py
test_command_line.py
test_demo.py
test_facebook.py
test_file.py
test_group.py
test_homematic.py
test_html5.py
test_pushbullet.py
test_smtp.py
test_yessssms.py
nuheat
onboarding
openuv
owntracks
panel_custom
panel_iframe
persistent_notification
person
pilight
plant
point
prometheus
proximity
ps4
python_script
qwikswitch
rainmachine
recorder
remember_the_milk
remote
rest_command
rflink
rfxtrx
ring
rss_feed_template
scene
script
sensor
shell_command
shopping_list
simplisafe
sleepiq
smartthings
smhi
snips
sonos
spaceapi
spc
splunk
statsd
sun
switch
system_health
system_log
tellduslive
timer
toon
tplink
tradfri
tts
twilio
unifi
updater
upnp
utility_meter
vacuum
verisure
vultr
wake_on_lan
water_heater
weather
webhook
weblink
webostv
websocket_api
xiaomi_miio
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
.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
84 lines
3.1 KiB
Python
84 lines
3.1 KiB
Python
"""The tests for the command line notification platform."""
|
|
import os
|
|
import tempfile
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from homeassistant.setup import setup_component
|
|
import homeassistant.components.notify as notify
|
|
from tests.common import assert_setup_component, get_test_home_assistant
|
|
|
|
|
|
class TestCommandLine(unittest.TestCase):
|
|
"""Test the command line notifications."""
|
|
|
|
def setUp(self): # pylint: disable=invalid-name
|
|
"""Set up things to be run when tests are started."""
|
|
self.hass = get_test_home_assistant()
|
|
|
|
def tearDown(self): # pylint: disable=invalid-name
|
|
"""Stop down everything that was started."""
|
|
self.hass.stop()
|
|
|
|
def test_setup(self):
|
|
"""Test setup."""
|
|
with assert_setup_component(1) as handle_config:
|
|
assert setup_component(self.hass, 'notify', {
|
|
'notify': {
|
|
'name': 'test',
|
|
'platform': 'command_line',
|
|
'command': 'echo $(cat); exit 1', }
|
|
})
|
|
assert handle_config[notify.DOMAIN]
|
|
|
|
def test_bad_config(self):
|
|
"""Test set up the platform with bad/missing configuration."""
|
|
config = {
|
|
notify.DOMAIN: {
|
|
'name': 'test',
|
|
'platform': 'command_line',
|
|
}
|
|
}
|
|
with assert_setup_component(0) as handle_config:
|
|
assert setup_component(self.hass, notify.DOMAIN, config)
|
|
assert not handle_config[notify.DOMAIN]
|
|
|
|
def test_command_line_output(self):
|
|
"""Test the command line output."""
|
|
with tempfile.TemporaryDirectory() as tempdirname:
|
|
filename = os.path.join(tempdirname, 'message.txt')
|
|
message = 'one, two, testing, testing'
|
|
with assert_setup_component(1) as handle_config:
|
|
assert setup_component(self.hass, notify.DOMAIN, {
|
|
'notify': {
|
|
'name': 'test',
|
|
'platform': 'command_line',
|
|
'command': 'echo $(cat) > {}'.format(filename)
|
|
}
|
|
})
|
|
assert handle_config[notify.DOMAIN]
|
|
|
|
assert self.hass.services.call(
|
|
'notify', 'test', {'message': message}, blocking=True)
|
|
|
|
with open(filename) as fil:
|
|
# the echo command adds a line break
|
|
assert fil.read() == "{}\n".format(message)
|
|
|
|
@patch('homeassistant.components.notify.command_line._LOGGER.error')
|
|
def test_error_for_none_zero_exit_code(self, mock_error):
|
|
"""Test if an error is logged for non zero exit codes."""
|
|
with assert_setup_component(1) as handle_config:
|
|
assert setup_component(self.hass, notify.DOMAIN, {
|
|
'notify': {
|
|
'name': 'test',
|
|
'platform': 'command_line',
|
|
'command': 'echo $(cat); exit 1'
|
|
}
|
|
})
|
|
assert handle_config[notify.DOMAIN]
|
|
|
|
assert self.hass.services.call('notify', 'test', {'message': 'error'},
|
|
blocking=True)
|
|
assert 1 == mock_error.call_count
|