Improve backup store in tests (#135798)

This commit is contained in:
Erik Montnemery 2025-01-16 23:14:19 +01:00 committed by GitHub
parent ef34a33a7b
commit 1fee0a5aa2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 105 additions and 89 deletions

View File

@ -227,7 +227,7 @@
'type': 'result',
})
# ---
# name: test_config_info[None]
# name: test_config_info[storage_data0]
dict({
'id': 1,
'result': dict({

View File

@ -848,11 +848,6 @@ async def test_async_initiate_backup_non_agent_upload_error(
exception: Exception,
) -> None:
"""Test an unknown or writer upload error during backup generation."""
hass_storage[DOMAIN] = {
"data": {},
"key": DOMAIN,
"version": 1,
}
agent_ids = [LOCAL_AGENT_ID, "test.remote"]
local_agent = local_backup_platform.CoreLocalBackupAgent(hass)
remote_agent = BackupAgentTest("remote", backups=[])
@ -944,7 +939,7 @@ async def test_async_initiate_backup_non_agent_upload_error(
result = await ws_client.receive_json()
assert result["event"] == {"manager_state": BackupManagerState.IDLE}
assert not hass_storage[DOMAIN]["data"]
assert DOMAIN not in hass_storage
@pytest.mark.usefixtures("mock_backup_generation")
@ -1724,11 +1719,6 @@ async def test_receive_backup_non_agent_upload_error(
exception: Exception,
) -> None:
"""Test non agent upload error during backup receive."""
hass_storage[DOMAIN] = {
"data": {},
"key": DOMAIN,
"version": 1,
}
local_agent = local_backup_platform.CoreLocalBackupAgent(hass)
remote_agent = BackupAgentTest("remote", backups=[])
@ -1814,7 +1804,7 @@ async def test_receive_backup_non_agent_upload_error(
result = await ws_client.receive_json()
assert result["event"] == {"manager_state": BackupManagerState.IDLE}
assert not hass_storage[DOMAIN]["data"]
assert DOMAIN not in hass_storage
assert resp.status == 500
assert open_mock.call_count == 1
assert move_mock.call_count == 0

View File

@ -906,8 +906,10 @@ async def test_agents_info(
@pytest.mark.parametrize(
"storage_data",
[
None,
{},
{
"backup": {
"data": {
"backups": {},
"config": {
"create_backup": {
@ -925,7 +927,13 @@ async def test_agents_info(
"schedule": {"state": "daily"},
},
},
"key": DOMAIN,
"version": 1,
},
},
{
"backup": {
"data": {
"backups": {},
"config": {
"create_backup": {
@ -943,7 +951,13 @@ async def test_agents_info(
"schedule": {"state": "never"},
},
},
"key": DOMAIN,
"version": 1,
},
},
{
"backup": {
"data": {
"backups": {},
"config": {
"create_backup": {
@ -961,7 +975,13 @@ async def test_agents_info(
"schedule": {"state": "never"},
},
},
"key": DOMAIN,
"version": 1,
},
},
{
"backup": {
"data": {
"backups": {},
"config": {
"create_backup": {
@ -979,7 +999,13 @@ async def test_agents_info(
"schedule": {"state": "mon"},
},
},
"key": DOMAIN,
"version": 1,
},
},
{
"backup": {
"data": {
"backups": {},
"config": {
"create_backup": {
@ -997,6 +1023,10 @@ async def test_agents_info(
"schedule": {"state": "sat"},
},
},
"key": DOMAIN,
"version": 1,
},
},
],
)
async def test_config_info(
@ -1007,11 +1037,7 @@ async def test_config_info(
storage_data: dict[str, Any] | None,
) -> None:
"""Test getting backup config info."""
hass_storage[DOMAIN] = {
"data": storage_data,
"key": DOMAIN,
"version": 1,
}
hass_storage.update(storage_data)
await setup_backup_integration(hass)
await hass.async_block_till_done()