This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

+28 -37
View File
@@ -12,46 +12,40 @@ from tests.common import MockConfigEntry, mock_coro
async def test_duplicate_error(hass):
"""Test that errors are shown when duplicates are added."""
conf = {
CONF_SENSOR_ID: '12345abcde',
}
conf = {CONF_SENSOR_ID: "12345abcde"}
MockConfigEntry(domain=DOMAIN, data=conf).add_to_hass(hass)
flow = config_flow.LuftDatenFlowHandler()
flow.hass = hass
result = await flow.async_step_user(user_input=conf)
assert result['errors'] == {CONF_SENSOR_ID: 'sensor_exists'}
assert result["errors"] == {CONF_SENSOR_ID: "sensor_exists"}
async def test_communication_error(hass):
"""Test that no sensor is added while unable to communicate with API."""
conf = {
CONF_SENSOR_ID: '12345abcde',
}
conf = {CONF_SENSOR_ID: "12345abcde"}
flow = config_flow.LuftDatenFlowHandler()
flow.hass = hass
with patch('luftdaten.Luftdaten.get_data', return_value=mock_coro(None)):
with patch("luftdaten.Luftdaten.get_data", return_value=mock_coro(None)):
result = await flow.async_step_user(user_input=conf)
assert result['errors'] == {CONF_SENSOR_ID: 'invalid_sensor'}
assert result["errors"] == {CONF_SENSOR_ID: "invalid_sensor"}
async def test_invalid_sensor(hass):
"""Test that an invalid sensor throws an error."""
conf = {
CONF_SENSOR_ID: '12345abcde',
}
conf = {CONF_SENSOR_ID: "12345abcde"}
flow = config_flow.LuftDatenFlowHandler()
flow.hass = hass
with patch('luftdaten.Luftdaten.get_data', return_value=mock_coro(False)),\
patch('luftdaten.Luftdaten.validate_sensor',
return_value=mock_coro(False)):
with patch("luftdaten.Luftdaten.get_data", return_value=mock_coro(False)), patch(
"luftdaten.Luftdaten.validate_sensor", return_value=mock_coro(False)
):
result = await flow.async_step_user(user_input=conf)
assert result['errors'] == {CONF_SENSOR_ID: 'invalid_sensor'}
assert result["errors"] == {CONF_SENSOR_ID: "invalid_sensor"}
async def test_show_form(hass):
@@ -61,29 +55,26 @@ async def test_show_form(hass):
result = await flow.async_step_user(user_input=None)
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
assert result['step_id'] == 'user'
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "user"
async def test_step_import(hass):
"""Test that the import step works."""
conf = {
CONF_SENSOR_ID: '12345abcde',
CONF_SHOW_ON_MAP: False,
}
conf = {CONF_SENSOR_ID: "12345abcde", CONF_SHOW_ON_MAP: False}
flow = config_flow.LuftDatenFlowHandler()
flow.hass = hass
with patch('luftdaten.Luftdaten.get_data', return_value=mock_coro(True)), \
patch('luftdaten.Luftdaten.validate_sensor',
return_value=mock_coro(True)):
with patch("luftdaten.Luftdaten.get_data", return_value=mock_coro(True)), patch(
"luftdaten.Luftdaten.validate_sensor", return_value=mock_coro(True)
):
result = await flow.async_step_import(import_config=conf)
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result['title'] == '12345abcde'
assert result['data'] == {
CONF_SENSOR_ID: '12345abcde',
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "12345abcde"
assert result["data"] == {
CONF_SENSOR_ID: "12345abcde",
CONF_SHOW_ON_MAP: False,
CONF_SCAN_INTERVAL: 600,
}
@@ -92,7 +83,7 @@ async def test_step_import(hass):
async def test_step_user(hass):
"""Test that the user step works."""
conf = {
CONF_SENSOR_ID: '12345abcde',
CONF_SENSOR_ID: "12345abcde",
CONF_SHOW_ON_MAP: False,
CONF_SCAN_INTERVAL: timedelta(minutes=5),
}
@@ -100,15 +91,15 @@ async def test_step_user(hass):
flow = config_flow.LuftDatenFlowHandler()
flow.hass = hass
with patch('luftdaten.Luftdaten.get_data', return_value=mock_coro(True)), \
patch('luftdaten.Luftdaten.validate_sensor',
return_value=mock_coro(True)):
with patch("luftdaten.Luftdaten.get_data", return_value=mock_coro(True)), patch(
"luftdaten.Luftdaten.validate_sensor", return_value=mock_coro(True)
):
result = await flow.async_step_user(user_input=conf)
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result['title'] == '12345abcde'
assert result['data'] == {
CONF_SENSOR_ID: '12345abcde',
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "12345abcde"
assert result["data"] == {
CONF_SENSOR_ID: "12345abcde",
CONF_SHOW_ON_MAP: False,
CONF_SCAN_INTERVAL: 300,
}
+8 -9
View File
@@ -10,13 +10,14 @@ from homeassistant.setup import async_setup_component
async def test_config_with_sensor_passed_to_config_entry(hass):
"""Test that configured options for a sensor are loaded."""
conf = {
CONF_SENSOR_ID: '12345abcde',
CONF_SENSOR_ID: "12345abcde",
CONF_SHOW_ON_MAP: False,
CONF_SCAN_INTERVAL: 600,
}
with patch.object(hass, 'config_entries') as mock_config_entries, \
patch.object(luftdaten, 'configured_sensors', return_value=[]):
with patch.object(hass, "config_entries") as mock_config_entries, patch.object(
luftdaten, "configured_sensors", return_value=[]
):
assert await async_setup_component(hass, DOMAIN, conf) is True
assert len(mock_config_entries.flow.mock_calls) == 0
@@ -24,13 +25,11 @@ async def test_config_with_sensor_passed_to_config_entry(hass):
async def test_config_already_registered_not_passed_to_config_entry(hass):
"""Test that an already registered sensor does not initiate an import."""
conf = {
CONF_SENSOR_ID: '12345abcde',
}
conf = {CONF_SENSOR_ID: "12345abcde"}
with patch.object(hass, 'config_entries') as mock_config_entries, \
patch.object(luftdaten, 'configured_sensors',
return_value=['12345abcde']):
with patch.object(hass, "config_entries") as mock_config_entries, patch.object(
luftdaten, "configured_sensors", return_value=["12345abcde"]
):
assert await async_setup_component(hass, DOMAIN, conf) is True
assert len(mock_config_entries.flow.mock_calls) == 0