hass-core/tests/components/thethingsnetwork/test_init.py
Angel Nunez Mencias b85cf36a68
Upgrade thethingsnetwork to v3 (#113375)
* thethingsnetwork upgrade to v3

* add en translations and requirements_all

* fix most of the findings

* hassfest

* use ttn_client v0.0.3

* reduce content of initial release

* remove features that trigger errors

* remove unneeded

* add initial testcases

* Exception warning

* add strict type checking

* add strict type checking

* full coverage

* rename to conftest

* review changes

* avoid using private attributes - use protected instead

* simplify config_flow

* remove unused options

* review changes

* upgrade client

* add types client library - no need to cast

* use add_suggested_values_to_schema

* add ruff fix

* review changes

* remove unneeded comment

* use typevar for TTN value

* use typevar for TTN value

* review

* ruff error not detected in local

* test review

* re-order fixture

* fix test

* reviews

* fix case

* split testcases

* review feedback

* Update homeassistant/components/thethingsnetwork/__init__.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update homeassistant/components/thethingsnetwork/__init__.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update tests/components/thethingsnetwork/test_config_flow.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Remove deprecated var

* Update tests/components/thethingsnetwork/test_config_flow.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Remove unused import

* fix ruff warning

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-05-26 16:30:33 +02:00

33 lines
1.1 KiB
Python

"""Define tests for the The Things Network init."""
import pytest
from ttn_client import TTNAuthError
from homeassistant.core import HomeAssistant
from homeassistant.helpers import issue_registry as ir
from homeassistant.setup import async_setup_component
from .conftest import DOMAIN
async def test_error_configuration(
hass: HomeAssistant,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test issue is logged when deprecated configuration is used."""
await async_setup_component(
hass, DOMAIN, {DOMAIN: {"app_id": "123", "access_key": "42"}}
)
await hass.async_block_till_done()
assert issue_registry.async_get_issue(DOMAIN, "manual_migration")
@pytest.mark.parametrize(("exception_class"), [TTNAuthError, Exception])
async def test_init_exceptions(
hass: HomeAssistant, mock_ttnclient, exception_class, mock_config_entry
) -> None:
"""Test TTN Exceptions."""
mock_ttnclient.return_value.fetch_data.side_effect = exception_class
mock_config_entry.add_to_hass(hass)
assert not await hass.config_entries.async_setup(mock_config_entry.entry_id)