Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -7,8 +7,7 @@ from sqlalchemy import create_engine
|
||||
from sqlalchemy.pool import StaticPool
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components.recorder import (
|
||||
migration, const, models)
|
||||
from homeassistant.components.recorder import migration, const, models
|
||||
from tests.components.recorder import models_original
|
||||
|
||||
|
||||
@@ -24,19 +23,20 @@ def create_engine_test(*args, **kwargs):
|
||||
|
||||
async def test_schema_update_calls(hass):
|
||||
"""Test that schema migrations occur in correct order."""
|
||||
with patch('sqlalchemy.create_engine', new=create_engine_test), \
|
||||
patch('homeassistant.components.recorder.migration._apply_update') as \
|
||||
update:
|
||||
await async_setup_component(hass, 'recorder', {
|
||||
'recorder': {
|
||||
'db_url': 'sqlite://'
|
||||
}
|
||||
})
|
||||
with patch("sqlalchemy.create_engine", new=create_engine_test), patch(
|
||||
"homeassistant.components.recorder.migration._apply_update"
|
||||
) as update:
|
||||
await async_setup_component(
|
||||
hass, "recorder", {"recorder": {"db_url": "sqlite://"}}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
update.assert_has_calls([
|
||||
call(hass.data[const.DATA_INSTANCE].engine, version+1, 0) for version
|
||||
in range(0, models.SCHEMA_VERSION)])
|
||||
update.assert_has_calls(
|
||||
[
|
||||
call(hass.data[const.DATA_INSTANCE].engine, version + 1, 0)
|
||||
for version in range(0, models.SCHEMA_VERSION)
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
async def test_schema_migrate(hass):
|
||||
@@ -46,14 +46,12 @@ async def test_schema_migrate(hass):
|
||||
throwing exceptions. Maintaining a set of assertions based on schema
|
||||
inspection could quickly become quite cumbersome.
|
||||
"""
|
||||
with patch('sqlalchemy.create_engine', new=create_engine_test), \
|
||||
patch('homeassistant.components.recorder.Recorder._setup_run') as \
|
||||
setup_run:
|
||||
await async_setup_component(hass, 'recorder', {
|
||||
'recorder': {
|
||||
'db_url': 'sqlite://'
|
||||
}
|
||||
})
|
||||
with patch("sqlalchemy.create_engine", new=create_engine_test), patch(
|
||||
"homeassistant.components.recorder.Recorder._setup_run"
|
||||
) as setup_run:
|
||||
await async_setup_component(
|
||||
hass, "recorder", {"recorder": {"db_url": "sqlite://"}}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert setup_run.called
|
||||
|
||||
@@ -66,24 +64,14 @@ def test_invalid_update():
|
||||
|
||||
def test_forgiving_add_column():
|
||||
"""Test that add column will continue if column exists."""
|
||||
engine = create_engine(
|
||||
'sqlite://',
|
||||
poolclass=StaticPool
|
||||
)
|
||||
engine.execute('CREATE TABLE hello (id int)')
|
||||
migration._add_columns(engine, 'hello', [
|
||||
'context_id CHARACTER(36)',
|
||||
])
|
||||
migration._add_columns(engine, 'hello', [
|
||||
'context_id CHARACTER(36)',
|
||||
])
|
||||
engine = create_engine("sqlite://", poolclass=StaticPool)
|
||||
engine.execute("CREATE TABLE hello (id int)")
|
||||
migration._add_columns(engine, "hello", ["context_id CHARACTER(36)"])
|
||||
migration._add_columns(engine, "hello", ["context_id CHARACTER(36)"])
|
||||
|
||||
|
||||
def test_forgiving_add_index():
|
||||
"""Test that add index will continue if index exists."""
|
||||
engine = create_engine(
|
||||
'sqlite://',
|
||||
poolclass=StaticPool
|
||||
)
|
||||
engine = create_engine("sqlite://", poolclass=StaticPool)
|
||||
models.Base.metadata.create_all(engine)
|
||||
migration._create_index(engine, "states", "ix_states_context_id")
|
||||
Reference in new issue
Block a user