555e282cc4
pi-agent-plugin checks / lint (push) Has been cancelled
pi-agent-plugin checks / test (20) (push) Has been cancelled
pi-agent-plugin checks / test (22) (push) Has been cancelled
pi-agent-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / check_changes (push) Has been cancelled
TypeScript SDK CI / changelog_check (push) Has been cancelled
ci / changelog_check (push) Has been cancelled
ci / check_changes (push) Has been cancelled
ci / build_mem0 (3.10) (push) Has been cancelled
ci / build_mem0 (3.11) (push) Has been cancelled
ci / build_mem0 (3.12) (push) Has been cancelled
CLI Node CI / lint (push) Has been cancelled
CLI Node CI / test (20) (push) Has been cancelled
CLI Node CI / test (22) (push) Has been cancelled
CLI Node CI / build (push) Has been cancelled
CLI Python CI / lint (push) Has been cancelled
CLI Python CI / test (3.10) (push) Has been cancelled
CLI Python CI / test (3.11) (push) Has been cancelled
CLI Python CI / test (3.12) (push) Has been cancelled
CLI Python CI / build (push) Has been cancelled
openclaw checks / lint (push) Has been cancelled
openclaw checks / test (20) (push) Has been cancelled
openclaw checks / test (22) (push) Has been cancelled
openclaw checks / build (push) Has been cancelled
opencode-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (22) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (22) (push) Has been cancelled
98 lines
3.4 KiB
Python
98 lines
3.4 KiB
Python
"""Tests for ``mem0.client.project.Project.update`` — focused on the
|
|
parameter-passthrough surface.
|
|
|
|
Verifies the kwarg → JSON payload mapping for every supported field
|
|
(``custom_instructions``, ``custom_categories``, ``retrieval_criteria``,
|
|
``multilingual``, ``decay``), the ValueError when no field is
|
|
provided, and the URL/method shape. The HTTP layer is mocked.
|
|
"""
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def project():
|
|
"""Build a ``Project`` with a mocked httpx client.
|
|
|
|
Bypasses ``MemoryClient`` so the test stays focused on
|
|
``Project.update`` payload construction.
|
|
"""
|
|
http = MagicMock()
|
|
http.patch.return_value = MagicMock(
|
|
json=lambda: {"message": "Updated"},
|
|
raise_for_status=lambda: None,
|
|
)
|
|
with patch("mem0.client.project.capture_client_event"):
|
|
from mem0.client.project import Project
|
|
|
|
proj = Project(client=http, org_id="org1", project_id="proj1")
|
|
yield proj, http
|
|
|
|
|
|
def _patch_payload(http):
|
|
"""Return the JSON body sent on the last PATCH, stripped of the SDK's
|
|
standard auth params (``org_id``, ``project_id``) that ``_prepare_params``
|
|
injects on every request."""
|
|
assert http.patch.called, "expected a PATCH call"
|
|
_, kwargs = http.patch.call_args
|
|
body = dict(kwargs.get("json", {}))
|
|
body.pop("org_id", None)
|
|
body.pop("project_id", None)
|
|
return body
|
|
|
|
|
|
class TestProjectUpdateDecay:
|
|
def test_decay_true_sent_in_payload(self, project):
|
|
proj, http = project
|
|
proj.update(decay=True)
|
|
assert _patch_payload(http) == {"decay": True}
|
|
|
|
def test_decay_false_sent_in_payload(self, project):
|
|
"""Explicit ``False`` must round-trip — not be filtered as falsy."""
|
|
proj, http = project
|
|
proj.update(decay=False)
|
|
assert _patch_payload(http) == {"decay": False}
|
|
|
|
def test_decay_combined_with_multilingual(self, project):
|
|
proj, http = project
|
|
proj.update(multilingual=True, decay=True)
|
|
assert _patch_payload(http) == {
|
|
"multilingual": True,
|
|
"decay": True,
|
|
}
|
|
|
|
def test_decay_omitted_when_none(self, project):
|
|
"""When the caller doesn't pass ``decay``, it must not appear in
|
|
the payload — backwards compatible with pre-decay callers."""
|
|
proj, http = project
|
|
proj.update(multilingual=False)
|
|
payload = _patch_payload(http)
|
|
assert payload == {"multilingual": False}
|
|
assert "decay" not in payload
|
|
|
|
def test_no_args_raises_with_decay_in_message(self, project):
|
|
proj, _ = project
|
|
with pytest.raises(ValueError, match=r"decay"):
|
|
proj.update()
|
|
|
|
def test_url_targets_project_endpoint(self, project):
|
|
proj, http = project
|
|
proj.update(decay=True)
|
|
args, _ = http.patch.call_args
|
|
assert args[0] == "/api/v1/orgs/organizations/org1/projects/proj1/"
|
|
|
|
|
|
class TestProjectUpdateBackwardsCompat:
|
|
def test_multilingual_only_still_works(self, project):
|
|
"""Pre-decay callers (multilingual only) keep working unchanged."""
|
|
proj, http = project
|
|
proj.update(multilingual=True)
|
|
assert _patch_payload(http) == {"multilingual": True}
|
|
|
|
def test_custom_instructions_only_still_works(self, project):
|
|
proj, http = project
|
|
proj.update(custom_instructions="be concise")
|
|
assert _patch_payload(http) == {"custom_instructions": "be concise"}
|