Avoid test failure by not checking exact size of backup (#5594)

* Avoid test failure by not checking exact size of backup

This is a workaround for the fact that the backup size is not exactly
the same every time. This is due to the fact that the inner gziped tar
file can vary in size due to difference in json file (key order) and
potentially also different field values (UUID, backup slug).

It seems that sorting the keys makes the actual difference today, but
this has runtime overhead and might not catch all cases.

Simply check if size property is there and a number bigger than 0
instead.

* Fix pytest
This commit is contained in:
Stefan Agner 2025-01-31 11:30:43 +01:00 committed by GitHub
parent 05b648629f
commit 28a87db515
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1035,12 +1035,13 @@ async def test_protected_backup(
assert body["data"]["backups"][0]["location"] is None
assert body["data"]["backups"][0]["locations"] == [None]
assert body["data"]["backups"][0]["protected"] is True
assert body["data"]["backups"][0]["location_attributes"] == {
".local": {
"protected": True,
"size_bytes": 10240,
}
}
assert (
body["data"]["backups"][0]["location_attributes"][".local"]["protected"] is True
)
# NOTE: It is not safe to check size exactly here, as order of keys in
# `homeassistant.json` and potentially other random data (e.g. isntance UUID,
# backup slug) does change the size of the backup (due to gzip).
assert body["data"]["backups"][0]["location_attributes"][".local"]["size_bytes"] > 0
resp = await api_client.get(f"/backups/{slug}/info")
assert resp.status == 200
@ -1048,12 +1049,8 @@ async def test_protected_backup(
assert body["data"]["location"] is None
assert body["data"]["locations"] == [None]
assert body["data"]["protected"] is True
assert body["data"]["location_attributes"] == {
".local": {
"protected": True,
"size_bytes": 10240,
}
}
assert body["data"]["location_attributes"][".local"]["protected"] is True
assert body["data"]["location_attributes"][".local"]["size_bytes"] > 0
@pytest.mark.usefixtures(