Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SecretNotFoundError should be raised when a secret is not found #68

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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