mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Collection of core tests improvements (#33757)
* Collection of core tests improvements * Added some more * Fix aiohttp client response release
This commit is contained in:
@@ -314,12 +314,10 @@ async def test_remove_entry_handles_callback_error(hass, manager):
|
||||
assert [item.entry_id for item in manager.async_entries()] == []
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_remove_entry_raises(hass, manager):
|
||||
async def test_remove_entry_raises(hass, manager):
|
||||
"""Test if a component raises while removing entry."""
|
||||
|
||||
@asyncio.coroutine
|
||||
def mock_unload_entry(hass, entry):
|
||||
async def mock_unload_entry(hass, entry):
|
||||
"""Mock unload entry function."""
|
||||
raise Exception("BROKEN")
|
||||
|
||||
@@ -337,14 +335,13 @@ def test_remove_entry_raises(hass, manager):
|
||||
"test3",
|
||||
]
|
||||
|
||||
result = yield from manager.async_remove("test2")
|
||||
result = await manager.async_remove("test2")
|
||||
|
||||
assert result == {"require_restart": True}
|
||||
assert [item.entry_id for item in manager.async_entries()] == ["test1", "test3"]
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_remove_entry_if_not_loaded(hass, manager):
|
||||
async def test_remove_entry_if_not_loaded(hass, manager):
|
||||
"""Test that we can remove an entry that is not loaded."""
|
||||
mock_unload_entry = MagicMock(return_value=mock_coro(True))
|
||||
|
||||
@@ -360,7 +357,7 @@ def test_remove_entry_if_not_loaded(hass, manager):
|
||||
"test3",
|
||||
]
|
||||
|
||||
result = yield from manager.async_remove("test2")
|
||||
result = await manager.async_remove("test2")
|
||||
|
||||
assert result == {"require_restart": False}
|
||||
assert [item.entry_id for item in manager.async_entries()] == ["test1", "test3"]
|
||||
@@ -368,8 +365,7 @@ def test_remove_entry_if_not_loaded(hass, manager):
|
||||
assert len(mock_unload_entry.mock_calls) == 0
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_add_entry_calls_setup_entry(hass, manager):
|
||||
async def test_add_entry_calls_setup_entry(hass, manager):
|
||||
"""Test we call setup_config_entry."""
|
||||
mock_setup_entry = MagicMock(return_value=mock_coro(True))
|
||||
|
||||
@@ -377,18 +373,19 @@ def test_add_entry_calls_setup_entry(hass, manager):
|
||||
mock_entity_platform(hass, "config_flow.comp", None)
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow):
|
||||
"""Test flow."""
|
||||
|
||||
VERSION = 1
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_step_user(self, user_input=None):
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Test user step."""
|
||||
return self.async_create_entry(title="title", data={"token": "supersecret"})
|
||||
|
||||
with patch.dict(config_entries.HANDLERS, {"comp": TestFlow, "beer": 5}):
|
||||
yield from manager.flow.async_init(
|
||||
await manager.flow.async_init(
|
||||
"comp", context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
yield from hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
p_hass, p_entry = mock_setup_entry.mock_calls[0][1]
|
||||
@@ -397,8 +394,7 @@ def test_add_entry_calls_setup_entry(hass, manager):
|
||||
assert p_entry.data == {"token": "supersecret"}
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_entries_gets_entries(manager):
|
||||
async def test_entries_gets_entries(manager):
|
||||
"""Test entries are filtered by domain."""
|
||||
MockConfigEntry(domain="test").add_to_manager(manager)
|
||||
entry1 = MockConfigEntry(domain="test2")
|
||||
@@ -409,8 +405,7 @@ def test_entries_gets_entries(manager):
|
||||
assert manager.async_entries("test2") == [entry1, entry2]
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_domains_gets_uniques(manager):
|
||||
async def test_domains_gets_uniques(manager):
|
||||
"""Test we only return each domain once."""
|
||||
MockConfigEntry(domain="test").add_to_manager(manager)
|
||||
MockConfigEntry(domain="test2").add_to_manager(manager)
|
||||
@@ -429,10 +424,13 @@ async def test_saving_and_loading(hass):
|
||||
mock_entity_platform(hass, "config_flow.test", None)
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow):
|
||||
"""Test flow."""
|
||||
|
||||
VERSION = 5
|
||||
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Test user step."""
|
||||
await self.async_set_unique_id("unique")
|
||||
return self.async_create_entry(title="Test Title", data={"token": "abcd"})
|
||||
|
||||
@@ -442,11 +440,13 @@ async def test_saving_and_loading(hass):
|
||||
)
|
||||
|
||||
class Test2Flow(config_entries.ConfigFlow):
|
||||
"""Test flow."""
|
||||
|
||||
VERSION = 3
|
||||
CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_PUSH
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_step_user(self, user_input=None):
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Test user step."""
|
||||
return self.async_create_entry(
|
||||
title="Test 2 Title", data={"username": "bla"}
|
||||
)
|
||||
@@ -528,9 +528,12 @@ async def test_discovery_notification(hass):
|
||||
with patch.dict(config_entries.HANDLERS):
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow, domain="test"):
|
||||
"""Test flow."""
|
||||
|
||||
VERSION = 5
|
||||
|
||||
async def async_step_discovery(self, user_input=None):
|
||||
"""Test discovery step."""
|
||||
if user_input is not None:
|
||||
return self.async_create_entry(
|
||||
title="Test Title", data={"token": "abcd"}
|
||||
@@ -560,9 +563,12 @@ async def test_discovery_notification_not_created(hass):
|
||||
await async_setup_component(hass, "persistent_notification", {})
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow):
|
||||
"""Test flow."""
|
||||
|
||||
VERSION = 5
|
||||
|
||||
async def async_step_discovery(self, user_input=None):
|
||||
"""Test discovery step."""
|
||||
return self.async_abort(reason="test")
|
||||
|
||||
with patch.dict(config_entries.HANDLERS, {"test": TestFlow}):
|
||||
@@ -685,11 +691,15 @@ async def test_entry_options(hass, manager):
|
||||
entry.add_to_manager(manager)
|
||||
|
||||
class TestFlow:
|
||||
"""Test flow."""
|
||||
|
||||
@staticmethod
|
||||
@callback
|
||||
def async_get_options_flow(config_entry):
|
||||
"""Test options flow."""
|
||||
|
||||
class OptionsFlowHandler(data_entry_flow.FlowHandler):
|
||||
pass
|
||||
"""Test options flow handler."""
|
||||
|
||||
return OptionsFlowHandler()
|
||||
|
||||
@@ -703,7 +713,6 @@ async def test_entry_options(hass, manager):
|
||||
await manager.options.async_finish_flow(flow, {"data": {"second": True}})
|
||||
|
||||
assert entry.data == {"first": True}
|
||||
|
||||
assert entry.options == {"second": True}
|
||||
|
||||
|
||||
@@ -1014,10 +1023,12 @@ async def test_unqiue_id_persisted(hass, manager):
|
||||
mock_entity_platform(hass, "config_flow.comp", None)
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow):
|
||||
"""Test flow."""
|
||||
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Test user step."""
|
||||
await self.async_set_unique_id("mock-unique-id")
|
||||
return self.async_create_entry(title="mock-title", data={})
|
||||
|
||||
@@ -1058,10 +1069,12 @@ async def test_unique_id_existing_entry(hass, manager):
|
||||
mock_entity_platform(hass, "config_flow.comp", None)
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow):
|
||||
"""Test flow."""
|
||||
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Test user step."""
|
||||
existing_entry = await self.async_set_unique_id("mock-unique-id")
|
||||
|
||||
assert existing_entry is not None
|
||||
@@ -1100,10 +1113,12 @@ async def test_unique_id_update_existing_entry(hass, manager):
|
||||
mock_entity_platform(hass, "config_flow.comp", None)
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow):
|
||||
"""Test flow."""
|
||||
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Test user step."""
|
||||
await self.async_set_unique_id("mock-unique-id")
|
||||
await self._abort_if_unique_id_configured(updates={"host": "1.1.1.1"})
|
||||
|
||||
@@ -1134,10 +1149,12 @@ async def test_unique_id_not_update_existing_entry(hass, manager):
|
||||
mock_entity_platform(hass, "config_flow.comp", None)
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow):
|
||||
"""Test flow."""
|
||||
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Test user step."""
|
||||
await self.async_set_unique_id("mock-unique-id")
|
||||
await self._abort_if_unique_id_configured(updates={"host": "0.0.0.0"})
|
||||
|
||||
@@ -1161,10 +1178,12 @@ async def test_unique_id_in_progress(hass, manager):
|
||||
mock_entity_platform(hass, "config_flow.comp", None)
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow):
|
||||
"""Test flow."""
|
||||
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Test user step."""
|
||||
await self.async_set_unique_id("mock-unique-id")
|
||||
return self.async_show_form(step_id="discovery")
|
||||
|
||||
@@ -1193,10 +1212,12 @@ async def test_finish_flow_aborts_progress(hass, manager):
|
||||
mock_entity_platform(hass, "config_flow.comp", None)
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow):
|
||||
"""Test flow."""
|
||||
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Test user step."""
|
||||
await self.async_set_unique_id("mock-unique-id", raise_on_progress=False)
|
||||
|
||||
if user_input is None:
|
||||
@@ -1228,10 +1249,12 @@ async def test_unique_id_ignore(hass, manager):
|
||||
mock_entity_platform(hass, "config_flow.comp", None)
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow):
|
||||
"""Test flow."""
|
||||
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Test user flow."""
|
||||
await self.async_set_unique_id("mock-unique-id")
|
||||
return self.async_show_form(step_id="discovery")
|
||||
|
||||
@@ -1268,10 +1291,12 @@ async def test_unignore_step_form(hass, manager):
|
||||
mock_entity_platform(hass, "config_flow.comp", None)
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow):
|
||||
"""Test flow."""
|
||||
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_unignore(self, user_input):
|
||||
"""Test unignore step."""
|
||||
unique_id = user_input["unique_id"]
|
||||
await self.async_set_unique_id(unique_id)
|
||||
return self.async_show_form(step_id="discovery")
|
||||
@@ -1310,10 +1335,12 @@ async def test_unignore_create_entry(hass, manager):
|
||||
mock_entity_platform(hass, "config_flow.comp", None)
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow):
|
||||
"""Test flow."""
|
||||
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_unignore(self, user_input):
|
||||
"""Test unignore step."""
|
||||
unique_id = user_input["unique_id"]
|
||||
await self.async_set_unique_id(unique_id)
|
||||
return self.async_create_entry(title="yo", data={})
|
||||
@@ -1355,6 +1382,7 @@ async def test_unignore_default_impl(hass, manager):
|
||||
mock_entity_platform(hass, "config_flow.comp", None)
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow):
|
||||
"""Test flow."""
|
||||
|
||||
VERSION = 1
|
||||
|
||||
@@ -1395,10 +1423,12 @@ async def test_partial_flows_hidden(hass, manager):
|
||||
pause_discovery = asyncio.Event()
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow):
|
||||
"""Test flow."""
|
||||
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_discovery(self, user_input):
|
||||
"""Test discovery step."""
|
||||
discovery_started.set()
|
||||
await pause_discovery.wait()
|
||||
return self.async_show_form(step_id="someform")
|
||||
|
||||
Reference in New Issue
Block a user