Propagate destination of watched folder moves (#70252)
This commit is contained in:
parent
9f15234b92
commit
22b8afe966
2 changed files with 59 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
|||
"""The tests for the folder_watcher component."""
|
||||
import os
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from homeassistant.components import folder_watcher
|
||||
|
@ -43,7 +44,9 @@ def test_event():
|
|||
hass = Mock()
|
||||
handler = folder_watcher.create_event_handler(["*"], hass)
|
||||
handler.on_created(
|
||||
Mock(is_directory=False, src_path="/hello/world.txt", event_type="created")
|
||||
SimpleNamespace(
|
||||
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
|
||||
|
@ -53,3 +56,39 @@ def test_event():
|
|||
"file": "world.txt",
|
||||
"folder": "/hello",
|
||||
}
|
||||
|
||||
|
||||
def test_move_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_moved(
|
||||
SimpleNamespace(
|
||||
is_directory=False,
|
||||
src_path="/hello/world.txt",
|
||||
dest_path="/hello/earth.txt",
|
||||
event_type="moved",
|
||||
)
|
||||
)
|
||||
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": "moved",
|
||||
"path": "/hello/world.txt",
|
||||
"dest_path": "/hello/earth.txt",
|
||||
"file": "world.txt",
|
||||
"dest_file": "earth.txt",
|
||||
"folder": "/hello",
|
||||
"dest_folder": "/hello",
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue