desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Test for setup failure for bad for.'
| def test_if_fails_setup_bad_for(self):
| with assert_setup_component(0):
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'state', 'entity_id': 'test.entity', 'to': 'world', 'for': {'invalid': 5}}, 'action': {'service': 'homeassistant.turn_on'}}})
|
'Test for setup failures for missing to.'
| def test_if_fails_setup_for_without_to(self):
| with assert_setup_component(0):
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'state', 'entity_id': 'test.entity', 'for': {'seconds': 5}}, 'action': {'service': 'homeassistant.turn_on'}}})
|
'Test for not firing on entity change with for.'
| def test_if_not_fires_on_entity_change_with_for(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'state', 'entity_id': 'test.entity', 'to': 'world', 'for': {'seconds': 5}}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
self.hass.sta... |
'Test for firing on entity change with for and attribute change.'
| def test_if_fires_on_entity_change_with_for_attribute_change(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'state', 'entity_id': 'test.entity', 'to': 'world', 'for': {'seconds': 5}}, 'action': {'service': 'test.automation'}}})
utcnow = dt_util.utcnow()
with patch('homeassistant.core.dt_util.utcnow') as mock_utcnow:
... |
'Test for firing on entity change with for.'
| def test_if_fires_on_entity_change_with_for(self):
| assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'state', 'entity_id': 'test.entity', 'to': 'world', 'for': {'seconds': 5}}, 'action': {'service': 'test.automation'}}})
self.hass.states.set('test.entity', 'world')
self.hass.block_till_done()
fire_time_cha... |
'Test for firing if contition is on.'
| def test_if_fires_on_for_condition(self):
| point1 = dt_util.utcnow()
point2 = (point1 + timedelta(seconds=10))
with patch('homeassistant.core.dt_util.utcnow') as mock_utcnow:
mock_utcnow.return_value = point1
self.hass.states.set('test.entity', 'on')
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'t... |
'Test for firing if contition is on with attribute change.'
| def test_if_fires_on_for_condition_attribute_change(self):
| point1 = dt_util.utcnow()
point2 = (point1 + timedelta(seconds=4))
point3 = (point1 + timedelta(seconds=8))
with patch('homeassistant.core.dt_util.utcnow') as mock_utcnow:
mock_utcnow.return_value = point1
self.hass.states.set('test.entity', 'on')
assert setup_component(self.hass... |
'Test for setup failure if no time is provided.'
| def test_if_fails_setup_for_without_time(self):
| with assert_setup_component(0):
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'platform': 'event', 'event_type': 'bla'}, 'condition': {'platform': 'state', 'entity_id': 'test.entity', 'state': 'on', 'for': {}}, 'action': {'service': 'test.automation'}}})
|
'Test for setup failure if no entity is provided.'
| def test_if_fails_setup_for_without_entity(self):
| with assert_setup_component(0):
assert setup_component(self.hass, automation.DOMAIN, {automation.DOMAIN: {'trigger': {'event_type': 'bla'}, 'condition': {'platform': 'state', 'state': 'on', 'for': {'seconds': 5}}, 'action': {'service': 'test.automation'}}})
|
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
|
'Stop down everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test setup with invalid configs.'
| def test_setup_with_invalid_configs(self):
| for value in ({'test': {}}, {'test hello world': {'sequence': [{'event': 'bla'}]}}, {'test': {'sequence': {'event': 'test_event', 'service': 'homeassistant.turn_on'}}}):
assert (not setup_component(self.hass, 'script', {'script': value})), 'Script loaded with wrong config {}'.format(val... |
'Verify that the turn_on service.'
| def test_turn_on_service(self):
| event = 'test_event'
events = []
@callback
def record_event(event):
'Add recorded event to set.'
events.append(event)
self.hass.bus.listen(event, record_event)
assert setup_component(self.hass, 'script', {'script': {'test': {'sequence': [{'delay': {'seconds': 5}}, {'e... |
'Test the toggling of a service.'
| def test_toggle_service(self):
| event = 'test_event'
events = []
@callback
def record_event(event):
'Add recorded event to set.'
events.append(event)
self.hass.bus.listen(event, record_event)
assert setup_component(self.hass, 'script', {'script': {'test': {'sequence': [{'delay': {'seconds': 5}}, {'e... |
'Test different ways of passing in variables.'
| def test_passing_variables(self):
| calls = []
@callback
def record_call(service):
'Add recorded event to set.'
calls.append(service)
self.hass.services.register('test', 'script', record_call)
assert setup_component(self.hass, 'script', {'script': {'test': {'sequence': {'service': 'test.script', 'data_templ... |
'Verify that the turn_on service.'
| def test_reload_service(self):
| assert setup_component(self.hass, 'script', {'script': {'test': {'sequence': [{'delay': {'seconds': 5}}]}}})
assert (self.hass.states.get(ENTITY_ID) is not None)
assert self.hass.services.has_service(script.DOMAIN, 'test')
with patch('homeassistant.config.load_yaml_config_file', return_value={'script': ... |
'Setup things to be run when tests are started.'
| def setup_method(self, method):
| self.hass = get_test_home_assistant()
self.hass.start()
self.hass.block_till_done()
|
'Stop everything that was started.'
| def teardown_method(self, method):
| self.hass.stop()
|
'Ensure it is ignored when unspecified.'
| def test_is_ignored_unspecified(self):
| self.hass.data['litejet_config'] = {}
assert (not litejet.is_ignored(self.hass, 'Test'))
|
'Ensure it is ignored when empty.'
| def test_is_ignored_empty(self):
| self.hass.data['litejet_config'] = {litejet.CONF_EXCLUDE_NAMES: []}
assert (not litejet.is_ignored(self.hass, 'Test'))
|
'Test if usually ignored.'
| def test_is_ignored_normal(self):
| self.hass.data['litejet_config'] = {litejet.CONF_EXCLUDE_NAMES: ['Test', 'Other One']}
assert litejet.is_ignored(self.hass, 'Test')
assert (not litejet.is_ignored(self.hass, 'Other one'))
assert (not litejet.is_ignored(self.hass, 'Other 0ne'))
assert litejet.is_ignored(self.hass, 'Other ... |
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test setup with all data.'
| def test_setup_config_full(self):
| config = {'splunk': {'host': 'host', 'port': 123, 'token': 'secret', 'ssl': 'False', 'name': 'hostname'}}
self.hass.bus.listen = mock.MagicMock()
self.assertTrue(setup_component(self.hass, splunk.DOMAIN, config))
self.assertTrue(self.hass.bus.listen.called)
self.assertEqual(EVENT_STATE_CHANGED, self... |
'Test setup with defaults.'
| def test_setup_config_defaults(self):
| config = {'splunk': {'host': 'host', 'token': 'secret'}}
self.hass.bus.listen = mock.MagicMock()
self.assertTrue(setup_component(self.hass, splunk.DOMAIN, config))
self.assertTrue(self.hass.bus.listen.called)
self.assertEqual(EVENT_STATE_CHANGED, self.hass.bus.listen.call_args_list[0][0][0])
|
'Test the setup.'
| def _setup(self, mock_requests):
| self.mock_post = mock_requests.post
self.mock_request_exception = Exception
mock_requests.exceptions.RequestException = self.mock_request_exception
config = {'splunk': {'host': 'host', 'token': 'secret', 'port': 8088}}
self.hass.bus.listen = mock.MagicMock()
setup_component(self.hass, splunk.DOM... |
'Test event listener.'
| @mock.patch.object(splunk, 'requests')
@mock.patch('json.dumps')
def test_event_listener(self, mock_dump, mock_requests):
| mock_dump.side_effect = (lambda x: x)
self._setup(mock_requests)
valid = {'1': 1, '1.0': 1.0, STATE_ON: 1, STATE_OFF: 0, 'foo': 'foo'}
for (in_, out) in valid.items():
state = mock.MagicMock(state=in_, domain='fake', object_id='entity', attributes={})
event = mock.MagicMock(data={'new_st... |
'Initialize values for this test case class.'
| def setUp(self):
| self.hass = get_test_home_assistant()
self.username = 'foo'
self.password = 'bar'
self.config = {'sleepiq': {'username': self.username, 'password': self.password}}
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test the setup.'
| @requests_mock.Mocker()
def test_setup(self, mock):
| mock_responses(mock)
with patch('homeassistant.helpers.discovery.load_platform', MagicMock()):
assert sleepiq.setup(self.hass, self.config)
|
'Test the setup if a bad username or password is given.'
| @requests_mock.Mocker()
def test_setup_login_failed(self, mock):
| mock.put('https://api.sleepiq.sleepnumber.com/rest/login', status_code=401, json=load_fixture('sleepiq-login-failed.json'))
response = sleepiq.setup(self.hass, self.config)
self.assertFalse(response)
|
'Test the setup when no login is configured.'
| def test_setup_component_no_login(self):
| conf = self.config.copy()
del conf['sleepiq']['username']
assert (not setup.setup_component(self.hass, sleepiq.DOMAIN, conf))
|
'Test the setup when no password is configured.'
| def test_setup_component_no_password(self):
| conf = self.config.copy()
del conf['sleepiq']['password']
assert (not setup.setup_component(self.hass, sleepiq.DOMAIN, conf))
|
'Setup things to be run when tests are started.'
| def setup_method(self, method):
| self.hass = get_test_home_assistant()
setup_component(self.hass, pn.DOMAIN, {})
|
'Stop everything that was started.'
| def teardown_method(self, method):
| self.hass.stop()
|
'Test creating notification without title or notification id.'
| def test_create(self):
| assert (len(self.hass.states.entity_ids(pn.DOMAIN)) == 0)
pn.create(self.hass, 'Hello World {{ 1 + 1 }}', title='{{ 1 + 1 }} beers')
self.hass.block_till_done()
entity_ids = self.hass.states.entity_ids(pn.DOMAIN)
assert (len(entity_ids) == 1)
state = self.hass.st... |
'Ensure overwrites existing notification with same id.'
| def test_create_notification_id(self):
| assert (len(self.hass.states.entity_ids(pn.DOMAIN)) == 0)
pn.create(self.hass, 'test', notification_id='Beer 2')
self.hass.block_till_done()
assert (len(self.hass.states.entity_ids()) == 1)
state = self.hass.states.get('persistent_notification.beer_2')
assert (state.state == 'test')
pn.cr... |
'Ensure we output templates if contain error.'
| def test_create_template_error(self):
| assert (len(self.hass.states.entity_ids(pn.DOMAIN)) == 0)
pn.create(self.hass, '{{ message + 1 }}', '{{ title + 1 }}')
self.hass.block_till_done()
entity_ids = self.hass.states.entity_ids(pn.DOMAIN)
assert (len(entity_ids) == 1)
state = self.hass.states.get(entity_ids[0])... |
'Ensure removal of specific notification.'
| def test_dismiss_notification(self):
| assert (len(self.hass.states.entity_ids(pn.DOMAIN)) == 0)
pn.create(self.hass, 'test', notification_id='Beer 2')
self.hass.block_till_done()
assert (len(self.hass.states.entity_ids(pn.DOMAIN)) == 1)
pn.dismiss(self.hass, notification_id='Beer 2')
self.hass.block_till_done()
assert (len... |
'Setup things to be run when tests are started.'
| def setup_method(self):
| self.hass = get_test_home_assistant()
self.mock_mqtt = mock_mqtt_component(self.hass)
|
'Stop everything that was started.'
| def teardown_method(self):
| self.hass.stop()
|
'Add a mqtt_eventstream component.'
| def add_eventstream(self, sub_topic=None, pub_topic=None):
| config = {}
if sub_topic:
config['subscribe_topic'] = sub_topic
if pub_topic:
config['publish_topic'] = pub_topic
return setup_component(self.hass, eventstream.DOMAIN, {eventstream.DOMAIN: config})
|
'"Test the success of the setup.'
| def test_setup_succeeds(self):
| assert self.add_eventstream()
|
'"Test the setup with subscription.'
| def test_setup_with_pub(self):
| assert (self.hass.bus.listeners.get('*') is None)
assert self.add_eventstream(pub_topic='bar')
self.hass.block_till_done()
assert (self.hass.bus.listeners.get('*') == 1)
|
'"Test the subscription.'
| @patch('homeassistant.components.mqtt.async_subscribe')
def test_subscribe(self, mock_sub):
| sub_topic = 'foo'
assert self.add_eventstream(sub_topic=sub_topic)
self.hass.block_till_done()
mock_sub.assert_called_with(self.hass, sub_topic, ANY)
|
'"Test the sending of a new message if event changed.'
| @patch('homeassistant.components.mqtt.async_publish')
@patch('homeassistant.core.dt_util.utcnow')
def test_state_changed_event_sends_message(self, mock_utcnow, mock_pub):
| now = dt_util.as_utc(dt_util.now())
e_id = 'fake.entity'
pub_topic = 'bar'
mock_utcnow.return_value = now
assert self.add_eventstream(pub_topic=pub_topic)
self.hass.block_till_done()
mock_pub.reset_mock()
mock_state_change_event(self.hass, State(e_id, 'on'))
self.hass.block_till_done... |
'"Test the sending of a new message if time event.'
| @patch('homeassistant.components.mqtt.async_publish')
def test_time_event_does_not_send_message(self, mock_pub):
| assert self.add_eventstream(pub_topic='bar')
self.hass.block_till_done()
mock_pub.reset_mock()
fire_time_changed(self.hass, dt_util.utcnow())
assert (not mock_pub.called)
|
'"Test the receiving of the remotely fired event.'
| def test_receiving_remote_event_fires_hass_event(self):
| sub_topic = 'foo'
assert self.add_eventstream(sub_topic=sub_topic)
self.hass.block_till_done()
calls = []
@callback
def listener(_):
calls.append(1)
self.hass.bus.listen_once('test_event', listener)
self.hass.block_till_done()
payload = json.dumps({'event_type': 'test_event',... |
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
|
'Stop everything that was started.'
| def tearDown(self):
| rfxtrx.RECEIVED_EVT_SUBSCRIBERS = []
rfxtrx.RFX_DEVICES = {}
if rfxtrx.RFXOBJECT:
rfxtrx.RFXOBJECT.close_connection()
self.hass.stop()
|
'Test configuration.'
| def test_default_config(self):
| self.assertTrue(setup_component(self.hass, 'rfxtrx', {'rfxtrx': {'device': ('/dev/serial/by-id/usb' + '-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0'), 'dummy': True}}))
self.assertTrue(setup_component(self.hass, 'sensor', {'sensor': {'platform': 'rfxtrx', 'automatic_add': True, 'devices': {}}}))
self.assertEqual(l... |
'Test configuration.'
| def test_valid_config(self):
| self.assertTrue(setup_component(self.hass, 'rfxtrx', {'rfxtrx': {'device': ('/dev/serial/by-id/usb' + '-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0'), 'dummy': True}}))
|
'Test configuration.'
| def test_valid_config2(self):
| self.assertTrue(setup_component(self.hass, 'rfxtrx', {'rfxtrx': {'device': ('/dev/serial/by-id/usb' + '-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0'), 'dummy': True, 'debug': True}}))
|
'Test configuration.'
| def test_invalid_config(self):
| self.assertFalse(setup_component(self.hass, 'rfxtrx', {'rfxtrx': {}}))
self.assertFalse(setup_component(self.hass, 'rfxtrx', {'rfxtrx': {'device': ('/dev/serial/by-id/usb' + '-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0'), 'invalid_key': True}}))
|
'Test fire event.'
| def test_fire_event(self):
| self.assertTrue(setup_component(self.hass, 'rfxtrx', {'rfxtrx': {'device': ('/dev/serial/by-id/usb' + '-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0'), 'dummy': True}}))
self.assertTrue(setup_component(self.hass, 'switch', {'switch': {'platform': 'rfxtrx', 'automatic_add': True, 'devices': {'0b1100cd0213c7f210010f51': ... |
'Test fire event.'
| def test_fire_event_sensor(self):
| self.assertTrue(setup_component(self.hass, 'rfxtrx', {'rfxtrx': {'device': ('/dev/serial/by-id/usb' + '-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0'), 'dummy': True}}))
self.assertTrue(setup_component(self.hass, 'sensor', {'sensor': {'platform': 'rfxtrx', 'automatic_add': True, 'devices': {'0a520802060100ff0e0269': {'... |
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test invalid configuration.'
| def test_invalid_config(self):
| with assert_setup_component(0):
assert (not setup_component(self.hass, datadog.DOMAIN, {datadog.DOMAIN: {'host1': 'host1'}}))
|
'Test setup with all data.'
| @MockDependency('datadog', 'beer')
def test_datadog_setup_full(self, mock_datadog):
| self.hass.bus.listen = mock.MagicMock()
mock_connection = mock_datadog.initialize
assert setup_component(self.hass, datadog.DOMAIN, {datadog.DOMAIN: {'host': 'host', 'port': 123, 'rate': 1, 'prefix': 'foo'}})
self.assertEqual(mock_connection.call_count, 1)
self.assertEqual(mock_connection.call_args,... |
'Test setup with defaults.'
| @MockDependency('datadog')
def test_datadog_setup_defaults(self, mock_datadog):
| self.hass.bus.listen = mock.MagicMock()
mock_connection = mock_datadog.initialize
assert setup_component(self.hass, datadog.DOMAIN, {datadog.DOMAIN: {'host': 'host', 'port': datadog.DEFAULT_PORT, 'prefix': datadog.DEFAULT_PREFIX}})
self.assertEqual(mock_connection.call_count, 1)
self.assertEqual(moc... |
'Test event listener.'
| @MockDependency('datadog')
def test_logbook_entry(self, mock_datadog):
| self.hass.bus.listen = mock.MagicMock()
mock_client = mock_datadog.statsd
assert setup_component(self.hass, datadog.DOMAIN, {datadog.DOMAIN: {'host': 'host', 'rate': datadog.DEFAULT_RATE}})
self.assertTrue(self.hass.bus.listen.called)
handler_method = self.hass.bus.listen.call_args_list[0][0][1]
... |
'Test event listener.'
| @MockDependency('datadog')
def test_state_changed(self, mock_datadog):
| self.hass.bus.listen = mock.MagicMock()
mock_client = mock_datadog.statsd
assert setup_component(self.hass, datadog.DOMAIN, {datadog.DOMAIN: {'host': 'host', 'prefix': 'ha', 'rate': datadog.DEFAULT_RATE}})
self.assertTrue(self.hass.bus.listen.called)
handler_method = self.hass.bus.listen.call_args_l... |
'Just return string for testing.'
| def _send_email(self, msg):
| return msg.as_string()
|
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
self.mailer = MockSMTP('localhost', 25, 5, 'test@test.com', 1, 'testuser', 'testpass', ['recip1@example.com', 'testrecip@test.com'], 'HomeAssistant', 0)
|
'"Stop down everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test build of default text email behavior.'
| @patch('email.utils.make_msgid', return_value='<mock@mock>')
def test_text_email(self, mock_make_msgid):
| msg = self.mailer.send_message('Test msg')
expected = '^Content-Type: text/plain; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\nSubject: Home Assistant\nTo: recip1@example.com,testrecip@test.com\nFrom: HomeAssistant <test@test.com>\nX-Mailer: HomeAssist... |
'Test build of mixed text email behavior.'
| @patch('email.utils.make_msgid', return_value='<mock@mock>')
def test_mixed_email(self, mock_make_msgid):
| msg = self.mailer.send_message('Test msg', data={'images': ['test.jpg']})
self.assertTrue(('Content-Type: multipart/related' in msg))
|
'Test build of html email behavior.'
| @patch('email.utils.make_msgid', return_value='<mock@mock>')
def test_html_email(self, mock_make_msgid):
| html = '\n <!DOCTYPE html>\n <html lang="en" xmlns="http://www.w3.org/1999/xhtml">\n <head><meta charset="UTF-8"></head>\n <body>\n ... |
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
|
'"Stop down everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test set up the platform with bad/missing config.'
| def test_bad_config(self):
| config = {notify.DOMAIN: {'name': 'test', 'platform': 'file'}}
with assert_setup_component(0) as handle_config:
assert setup_component(self.hass, notify.DOMAIN, config)
assert (not handle_config[notify.DOMAIN])
|
'Test the notify file output.'
| def _test_notify_file(self, timestamp, mock_utcnow, mock_stat):
| mock_utcnow.return_value = dt_util.as_utc(dt_util.now())
mock_stat.return_value.st_size = 0
m_open = mock_open()
with patch('homeassistant.components.notify.file.open', m_open, create=True):
filename = 'mock_file'
message = 'one, two, testing, testing'
with assert_setup_... |
'Test the notify file output without timestamp.'
| @patch('homeassistant.components.notify.file.os.stat')
@patch('homeassistant.util.dt.utcnow')
def test_notify_file(self, mock_utcnow, mock_stat):
| self._test_notify_file(False, mock_utcnow, mock_stat)
|
'Test the notify file output with timestamp.'
| @patch('homeassistant.components.notify.file.os.stat')
@patch('homeassistant.util.dt.utcnow')
def test_notify_file_timestamp(self, mock_utcnow, mock_stat):
| self._test_notify_file(True, mock_utcnow, mock_stat)
|
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test setup with all data.'
| @patch('os.path.isfile', return_value=True)
@patch('os.access', return_value=True)
def test_apns_setup_full(self, mock_access, mock_isfile):
| config = {'notify': {'platform': 'apns', 'name': 'test_app', 'sandbox': 'True', 'topic': 'testapp.appname', 'cert_file': 'test_app.pem'}}
with assert_setup_component(1) as handle_config:
assert setup_component(self.hass, notify.DOMAIN, config)
assert handle_config[notify.DOMAIN]
|
'Test setup with missing name.'
| def test_apns_setup_missing_name(self):
| config = {'notify': {'platform': 'apns', 'topic': 'testapp.appname', 'cert_file': 'test_app.pem'}}
with assert_setup_component(0) as handle_config:
assert setup_component(self.hass, notify.DOMAIN, config)
assert (not handle_config[notify.DOMAIN])
|
'Test setup with missing certificate.'
| def test_apns_setup_missing_certificate(self):
| config = {'notify': {'platform': 'apns', 'name': 'test_app', 'topic': 'testapp.appname'}}
with assert_setup_component(0) as handle_config:
assert setup_component(self.hass, notify.DOMAIN, config)
assert (not handle_config[notify.DOMAIN])
|
'Test setup with missing topic.'
| def test_apns_setup_missing_topic(self):
| config = {'notify': {'platform': 'apns', 'name': 'test_app', 'cert_file': 'test_app.pem'}}
with assert_setup_component(0) as handle_config:
assert setup_component(self.hass, notify.DOMAIN, config)
assert (not handle_config[notify.DOMAIN])
|
'Test registering a new device with a name.'
| @patch('homeassistant.components.notify.apns._write_device')
def test_register_new_device(self, mock_write):
| yaml_file = {5678: {'name': 'test device 2'}}
written_devices = []
def fake_write(_out, device):
'Fake write_device.'
written_devices.append(device)
mock_write.side_effect = fake_write
with patch('homeassistant.components.notify.apns.load_yaml_config_file', Mock(return_value... |
'Test registering a without a name.'
| @patch('homeassistant.components.notify.apns._write_device')
def test_register_device_without_name(self, mock_write):
| yaml_file = {1234: {'name': 'test device 1', 'tracking_device_id': 'tracking123'}, 5678: {'name': 'test device 2', 'tracking_device_id': 'tracking456'}}
written_devices = []
def fake_write(_out, device):
'Fake write_device.'
written_devices.append(device)
mock_write.side_e... |
'Test updating an existing device.'
| @patch('homeassistant.components.notify.apns._write_device')
def test_update_existing_device(self, mock_write):
| yaml_file = {1234: {'name': 'test device 1'}, 5678: {'name': 'test device 2'}}
written_devices = []
def fake_write(_out, device):
'Fake write_device.'
written_devices.append(device)
mock_write.side_effect = fake_write
with patch('homeassistant.components.notify.apns.lo... |
'Test updating an existing device that has a tracking id.'
| @patch('homeassistant.components.notify.apns._write_device')
def test_update_existing_device_with_tracking_id(self, mock_write):
| yaml_file = {1234: {'name': 'test device 1', 'tracking_device_id': 'tracking123'}, 5678: {'name': 'test device 2', 'tracking_device_id': 'tracking456'}}
written_devices = []
def fake_write(_out, device):
'Fake write_device.'
written_devices.append(device)
mock_write.side_e... |
'Test updating an existing device.'
| @patch('apns2.client.APNsClient')
def test_send(self, mock_client):
| send = mock_client.return_value.send_notification
yaml_file = {1234: {'name': 'test device 1'}}
with patch('homeassistant.components.notify.apns.load_yaml_config_file', Mock(return_value=yaml_file)):
self._setup_notify()
self.assertTrue(self.hass.services.call('notify', 'test_app', {'messa... |
'Test updating an existing device.'
| @patch('apns2.client.APNsClient')
def test_send_when_disabled(self, mock_client):
| send = mock_client.return_value.send_notification
yaml_file = {1234: {'name': 'test device 1', 'disabled': True}}
with patch('homeassistant.components.notify.apns.load_yaml_config_file', Mock(return_value=yaml_file)):
self._setup_notify()
self.assertTrue(self.hass.services.call('notify', '... |
'Test updating an existing device.'
| @patch('apns2.client.APNsClient')
def test_send_with_state(self, mock_client):
| send = mock_client.return_value.send_notification
yaml_file = {1234: {'name': 'test device 1', 'tracking_device_id': 'tracking123'}, 5678: {'name': 'test device 2', 'tracking_device_id': 'tracking456'}}
with patch('homeassistant.components.notify.apns.load_yaml_config_file', Mock(return_value=ya... |
'Test disabling a device when it is unregistered.'
| @patch('apns2.client.APNsClient')
@patch('homeassistant.components.notify.apns._write_device')
def test_disable_when_unregistered(self, mock_write, mock_client):
| send = mock_client.return_value.send_notification
send.side_effect = Unregistered()
yaml_file = {1234: {'name': 'test device 1', 'tracking_device_id': 'tracking123'}, 5678: {'name': 'test device 2', 'tracking_device_id': 'tracking456'}}
written_devices = []
def fake_write(_out, device):
... |
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
self.events = []
self.service1 = demo.DemoNotificationService(self.hass)
self.service2 = demo.DemoNotificationService(self.hass)
self.service1.send_message = MagicMock(autospec=True)
self.service2.send_message = MagicMock(autospec=True)
def mock_get_serv... |
'"Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test sending a message with to a notify group.'
| def test_send_message_with_data(self):
| run_coroutine_threadsafe(self.service.async_send_message('Hello', title='Test notification', data={'hello': 'world'}), self.hass.loop).result()
self.hass.block_till_done()
assert (self.service1.send_message.mock_calls[0][1][0] == 'Hello')
assert (self.service1.send_message.mock_calls[0][2] == {'title... |
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
self.events = []
self.calls = []
@callback
def record_event(event):
'Record event to send notification.'
self.events.append(event)
self.hass.bus.listen(demo.EVENT_NOTIFY, record_event)
|
'"Stop down everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test setup.'
| def test_setup(self):
| self._setup_notify()
|
'Test missing platform notify service instance.'
| @patch('homeassistant.components.notify.demo.get_service', autospec=True)
def test_no_notify_service(self, mock_demo_get_service):
| mock_demo_get_service.return_value = None
with self.assertLogs('homeassistant.components.notify', level='ERROR') as log_handle:
self._setup_notify()
self.hass.block_till_done()
assert mock_demo_get_service.called
self.assertEqual(log_handle.output, ['ERROR:homeassistant.components.notify:Fai... |
'Test discovery of notify demo platform.'
| @patch('homeassistant.components.notify.demo.get_service', autospec=True)
def test_discover_notify(self, mock_demo_get_service):
| assert (notify.DOMAIN not in self.hass.config.components)
discovery.load_platform(self.hass, 'notify', 'demo', {'test_key': 'test_val'}, {})
self.hass.block_till_done()
assert (notify.DOMAIN in self.hass.config.components)
assert mock_demo_get_service.called
assert (mock_demo_get_service.call_ar... |
'Helper for recording calls.'
| @callback
def record_calls(self, *args):
| self.calls.append(args)
|
'Test send with None as message.'
| def test_sending_none_message(self):
| self._setup_notify()
notify.send_message(self.hass, None)
self.hass.block_till_done()
self.assertTrue((len(self.events) == 0))
|
'Send a templated message.'
| def test_sending_templated_message(self):
| self._setup_notify()
self.hass.states.set('sensor.temperature', 10)
notify.send_message(self.hass, '{{ states.sensor.temperature.state }}', '{{ states.sensor.temperature.name }}')
self.hass.block_till_done()
last_event = self.events[(-1)]
self.assertEqual(last_event.data[notify.ATTR_... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.