hass-core/tests/components/thethingsnetwork/conftest.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

95 lines
2.2 KiB
Python

"""Define fixtures for the The Things Network tests."""
from unittest.mock import AsyncMock, patch
import pytest
from ttn_client import TTNSensorValue
from homeassistant.components.thethingsnetwork.const import (
CONF_APP_ID,
DOMAIN,
TTN_API_HOST,
)
from homeassistant.const import CONF_API_KEY, CONF_HOST
from tests.common import MockConfigEntry
HOST = "example.com"
APP_ID = "my_app"
API_KEY = "my_api_key"
DEVICE_ID = "my_device"
DEVICE_ID_2 = "my_device_2"
DEVICE_FIELD = "a_field"
DEVICE_FIELD_2 = "a_field_2"
DEVICE_FIELD_VALUE = 42
DATA = {
DEVICE_ID: {
DEVICE_FIELD: TTNSensorValue(
{
"end_device_ids": {"device_id": DEVICE_ID},
"received_at": "2024-03-11T08:49:11.153738893Z",
},
DEVICE_FIELD,
DEVICE_FIELD_VALUE,
)
}
}
DATA_UPDATE = {
DEVICE_ID: {
DEVICE_FIELD: TTNSensorValue(
{
"end_device_ids": {"device_id": DEVICE_ID},
"received_at": "2024-03-12T08:49:11.153738893Z",
},
DEVICE_FIELD,
DEVICE_FIELD_VALUE,
)
},
DEVICE_ID_2: {
DEVICE_FIELD_2: TTNSensorValue(
{
"end_device_ids": {"device_id": DEVICE_ID_2},
"received_at": "2024-03-12T08:49:11.153738893Z",
},
DEVICE_FIELD_2,
DEVICE_FIELD_VALUE,
)
},
}
@pytest.fixture
def mock_config_entry() -> MockConfigEntry:
"""Mock a config entry."""
return MockConfigEntry(
domain=DOMAIN,
unique_id=APP_ID,
title=APP_ID,
data={
CONF_APP_ID: APP_ID,
CONF_HOST: TTN_API_HOST,
CONF_API_KEY: API_KEY,
},
)
@pytest.fixture
def mock_ttnclient():
"""Mock TTNClient."""
with (
patch(
"homeassistant.components.thethingsnetwork.coordinator.TTNClient",
autospec=True,
) as ttn_client,
patch(
"homeassistant.components.thethingsnetwork.config_flow.TTNClient",
new=ttn_client,
),
):
instance = ttn_client.return_value
instance.fetch_data = AsyncMock(return_value=DATA)
yield ttn_client