diff --git a/scenario/mocking.py b/scenario/mocking.py index fe0f0a30..97726d94 100644 --- a/scenario/mocking.py +++ b/scenario/mocking.py @@ -12,6 +12,7 @@ from ops.model import ( ModelError, SecretInfo, + SecretNotFoundError, SecretRotate, _format_action_result_dict, _ModelBackend, @@ -134,12 +135,12 @@ def _get_secret(self, id=None, label=None): try: return next(filter(lambda s: s.id == id, self._state.secrets)) except StopIteration: - raise RuntimeError(f"not found: secret with id={id}.") + raise SecretNotFoundError(f"not found: secret with id={id}.") elif label: try: return next(filter(lambda s: s.label == label, self._state.secrets)) except StopIteration: - raise RuntimeError(f"not found: secret with label={label}.") + raise SecretNotFoundError(f"not found: secret with label={label}.") else: raise RuntimeError("need id or label.") diff --git a/tests/test_e2e/test_secrets.py b/tests/test_e2e/test_secrets.py index 2b08cae2..4ed46965 100644 --- a/tests/test_e2e/test_secrets.py +++ b/tests/test_e2e/test_secrets.py @@ -3,7 +3,7 @@ import pytest from ops.charm import CharmBase from ops.framework import Framework -from ops.model import SecretRotate +from ops.model import SecretNotFoundError, SecretRotate from scenario.state import Relation, Secret, State from tests.helpers import trigger @@ -25,9 +25,9 @@ def _on_event(self, event): def test_get_secret_no_secret(mycharm): def post_event(charm: CharmBase): - with pytest.raises(RuntimeError): + with pytest.raises(SecretNotFoundError): assert charm.model.get_secret(id="foo") - with pytest.raises(RuntimeError): + with pytest.raises(SecretNotFoundError): assert charm.model.get_secret(label="foo") trigger(