1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Extract instance ID helper from updater (#35043)

This commit is contained in:
Paulus Schoutsen
2020-05-04 11:23:12 -07:00
committed by GitHub
parent b3e637ca7a
commit e54e9279e3
8 changed files with 72 additions and 37 deletions

View File

@@ -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