Skip to content

Commit

Permalink
Merge pull request #68 from juditnovak/bugfix/secret_not_found_instea…
Browse files Browse the repository at this point in the history
…d_of_runtime_error

SecretNotFoundError should be raised when a secret is not found
  • Loading branch information
PietroPasotti authored Oct 20, 2023
2 parents ca13b72 + 3a494af commit 3a5284d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "ops-scenario"

version = "5.4"
version = "5.4.1"

authors = [
{ name = "Pietro Pasotti", email = "[email protected]" }
Expand Down
5 changes: 3 additions & 2 deletions scenario/mocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ops.model import (
ModelError,
SecretInfo,
SecretNotFoundError,
SecretRotate,
_format_action_result_dict,
_ModelBackend,
Expand Down Expand Up @@ -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()
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()
else:
raise RuntimeError("need id or label.")

Expand Down
6 changes: 3 additions & 3 deletions tests/test_e2e/test_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down

0 comments on commit 3a5284d

Please sign in to comment.