Await block till done inside patched config entry in tests (#89515)

This commit is contained in:
Paulus Schoutsen 2023-03-10 11:42:53 -05:00 committed by GitHub
parent 96bd714364
commit d6a223f0e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 17 additions and 16 deletions

View File

@ -33,12 +33,12 @@ async def test_form(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) ->
result1["flow_id"],
USER_INPUT,
)
await hass.async_block_till_done()
assert len(aioclient_mock.mock_calls) == 1
assert result2["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert result2["title"] == "testname"
assert result2["data"] == USER_INPUT
await hass.async_block_till_done()
assert len(mock_setup_entry.mock_calls) == 1
# Test Duplicate Config Flow

View File

@ -187,11 +187,11 @@ async def test_user_form_one_entry_per_device_allowed(hass: HomeAssistant) -> No
result["flow_id"],
{CONF_HOST: "some host", CONF_ACCESS_TOKEN: "test-token"},
)
await hass.async_block_till_done()
assert result2["type"] == "abort"
assert result2["reason"] == "already_configured"
await hass.async_block_till_done()
assert len(mock_setup_entry.mock_calls) == 0

View File

@ -33,11 +33,11 @@ async def test_form(hass: HomeAssistant) -> None:
result["flow_id"],
{CONF_HOST: "1.1.1.1", CONF_NAME: "test-epson"},
)
await hass.async_block_till_done()
assert result2["type"] == "create_entry"
assert result2["title"] == "test-epson"
assert result2["data"] == {CONF_HOST: "1.1.1.1"}
await hass.async_block_till_done()
assert len(mock_setup_entry.mock_calls) == 1

View File

@ -37,13 +37,13 @@ async def test_form(hass: HomeAssistant) -> None:
"id": "test",
},
)
await hass.async_block_till_done()
assert result2["type"] == "create_entry"
assert result2["title"] == "Test airport"
assert result2["data"] == {
"id": "test",
}
await hass.async_block_till_done()
assert len(mock_setup_entry.mock_calls) == 1

View File

@ -37,6 +37,7 @@ async def test_form(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
"password": "test-password",
},
)
await hass.async_block_till_done()
assert result2["type"] == "create_entry"
assert result2["title"] == "1.1.1.1"
@ -45,7 +46,6 @@ async def test_form(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
"username": "test-username",
"password": "test-password",
}
await hass.async_block_till_done()
assert len(mock_setup_entry.mock_calls) == 1

View File

@ -47,6 +47,7 @@ async def test_formx(hass: HomeAssistant) -> None:
"password": "test-password",
},
)
await hass.async_block_till_done()
mock_api_class.assert_called_once_with(ANY, "1.1.1.1")
mock_api.__aenter__.assert_called_once()
@ -60,7 +61,6 @@ async def test_formx(hass: HomeAssistant) -> None:
"host": "1.1.1.1",
"password": "test-password",
}
await hass.async_block_till_done()
assert len(mock_setup_entry.mock_calls) == 1

View File

@ -60,10 +60,10 @@ async def test_flow_no_devices_found(hass: HomeAssistant) -> None:
result["flow_id"],
{},
)
await hass.async_block_till_done()
assert result2["type"] == "abort"
assert result2["reason"] == "no_devices_found"
await hass.async_block_till_done()
assert len(mock_setup_entry.mock_calls) == 0
@ -87,8 +87,8 @@ async def test_flow_exceptions_caught(hass: HomeAssistant) -> None:
result["flow_id"],
{},
)
await hass.async_block_till_done()
assert result2["type"] == "abort"
assert result2["reason"] == "no_devices_found"
await hass.async_block_till_done()
assert len(mock_setup_entry.mock_calls) == 0

View File

@ -67,13 +67,13 @@ async def test_bridge_import_flow(hass: HomeAssistant) -> None:
context={"source": config_entries.SOURCE_IMPORT},
data=entry_mock_data,
)
await hass.async_block_till_done()
assert result["type"] == "create_entry"
assert result["title"] == CasetaConfigFlow.ENTRY_DEFAULT_TITLE
assert result["data"] == entry_mock_data
assert result["result"].unique_id == "000004d2"
await hass.async_block_till_done()
assert len(mock_setup_entry.mock_calls) == 1

View File

@ -381,6 +381,8 @@ async def test_import_discovery_integration(
type=type_in_discovery,
),
)
await hass.async_block_till_done()
assert result["type"] == "create_entry"
assert result["title"] == TEST_NAME
assert result["data"] == {
@ -395,7 +397,6 @@ async def test_import_discovery_integration(
mock_save_json.assert_called_once()
mock_remove.assert_not_called()
await hass.async_block_till_done()
assert len(mock_setup_entry.mock_calls) == 1
@ -431,6 +432,7 @@ async def test_ssdp_discovery(hass: HomeAssistant) -> None:
assert result["step_id"] == "link"
result2 = await hass.config_entries.flow.async_configure(result["flow_id"], {})
await hass.async_block_till_done()
assert result2["type"] == "create_entry"
assert result2["title"] == TEST_NAME
@ -439,5 +441,4 @@ async def test_ssdp_discovery(hass: HomeAssistant) -> None:
CONF_TOKEN: TEST_TOKEN,
}
await hass.async_block_till_done()
assert len(mock_setup_entry.mock_calls) == 1

View File

@ -108,7 +108,8 @@ async def test_form_already_configured(
result["flow_id"],
{"api_key": "test"},
)
await hass.async_block_till_done()
assert result2["type"] == "abort"
assert result2["reason"] == "already_configured"
await hass.async_block_till_done()
assert len(mock_setup_entry.mock_calls) == 0

View File

@ -76,7 +76,8 @@ async def test_user_flow(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> No
CONF_HOST: "1.2.3.4",
CONF_PORT: 1234,
}
await hass.async_block_till_done()
await hass.async_block_till_done()
assert len(mock_setup_entry.mock_calls) == 1
@ -102,8 +103,6 @@ async def test_user_duplicate(
)
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "already_configured"
await hass.async_block_till_done()
assert len(mock_setup_entry.mock_calls) == 1
@pytest.mark.usefixtures("filled_device_registry")

View File

@ -119,10 +119,10 @@ async def test_success(
context={"source": config_entries.SOURCE_USER},
data=FIXTURE_USER_INPUT,
)
await hass.async_block_till_done()
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert result["data"][CONF_URL] == FIXTURE_USER_INPUT[CONF_URL]
await hass.async_block_till_done()
assert len(mock_setup_entry.mock_calls) == 1