Fix Downloader test cases and error title (#114847)
* Fix test cases * Return value * isdir change * FIx test cases and error title * Removing patch * Tiny needless fine-tuning
This commit is contained in:
parent
d9dada4fb3
commit
85b453b86c
3 changed files with 17 additions and 26 deletions
|
@ -29,7 +29,7 @@ class DownloaderConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
try:
|
try:
|
||||||
await self._validate_input(user_input)
|
await self._validate_input(user_input)
|
||||||
except DirectoryDoesNotExist:
|
except DirectoryDoesNotExist:
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "directory_does_not_exist"
|
||||||
else:
|
else:
|
||||||
return self.async_create_entry(title=DEFAULT_NAME, data=user_input)
|
return self.async_create_entry(title=DEFAULT_NAME, data=user_input)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"cannot_connect": "The directory could not be reached. Please check your settings."
|
"directory_does_not_exist": "The directory could not be reached. Please check your settings."
|
||||||
},
|
},
|
||||||
"abort": {
|
"abort": {
|
||||||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]"
|
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]"
|
||||||
|
|
|
@ -5,7 +5,6 @@ from unittest.mock import patch
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.downloader.config_flow import DirectoryDoesNotExist
|
|
||||||
from homeassistant.components.downloader.const import CONF_DOWNLOAD_DIR, DOMAIN
|
from homeassistant.components.downloader.const import CONF_DOWNLOAD_DIR, DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -21,39 +20,35 @@ async def test_user_form(hass: HomeAssistant) -> None:
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": SOURCE_USER}
|
DOMAIN, context={"source": SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
user_input=CONFIG,
|
||||||
|
)
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
|
||||||
with patch(
|
with patch("os.path.isdir", return_value=False):
|
||||||
"homeassistant.components.downloader.async_setup_entry",
|
|
||||||
return_value=True,
|
|
||||||
):
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
user_input=CONFIG,
|
user_input=CONFIG,
|
||||||
)
|
)
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
assert result["step_id"] == "user"
|
||||||
with patch(
|
assert result["errors"] == {"base": "directory_does_not_exist"}
|
||||||
"homeassistant.components.downloader.config_flow.DownloaderConfigFlow._validate_input",
|
|
||||||
side_effect=DirectoryDoesNotExist,
|
|
||||||
):
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
|
||||||
assert result["step_id"] == "user"
|
|
||||||
assert result["errors"] == {"base": "cannot_connect"}
|
|
||||||
|
|
||||||
with (
|
with (
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.components.downloader.async_setup_entry", return_value=True
|
"homeassistant.components.downloader.async_setup_entry", return_value=True
|
||||||
),
|
),
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.components.downloader.config_flow.DownloaderConfigFlow._validate_input",
|
"os.path.isdir",
|
||||||
return_value=None,
|
return_value=True,
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
user_input=CONFIG,
|
user_input=CONFIG,
|
||||||
)
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
assert result["title"] == "Downloader"
|
assert result["title"] == "Downloader"
|
||||||
assert result["data"] == {"download_dir": "download_dir"}
|
assert result["data"] == {"download_dir": "download_dir"}
|
||||||
|
@ -66,7 +61,6 @@ async def test_single_instance_allowed(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test we abort if already setup."""
|
"""Test we abort if already setup."""
|
||||||
mock_config_entry = MockConfigEntry(domain=DOMAIN)
|
mock_config_entry = MockConfigEntry(domain=DOMAIN)
|
||||||
|
|
||||||
mock_config_entry.add_to_hass(hass)
|
mock_config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -84,21 +78,19 @@ async def test_import_flow_success(hass: HomeAssistant) -> None:
|
||||||
"homeassistant.components.downloader.async_setup_entry", return_value=True
|
"homeassistant.components.downloader.async_setup_entry", return_value=True
|
||||||
),
|
),
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.components.downloader.config_flow.DownloaderConfigFlow._validate_input",
|
"os.path.isdir",
|
||||||
return_value=None,
|
return_value=True,
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_IMPORT},
|
context={"source": config_entries.SOURCE_IMPORT},
|
||||||
data={},
|
data=CONFIG,
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
assert result["title"] == "Downloader"
|
assert result["title"] == "Downloader"
|
||||||
assert result["data"] == {}
|
assert result["data"] == CONFIG
|
||||||
assert result["options"] == {}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_import_flow_directory_not_found(hass: HomeAssistant) -> None:
|
async def test_import_flow_directory_not_found(hass: HomeAssistant) -> None:
|
||||||
|
@ -112,6 +104,5 @@ async def test_import_flow_directory_not_found(hass: HomeAssistant) -> None:
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result["reason"] == "directory_does_not_exist"
|
assert result["reason"] == "directory_does_not_exist"
|
||||||
|
|
Loading…
Add table
Reference in a new issue