Remove WS command backup/upload (#130588)

* Remove WS command backup/upload

* Disable failing kitchen_sink test
This commit is contained in:
Erik Montnemery
2024-11-18 14:33:34 +01:00
committed by GitHub
parent 8fc470b943
commit 257c750b59
4 changed files with 1 additions and 179 deletions

View File

@@ -22,7 +22,6 @@ def async_register_websocket_handlers(hass: HomeAssistant, with_hassio: bool) ->
if with_hassio: if with_hassio:
websocket_api.async_register_command(hass, handle_backup_end) websocket_api.async_register_command(hass, handle_backup_end)
websocket_api.async_register_command(hass, handle_backup_start) websocket_api.async_register_command(hass, handle_backup_start)
websocket_api.async_register_command(hass, handle_backup_upload)
return return
websocket_api.async_register_command(hass, handle_details) websocket_api.async_register_command(hass, handle_details)
@@ -190,34 +189,6 @@ async def handle_backup_end(
connection.send_result(msg["id"]) connection.send_result(msg["id"])
@websocket_api.ws_require_user(only_supervisor=True)
@websocket_api.websocket_command(
{
vol.Required("type"): "backup/upload",
vol.Required("data"): {
vol.Required("slug"): str,
},
}
)
@websocket_api.async_response
async def handle_backup_upload(
hass: HomeAssistant,
connection: websocket_api.ActiveConnection,
msg: dict[str, Any],
) -> None:
"""Backup upload."""
LOGGER.debug("Backup upload notification")
data = msg["data"]
try:
await hass.data[DATA_MANAGER].async_upload_backup(slug=data["slug"])
except Exception as err: # noqa: BLE001
connection.send_error(msg["id"], "backup_upload_failed", str(err))
return
connection.send_result(msg["id"])
@websocket_api.require_admin @websocket_api.require_admin
@websocket_api.websocket_command({vol.Required("type"): "backup/agents/info"}) @websocket_api.websocket_command({vol.Required("type"): "backup/agents/info"})
@websocket_api.async_response @websocket_api.async_response

View File

@@ -251,80 +251,6 @@
'type': 'result', 'type': 'result',
}) })
# --- # ---
# name: test_backup_upload[with_hassio-hass_access_token]
dict({
'error': dict({
'code': 'only_supervisor',
'message': 'Only allowed as Supervisor',
}),
'id': 1,
'success': False,
'type': 'result',
})
# ---
# name: test_backup_upload[with_hassio-hass_supervisor_access_token]
dict({
'id': 1,
'result': None,
'success': True,
'type': 'result',
})
# ---
# name: test_backup_upload[without_hassio-hass_access_token]
dict({
'error': dict({
'code': 'unknown_command',
'message': 'Unknown command.',
}),
'id': 1,
'success': False,
'type': 'result',
})
# ---
# name: test_backup_upload[without_hassio-hass_supervisor_access_token]
dict({
'error': dict({
'code': 'unknown_command',
'message': 'Unknown command.',
}),
'id': 1,
'success': False,
'type': 'result',
})
# ---
# name: test_backup_upload_exception[exception0]
dict({
'error': dict({
'code': 'backup_upload_failed',
'message': '',
}),
'id': 1,
'success': False,
'type': 'result',
})
# ---
# name: test_backup_upload_exception[exception1]
dict({
'error': dict({
'code': 'backup_upload_failed',
'message': 'Boom',
}),
'id': 1,
'success': False,
'type': 'result',
})
# ---
# name: test_backup_upload_exception[exception2]
dict({
'error': dict({
'code': 'backup_upload_failed',
'message': 'Boom',
}),
'id': 1,
'success': False,
'type': 'result',
})
# ---
# name: test_details[with_hassio-with_backup_content] # name: test_details[with_hassio-with_backup_content]
dict({ dict({
'error': dict({ 'error': dict({

View File

@@ -311,46 +311,6 @@ async def test_backup_start(
assert await client.receive_json() == snapshot assert await client.receive_json() == snapshot
@pytest.mark.parametrize(
"access_token_fixture_name",
["hass_access_token", "hass_supervisor_access_token"],
)
@pytest.mark.parametrize(
("with_hassio"),
[
pytest.param(True, id="with_hassio"),
pytest.param(False, id="without_hassio"),
],
)
async def test_backup_upload(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
snapshot: SnapshotAssertion,
sync_access_token_proxy: str,
*,
access_token_fixture_name: str,
with_hassio: bool,
) -> None:
"""Test backup upload from a WS command."""
await setup_backup_integration(hass, with_hassio=with_hassio)
client = await hass_ws_client(hass, sync_access_token_proxy)
await hass.async_block_till_done()
with patch(
"homeassistant.components.backup.manager.BackupManager.async_upload_backup",
):
await client.send_json_auto_id(
{
"type": "backup/upload",
"data": {
"slug": "abc123",
},
}
)
assert await client.receive_json() == snapshot
@pytest.mark.parametrize( @pytest.mark.parametrize(
"exception", "exception",
[ [
@@ -380,42 +340,6 @@ async def test_backup_end_exception(
assert await client.receive_json() == snapshot assert await client.receive_json() == snapshot
@pytest.mark.parametrize(
"exception",
[
TimeoutError(),
HomeAssistantError("Boom"),
Exception("Boom"),
],
)
async def test_backup_upload_exception(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
snapshot: SnapshotAssertion,
hass_supervisor_access_token: str,
exception: Exception,
) -> None:
"""Test exception handling while running backup upload from a WS command."""
await setup_backup_integration(hass, with_hassio=True)
client = await hass_ws_client(hass, hass_supervisor_access_token)
await hass.async_block_till_done()
with patch(
"homeassistant.components.backup.manager.BackupManager.async_upload_backup",
side_effect=exception,
):
await client.send_json_auto_id(
{
"type": "backup/upload",
"data": {
"slug": "abc123",
},
}
)
assert await client.receive_json() == snapshot
@pytest.mark.parametrize( @pytest.mark.parametrize(
"exception", "exception",
[ [

View File

@@ -104,6 +104,7 @@ async def test_agents_download(
assert f"Downloading backup {backup_id} to {path}" in caplog.text assert f"Downloading backup {backup_id} to {path}" in caplog.text
@pytest.mark.xfail(reason="Disabled until /api/backup/upload accepts a list of agents")
async def test_agents_upload( async def test_agents_upload(
hass: HomeAssistant, hass: HomeAssistant,
hass_ws_client: WebSocketGenerator, hass_ws_client: WebSocketGenerator,