From 28a87db515acf8fc2eb07f977bb3baa1f8785288 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Fri, 31 Jan 2025 11:30:43 +0100 Subject: [PATCH] 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 --- tests/api/test_backups.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/tests/api/test_backups.py b/tests/api/test_backups.py index 24aaa0bd5..f3a17e4ab 100644 --- a/tests/api/test_backups.py +++ b/tests/api/test_backups.py @@ -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(