Extract instance ID helper from updater (#35043)
This commit is contained in:
1 parent
b3e637ca7a
commit
e54e9279e3
8 files changed
+72
-37
No files matched your search
@@ -37,7 +37,7 @@ def mock_get_newest_version_fixture():
|
||||
@pytest.fixture(name="mock_get_uuid", autouse=True)
|
||||
def mock_get_uuid_fixture():
|
||||
"""Fixture to mock get_uuid."""
|
||||
with patch("homeassistant.components.updater._load_uuid") as mock:
|
||||
with patch("homeassistant.helpers.instance_id.async_get") as mock:
|
||||
yield mock
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
"""Tests for instance ID helper."""
|
||||
from tests.async_mock import patch
|
||||
|
||||
|
||||
async def test_get_id_empty(hass, hass_storage):
|
||||
"""Get unique ID."""
|
||||
uuid = await hass.helpers.instance_id.async_get()
|
||||
assert uuid is not None
|
||||
# Assert it's stored
|
||||
assert hass_storage["core.uuid"]["data"]["uuid"] == uuid
|
||||
|
||||
|
||||
async def test_get_id_migrate(hass, hass_storage):
|
||||
"""Migrate existing file."""
|
||||
with patch(
|
||||
"homeassistant.util.json.load_json", return_value={"uuid": "1234"}
|
||||
), patch("os.path.isfile", return_value=True), patch("os.remove") as mock_remove:
|
||||
uuid = await hass.helpers.instance_id.async_get()
|
||||
|
||||
assert uuid == "1234"
|
||||
|
||||
# Assert it's stored
|
||||
assert hass_storage["core.uuid"]["data"]["uuid"] == uuid
|
||||
|
||||
# assert old deleted
|
||||
assert len(mock_remove.mock_calls) == 1
|
||||
Reference in new issue
Block a user