mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Add tests for version upgrade
This commit is contained in:
parent
700b7ba591
commit
0f68dc6b7b
@ -5,11 +5,13 @@ tests.test_bootstrap
|
|||||||
Tests bootstrap.
|
Tests bootstrap.
|
||||||
"""
|
"""
|
||||||
# pylint: disable=too-many-public-methods,protected-access
|
# pylint: disable=too-many-public-methods,protected-access
|
||||||
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from homeassistant import bootstrap
|
from homeassistant import core, bootstrap
|
||||||
|
from homeassistant.const import __version__
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
from tests.common import mock_detect_location_info
|
from tests.common import mock_detect_location_info
|
||||||
@ -39,3 +41,45 @@ class TestBootstrap(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(sorted(components),
|
self.assertEqual(sorted(components),
|
||||||
sorted(hass.config.components))
|
sorted(hass.config.components))
|
||||||
|
|
||||||
|
def test_remove_lib_on_upgrade(self):
|
||||||
|
with tempfile.TemporaryDirectory() as config_dir:
|
||||||
|
version_path = os.path.join(config_dir, '.HA_VERSION')
|
||||||
|
lib_dir = os.path.join(config_dir, 'lib')
|
||||||
|
check_file = os.path.join(lib_dir, 'check')
|
||||||
|
|
||||||
|
with open(version_path, 'wt') as outp:
|
||||||
|
outp.write('0.7.0')
|
||||||
|
|
||||||
|
os.mkdir(lib_dir)
|
||||||
|
|
||||||
|
with open(check_file, 'w'):
|
||||||
|
pass
|
||||||
|
|
||||||
|
hass = core.HomeAssistant()
|
||||||
|
hass.config.config_dir = config_dir
|
||||||
|
|
||||||
|
self.assertTrue(os.path.isfile(check_file))
|
||||||
|
bootstrap.process_ha_config_upgrade(hass)
|
||||||
|
self.assertFalse(os.path.isfile(check_file))
|
||||||
|
|
||||||
|
def test_not_remove_lib_if_not_upgrade(self):
|
||||||
|
with tempfile.TemporaryDirectory() as config_dir:
|
||||||
|
version_path = os.path.join(config_dir, '.HA_VERSION')
|
||||||
|
lib_dir = os.path.join(config_dir, 'lib')
|
||||||
|
check_file = os.path.join(lib_dir, 'check')
|
||||||
|
|
||||||
|
with open(version_path, 'wt') as outp:
|
||||||
|
outp.write(__version__)
|
||||||
|
|
||||||
|
os.mkdir(lib_dir)
|
||||||
|
|
||||||
|
with open(check_file, 'w'):
|
||||||
|
pass
|
||||||
|
|
||||||
|
hass = core.HomeAssistant()
|
||||||
|
hass.config.config_dir = config_dir
|
||||||
|
|
||||||
|
bootstrap.process_ha_config_upgrade(hass)
|
||||||
|
|
||||||
|
self.assertTrue(os.path.isfile(check_file))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user