mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Add bring integration (#108027)
* add bring integration * fix typings and remove from strictly typed - wait for python-bring-api to be ready for strictly typed * make entity unique to user and list - before it was only list, therefore the same list imported by two users would have failed * simplify bring attribute Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * cleanup and code simplification * remove empty fields in manifest * __init__.py aktualisieren Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * __init__.py aktualisieren Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * strings.json aktualisieren Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * streamline async calls * use coordinator refresh * fix order in update call and simplify bring list * simplify the config_flow * Update homeassistant/components/bring/manifest.json Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com> * add unit testing for __init__.py * cleanup comments * use dict instead of list * Update homeassistant/components/bring/todo.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * clean up * update attribute name * update more attribute name * improve unit tests - remove patch and use mock in conftest * clean up tests even more * more unit test inprovements * remove optional type * minor unit test cleanup * Update .coveragerc Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
This commit is contained in:
111
tests/components/bring/test_config_flow.py
Normal file
111
tests/components/bring/test_config_flow.py
Normal file
@@ -0,0 +1,111 @@
|
||||
"""Test the Bring! config flow."""
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
|
||||
import pytest
|
||||
from python_bring_api.exceptions import (
|
||||
BringAuthException,
|
||||
BringParseException,
|
||||
BringRequestException,
|
||||
)
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.bring.const import DOMAIN
|
||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from .conftest import EMAIL, PASSWORD
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
MOCK_DATA_STEP = {
|
||||
CONF_EMAIL: EMAIL,
|
||||
CONF_PASSWORD: PASSWORD,
|
||||
}
|
||||
|
||||
|
||||
async def test_form(
|
||||
hass: HomeAssistant, mock_setup_entry: AsyncMock, mock_bring_client: Mock
|
||||
) -> None:
|
||||
"""Test we get the form."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["errors"] == {}
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": "user"}
|
||||
)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input=MOCK_DATA_STEP,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == MOCK_DATA_STEP["email"]
|
||||
assert result["data"] == MOCK_DATA_STEP
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("raise_error", "text_error"),
|
||||
[
|
||||
(BringRequestException(), "cannot_connect"),
|
||||
(BringAuthException(), "invalid_auth"),
|
||||
(BringParseException(), "unknown"),
|
||||
(IndexError(), "unknown"),
|
||||
],
|
||||
)
|
||||
async def test_flow_user_init_data_unknown_error_and_recover(
|
||||
hass: HomeAssistant, mock_bring_client: Mock, raise_error, text_error
|
||||
) -> None:
|
||||
"""Test unknown errors."""
|
||||
mock_bring_client.login.side_effect = raise_error
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": "user"}
|
||||
)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input=MOCK_DATA_STEP,
|
||||
)
|
||||
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["errors"]["base"] == text_error
|
||||
|
||||
# Recover
|
||||
mock_bring_client.login.side_effect = None
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": "user"}
|
||||
)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input=MOCK_DATA_STEP,
|
||||
)
|
||||
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["result"].title == MOCK_DATA_STEP["email"]
|
||||
|
||||
assert result["data"] == MOCK_DATA_STEP
|
||||
|
||||
|
||||
async def test_flow_user_init_data_already_configured(
|
||||
hass: HomeAssistant, mock_bring_client: Mock, bring_config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test we abort user data set when entry is already configured."""
|
||||
|
||||
bring_config_entry.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": "user"}
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input=MOCK_DATA_STEP,
|
||||
)
|
||||
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
Reference in New Issue
Block a user