mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-12-24 12:29:08 +00:00
Persistent notifications to repairs and fix free_space check (#6179)
* Persistent notifications to repairs and fix free_space check * Fix tests mocking too little free space
This commit is contained in:
@@ -1,33 +1,12 @@
|
||||
"""Test check free space fixup."""
|
||||
|
||||
# pylint: disable=import-error,protected-access
|
||||
from unittest.mock import MagicMock, PropertyMock, patch
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from supervisor.backups.const import BackupType
|
||||
from supervisor.const import CoreState
|
||||
from supervisor.coresys import CoreSys
|
||||
from supervisor.resolution.checks.free_space import CheckFreeSpace
|
||||
from supervisor.resolution.const import IssueType, SuggestionType
|
||||
|
||||
|
||||
@pytest.fixture(name="suggestion")
|
||||
async def fixture_suggestion(
|
||||
coresys: CoreSys, request: pytest.FixtureRequest
|
||||
) -> SuggestionType | None:
|
||||
"""Set up test for suggestion."""
|
||||
if request.param == SuggestionType.CLEAR_FULL_BACKUP:
|
||||
backup = MagicMock()
|
||||
backup.sys_type = BackupType.FULL
|
||||
with patch.object(
|
||||
type(coresys.backups),
|
||||
"list_backups",
|
||||
new=PropertyMock(return_value=[backup, backup, backup]),
|
||||
):
|
||||
yield SuggestionType.CLEAR_FULL_BACKUP
|
||||
else:
|
||||
yield request.param
|
||||
from supervisor.resolution.const import IssueType
|
||||
|
||||
|
||||
async def test_base(coresys: CoreSys):
|
||||
@@ -37,19 +16,14 @@ async def test_base(coresys: CoreSys):
|
||||
assert free_space.enabled
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"suggestion",
|
||||
[None, SuggestionType.CLEAR_FULL_BACKUP],
|
||||
indirect=True,
|
||||
)
|
||||
async def test_check(coresys: CoreSys, suggestion: SuggestionType | None):
|
||||
async def test_check(coresys: CoreSys):
|
||||
"""Test check."""
|
||||
free_space = CheckFreeSpace(coresys)
|
||||
await coresys.core.set_state(CoreState.RUNNING)
|
||||
|
||||
assert len(coresys.resolution.issues) == 0
|
||||
|
||||
with patch("shutil.disk_usage", return_value=(42, 42, 2 * (1024.0**3))):
|
||||
with patch("shutil.disk_usage", return_value=(42, 42, 3 * (1024.0**3))):
|
||||
await free_space.run_check()
|
||||
|
||||
assert len(coresys.resolution.issues) == 0
|
||||
@@ -58,11 +32,7 @@ async def test_check(coresys: CoreSys, suggestion: SuggestionType | None):
|
||||
await free_space.run_check()
|
||||
|
||||
assert coresys.resolution.issues[-1].type == IssueType.FREE_SPACE
|
||||
|
||||
if suggestion:
|
||||
assert coresys.resolution.suggestions[-1].type == suggestion
|
||||
else:
|
||||
assert len(coresys.resolution.suggestions) == 0
|
||||
assert len(coresys.resolution.suggestions) == 0
|
||||
|
||||
|
||||
async def test_approve(coresys: CoreSys):
|
||||
@@ -73,7 +43,7 @@ async def test_approve(coresys: CoreSys):
|
||||
with patch("shutil.disk_usage", return_value=(1, 1, 1)):
|
||||
assert await free_space.approve_check()
|
||||
|
||||
with patch("shutil.disk_usage", return_value=(42, 42, 2 * (1024.0**3))):
|
||||
with patch("shutil.disk_usage", return_value=(42, 42, 3 * (1024.0**3))):
|
||||
assert not await free_space.approve_check()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user