Check buckets/dbs for validity during Influx sensor startup (#37391)

* Check buckets/dbs for validity during sensor startup

* Empty array instead of none
This commit is contained in:
mdegat01 authored and GitHub committed 2020-07-08 15:37:43 -04:00
1 parent 9964bd40ed
commit d60c52bbc7
4 files changed
+73 -11

No files matched your search

+35
View File
@@ -551,3 +551,38 @@ async def test_connection_error_at_startup(
async_fire_time_changed(hass, new_time)
await hass.async_block_till_done()
assert hass.states.get(expected_sensor) is not None
@pytest.mark.parametrize(
"mock_client, config_ext, queries, set_query_mock",
[
(
DEFAULT_API_VERSION,
{"database": "bad_db"},
BASE_V1_QUERY,
_set_query_mock_v1,
),
(
API_VERSION_2,
{
"api_version": API_VERSION_2,
"organization": "org",
"token": "token",
"bucket": "bad_bucket",
},
BASE_V2_QUERY,
_set_query_mock_v2,
),
],
indirect=["mock_client"],
)
async def test_data_repository_not_found(
hass, caplog, mock_client, config_ext, queries, set_query_mock,
):
"""Test sensor is not setup when bucket not available."""
set_query_mock(mock_client)
await _setup(hass, config_ext, queries, [])
assert hass.states.get("sensor.test") is None
assert (
len([record for record in caplog.records if record.levelname == "ERROR"]) == 1
)