Additional event data tests to cover recent bugs

This commit is contained in:
Adam Mills 2017-10-23 19:41:58 -04:00
parent d1424714c7
commit 5f8eb08cd9
No known key found for this signature in database
GPG Key ID: 7733DCD6D0428689

View File

@ -43,6 +43,31 @@ class TestAutomationEvent(unittest.TestCase):
}
})
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
automation.turn_off(self.hass)
self.hass.block_till_done()
self.hass.bus.fire('test_event')
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
def test_if_fires_on_event_extra_data(self):
"""Test the firing of events still matches with event data."""
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'event',
'event_type': 'test_event',
},
'action': {
'service': 'test.automation',
}
}
})
self.hass.bus.fire('test_event', {'extra_key': 'extra_data'})
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
@ -74,6 +99,30 @@ class TestAutomationEvent(unittest.TestCase):
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
def test_if_fires_on_event_with_empty_data_config(self):
"""Test the firing of events with empty data config.
The frontend automation editor can produce configurations with an
empty dict for event_data instead of no key.
"""
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'event',
'event_type': 'test_event',
'event_data': {}
},
'action': {
'service': 'test.automation',
}
}
})
self.hass.bus.fire('test_event', {'some_attr': 'some_value',
'another': 'value'})
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
def test_if_fires_on_event_with_nested_data(self):
"""Test the firing of events with nested data."""
assert setup_component(self.hass, automation.DOMAIN, {