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

Update agent_persist_mock to patch _exists method #868

Merged
merged 5 commits into from
Feb 24, 2025
Merged
Changes from 1 commit
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
14 changes: 12 additions & 2 deletions src/ostorlab/testing/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,15 @@
if key in storage:
return storage[key]

def _add(key, value):
def _add(key: str | bytes, value: bytes):
"""Check values are present in the storage dict."""
storage[key] = str(value).encode()
if isinstance(value, bytes) is False:
storage[key] = str(value).encode()
storage[key] = value

Check warning on line 102 in src/ostorlab/testing/agent.py

View check run for this annotation

Codecov / codecov/patch

src/ostorlab/testing/agent.py#L100-L102

Added lines #L100 - L102 were not covered by tests

def _exists(key: str) -> bool:
"""Check if thr key is present in the storage dict."""
return key in storage

Check warning on line 106 in src/ostorlab/testing/agent.py

View check run for this annotation

Codecov / codecov/patch

src/ostorlab/testing/agent.py#L106

Added line #L106 was not covered by tests

def _hash_add(hash_name, mapping):
for k, v in mapping.items():
Expand Down Expand Up @@ -156,6 +162,10 @@
"ostorlab.agent.mixins.agent_persist_mixin.AgentPersistMixin.add",
side_effect=_add,
)
mocker.patch(
"ostorlab.agent.mixins.agent_persist_mixin.AgentPersistMixin.exists",
side_effect=_exists,
)
mocker.patch(
"ostorlab.agent.mixins.agent_persist_mixin.AgentPersistMixin.hash_add",
side_effect=_hash_add,
Expand Down
Loading