Skip to content

Commit aed4123

Browse files
committed
Remove one no-cover pragma by mocking a method
It is fairly easy to mock the _volume_key_loaded() method. Signed-off-by: mulhern <amulhern@redhat.com>
1 parent 27b6261 commit aed4123

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

src/stratis_cli/_actions/_list_pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def alert_codes(
314314
and not vkl_is_bool
315315
else []
316316
)
317-
except DbusClientMissingPropertyError: # pragma: no cover
317+
except DbusClientMissingPropertyError:
318318
pool_encryption_alerts = [PoolEncryptionAlert.VOLUME_KEY_STATUS_UNKNOWN]
319319
return availability_alerts + no_alloc_space_alerts + pool_encryption_alerts
320320

tests/integration/pool/test_list.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
"""
1717

1818
# isort: STDLIB
19+
from unittest.mock import patch
1920
from uuid import uuid4
2021

2122
# isort: FIRSTPARTY
22-
from dbus_client_gen import DbusClientUniqueResultError
23+
from dbus_client_gen import DbusClientMissingPropertyError, DbusClientUniqueResultError
2324

2425
# isort: LOCAL
2526
from stratis_cli import StratisCliErrorCodes
@@ -316,3 +317,46 @@ def test_list_detail(self):
316317
Test detail view on running pool.
317318
"""
318319
TEST_RUNNER(self._MENU + [f"--name={self._POOLNAME}"])
320+
321+
def test_list_volume_key_loaded_raises_detail(self):
322+
"""
323+
Test with _volume_key_loaded raising DbusClientMissingPropertyError,
324+
in detail view.
325+
"""
326+
327+
# isort: LOCAL
328+
import stratis_cli # pylint: disable=import-outside-toplevel
329+
330+
with patch.object(
331+
# pylint: disable=protected-access
332+
stratis_cli._actions._list_pool.Default, # pyright: ignore
333+
"_volume_key_loaded",
334+
autospec=True,
335+
side_effect=DbusClientMissingPropertyError(
336+
"oops",
337+
stratis_cli._actions._constants.POOL_INTERFACE, # pyright: ignore
338+
"VolumeKeyLoaded",
339+
),
340+
):
341+
TEST_RUNNER(self._MENU + [f"--name={self._POOLNAME}"])
342+
343+
def test_list_volume_key_loaded_raises(self):
344+
"""
345+
Test with _volume_key_loaded raising DbusClientMissingPropertyError.
346+
"""
347+
348+
# isort: LOCAL
349+
import stratis_cli # pylint: disable=import-outside-toplevel
350+
351+
with patch.object(
352+
# pylint: disable=protected-access
353+
stratis_cli._actions._list_pool.Default, # pyright: ignore
354+
"_volume_key_loaded",
355+
autospec=True,
356+
side_effect=DbusClientMissingPropertyError(
357+
"oops",
358+
stratis_cli._actions._constants.POOL_INTERFACE, # pyright: ignore
359+
"VolumeKeyLoaded",
360+
),
361+
):
362+
TEST_RUNNER(self._MENU)

0 commit comments

Comments
 (0)