Fix OTBR reset (#94157)

This commit is contained in:
Erik Montnemery 2023-06-07 18:42:40 +02:00 committed by Paulus Schoutsen
parent 93baf24394
commit e1c47fdb61
7 changed files with 46 additions and 6 deletions

View file

@ -84,6 +84,8 @@ async def test_create_network(
with patch(
"python_otbr_api.OTBR.create_active_dataset"
) as create_dataset_mock, patch(
"python_otbr_api.OTBR.delete_active_dataset"
) as delete_dataset_mock, patch(
"python_otbr_api.OTBR.set_enabled"
) as set_enabled_mock, patch(
"python_otbr_api.OTBR.get_active_dataset_tlvs", return_value=DATASET_CH16
@ -99,6 +101,7 @@ async def test_create_network(
create_dataset_mock.assert_called_once_with(
python_otbr_api.models.ActiveDataSet(channel=15, network_name="home-assistant")
)
delete_dataset_mock.assert_called_once_with()
assert len(set_enabled_mock.mock_calls) == 2
assert set_enabled_mock.mock_calls[0][1][0] is False
assert set_enabled_mock.mock_calls[1][1][0] is True
@ -151,7 +154,7 @@ async def test_create_network_fails_2(
), patch(
"python_otbr_api.OTBR.create_active_dataset",
side_effect=python_otbr_api.OTBRError,
):
), patch("python_otbr_api.OTBR.delete_active_dataset"):
await websocket_client.send_json_auto_id({"type": "otbr/create_network"})
msg = await websocket_client.receive_json()
@ -171,6 +174,8 @@ async def test_create_network_fails_3(
side_effect=[None, python_otbr_api.OTBRError],
), patch(
"python_otbr_api.OTBR.create_active_dataset",
), patch(
"python_otbr_api.OTBR.delete_active_dataset"
):
await websocket_client.send_json_auto_id({"type": "otbr/create_network"})
msg = await websocket_client.receive_json()
@ -191,6 +196,8 @@ async def test_create_network_fails_4(
), patch(
"python_otbr_api.OTBR.get_active_dataset_tlvs",
side_effect=python_otbr_api.OTBRError,
), patch(
"python_otbr_api.OTBR.delete_active_dataset"
):
await websocket_client.send_json_auto_id({"type": "otbr/create_network"})
msg = await websocket_client.receive_json()
@ -208,7 +215,9 @@ async def test_create_network_fails_5(
"""Test create network."""
with patch("python_otbr_api.OTBR.set_enabled"), patch(
"python_otbr_api.OTBR.create_active_dataset"
), patch("python_otbr_api.OTBR.get_active_dataset_tlvs", return_value=None):
), patch("python_otbr_api.OTBR.get_active_dataset_tlvs", return_value=None), patch(
"python_otbr_api.OTBR.delete_active_dataset"
):
await websocket_client.send_json_auto_id({"type": "otbr/create_network"})
msg = await websocket_client.receive_json()
@ -216,6 +225,26 @@ async def test_create_network_fails_5(
assert msg["error"]["code"] == "get_active_dataset_tlvs_empty"
async def test_create_network_fails_6(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
otbr_config_entry,
websocket_client,
) -> None:
"""Test create network."""
with patch("python_otbr_api.OTBR.set_enabled"), patch(
"python_otbr_api.OTBR.create_active_dataset"
), patch("python_otbr_api.OTBR.get_active_dataset_tlvs", return_value=None), patch(
"python_otbr_api.OTBR.delete_active_dataset",
side_effect=python_otbr_api.OTBRError,
):
await websocket_client.send_json_auto_id({"type": "otbr/create_network"})
msg = await websocket_client.receive_json()
assert not msg["success"]
assert msg["error"]["code"] == "delete_active_dataset_failed"
async def test_set_network(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,