def test_event(mock_watchdog): """Check that HASS events are fired correctly on watchdog event.""" class MockPatternMatchingEventHandler: """Mock base class for the pattern matcher event handler.""" def __init__(self, patterns): pass mock_watchdog.events.PatternMatchingEventHandler = \ MockPatternMatchingEventHandler hass = Mock() handler = folder_watcher.create_event_handler(['*'], hass) handler.on_created(Mock( is_directory=False, src_path='/hello/world.txt', event_type='created' )) assert hass.bus.fire.called assert hass.bus.fire.mock_calls[0][1][0] == folder_watcher.DOMAIN assert hass.bus.fire.mock_calls[0][1][1] == { 'event_type': 'created', 'path': '/hello/world.txt', 'file': 'world.txt', 'folder': '/hello', }
def test_event(): """Check that Home Assistant events are fired correctly on watchdog event.""" class MockPatternMatchingEventHandler: """Mock base class for the pattern matcher event handler.""" def __init__(self, patterns): pass with patch( "homeassistant.components.folder_watcher.PatternMatchingEventHandler", MockPatternMatchingEventHandler, ): hass = Mock() handler = folder_watcher.create_event_handler(["*"], hass) handler.on_created( Mock(is_directory=False, src_path="/hello/world.txt", event_type="created")) assert hass.bus.fire.called assert hass.bus.fire.mock_calls[0][1][0] == folder_watcher.DOMAIN assert hass.bus.fire.mock_calls[0][1][1] == { "event_type": "created", "path": "/hello/world.txt", "file": "world.txt", "folder": "/hello", }
def test_event(self): """Check that HASS events are fired correctly on watchdog event.""" fake_hass = Mock() event_handler = folder_watcher.create_event_handler( [folder_watcher.DEFAULT_PATTERN], fake_hass) fake_event = get_fake_event() event_handler.process(fake_event) expected_payload = { "event_type": fake_event.event_type, 'path': fake_event.src_path, 'file': FILE, 'folder': FOLDER } fake_hass.bus.fire.assert_called_with(folder_watcher.DOMAIN, expected_payload)