From 93a26e0c4b5115bd3aff4c8694f9dae4ad2d17d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20H=C3=B6ij?= Date: Wed, 11 Nov 2026 06:22:19 +0100 Subject: [PATCH 1/3] Raise Client.py unit coverage to 95% and fix pull/DatabaseError bugs Adds 46 tests to test_Client.py driving the real connect() flow under mocked session responses: module classes (WoqlResult iteration and error paths, JWTAuth/APITokenAuth headers, Patch update/before transforms and property guards), all _auth() variants including jwt/api/env-token and the disconnected RuntimeError, streaming query via WoqlResult, connect/close lifecycle, delete_database/create_branch/delete_branch/patch_resource, prefix CRUD, document read/write with data versions and iterable inputs, VCS operations, diff variants, organization/database listing, URL builders across _system/_meta/_commits/ref branches, and connection guards. Fixes two real bugs surfaced by the tests: pull() referenced self.author which does not exist and now uses self._author, and DatabaseError raised AttributeError when WoqlResult passed a parsed dict, so it now accepts dict payloads and extracts api:message/vio:message details. Client.py coverage: 53% to 95%, 1405 tests passing. --- terminusdb_client/client/Client.py | 2 +- terminusdb_client/errors.py | 9 + terminusdb_client/tests/test_Client.py | 661 ++++++++++++++++++++++++- 3 files changed, 670 insertions(+), 2 deletions(-) diff --git a/terminusdb_client/client/Client.py b/terminusdb_client/client/Client.py index 3341547a..fd6aa9b8 100644 --- a/terminusdb_client/client/Client.py +++ b/terminusdb_client/client/Client.py @@ -2009,7 +2009,7 @@ def pull( if remote_branch is None: remote_branch = self.branch if author is None: - author = self.author + author = self._author if message is None: message = ( f"Pulling from {remote}/{remote_branch} by Python client {__version__}" diff --git a/terminusdb_client/errors.py b/terminusdb_client/errors.py index 82a54106..883659f8 100644 --- a/terminusdb_client/errors.py +++ b/terminusdb_client/errors.py @@ -44,6 +44,15 @@ def __init__(self, response=None): response from the api call """ super().__init__() + if isinstance(response, dict): + self.error_obj = response + details = json.dumps(response, indent=4, sort_keys=True) + msg = response.get("api:message") + if not msg and isinstance(response.get("api:error"), dict): + msg = response["api:error"].get("vio:message") + self.message = (msg + "\n" if msg else "Unknown Error:\n") + details + self.status_code = None + return if not response.text: self.message = "Unknown Error - No error message from response." elif ( diff --git a/terminusdb_client/tests/test_Client.py b/terminusdb_client/tests/test_Client.py index dd56e920..9191f890 100644 --- a/terminusdb_client/tests/test_Client.py +++ b/terminusdb_client/tests/test_Client.py @@ -1,6 +1,8 @@ # import sys # sys.path.append('client') +import json import unittest.mock as mock +from datetime import datetime import pytest import random @@ -8,7 +10,13 @@ from terminusdb_client.client import Client, GraphType -from terminusdb_client.errors import InterfaceError +from terminusdb_client.client.Client import ( + APITokenAuth, + JWTAuth, + Patch, + WoqlResult, +) +from terminusdb_client.errors import DatabaseError, InterfaceError from terminusdb_client.woqlschema import WOQLSchema from ..__version__ import __version__ @@ -745,3 +753,654 @@ def test_convert_document_keeps_prefixed_and_schema_ids(): [{"@id": "Coordinate", "@type": "Class"}], "schema" ) assert docs[0]["@id"] == "Coordinate" + + +def _resp(payload, status=200, text=None, lines=None): + r = mock.MagicMock() + r.status_code = status + r.headers = { + "content-type": "application/json", + "Terminusdb-Data-Version": "v0", + } + r.text = text if text is not None else json.dumps(payload) + r.json.return_value = payload + r.iter_lines.return_value = iter(lines or []) + return r + + +def _mock(payload, status=200, text=None): + return lambda *a, **k: _resp(payload, status, text=text) + + +def _route(routes): + def f(url, *a, **k): + for pat, payload in routes: + if pat in url: + return _resp(payload) + return _resp({}) + + return f + + +INFO_RESPONSE = { + "@type": "api:InfoResponse", + "api:info": { + "authority": "admin", + "terminusdb": {"version": "11.0.0"}, + }, + "api:status": "api:success", +} + + +def _connect(client, **kwargs): + kwargs.setdefault("user", "admin") + kwargs.setdefault("key", "root") + kwargs.setdefault("team", "admin") + with mock.patch.object( + requests.Session, "get", side_effect=_mock(INFO_RESPONSE) + ): + client.connect(**kwargs) + return client + + +def _client(): + client = _connect(Client("http://localhost:6363"), repo="local") + client.branch = "main" + client.db = "db" + return client + + +class TestAuthClasses: + def test_jwt_auth_sets_bearer_header(self): + req = mock.Mock() + req.headers = {} + JWTAuth("tok")(req) + assert req.headers["Authorization"] == "Bearer tok" + + def test_api_token_auth_sets_token_header(self): + req = mock.Mock() + req.headers = {} + APITokenAuth("tok")(req) + assert req.headers["Authorization"] == "Token tok" + + +class TestWoqlResult: + def _lines(self, *docs): + return iter(json.dumps(d) for d in docs) + + def test_iterates_bindings_and_captures_postscript(self): + result = WoqlResult( + self._lines( + {"@type": "PrefaceRecord", "names": ["v:x"]}, + {"@type": "Binding", "v:x": 1}, + {"@type": "Binding", "v:x": 2}, + {"@type": "PostscriptRecord", "done": True}, + ) + ) + assert result.variable_names() == ["v:x"] + rows = list(result) + assert len(rows) == 2 + assert rows[0]["v:x"] == 1 + assert result.postscript == {"@type": "PostscriptRecord", "done": True} + + def test_rejects_non_preface_first_line(self): + with pytest.raises(DatabaseError) as exc: + WoqlResult(self._lines({"@type": "SomethingElse"})) + assert exc.value.error_obj["@type"] == "SomethingElse" + + def test_rejects_document_without_type(self): + result = WoqlResult( + self._lines( + {"@type": "PrefaceRecord", "names": []}, + {"not": "a typed document"}, + ) + ) + with pytest.raises(DatabaseError): + next(result) + + +class TestPatch: + def test_update_extracts_after_values(self): + patch = Patch( + json.dumps( + { + "name": {"@op": "SwapValue", "@before": "a", "@after": "b"}, + "nested": {"deep": {"@op": "SwapValue", "@after": 5}}, + } + ) + ) + assert patch.update == {"name": "b", "nested": {"deep": 5}} + + def test_before_extracts_before_values(self): + patch = Patch( + json.dumps( + { + "name": {"@op": "SwapValue", "@before": "a", "@after": "b"}, + "other": "plain", + "nested": {"deep": {"@before": 1}}, + } + ) + ) + assert patch.before == {"name": "a", "other": "plain", "nested": {"deep": 1}} + + def test_to_json_and_copy_round_trip(self): + patch = Patch(json.dumps({"a": {"@before": 1}})) + clone = patch.copy() + assert json.loads(clone.to_json()) == json.loads(patch.to_json()) + + def test_properties_reject_set_and_delete(self): + patch = Patch(json.dumps({"a": 1})) + for prop in ("update", "before"): + with pytest.raises(Exception): + setattr(patch, prop, None) + with pytest.raises(Exception): + delattr(patch, prop) + + +class TestClientProperties: + def test_team_quotes_and_unquotes(self): + client = Client("http://localhost:6363") + client.team = "my team" + assert client.team == "my team" + assert client._team == "my%20team" + + def test_db_branch_repo_ref_accessors(self): + client = Client("http://localhost:6363") + client.db = "mydb" + client.branch = "dev" + client.repo = "origin" + client.ref = "abc123" + assert client.db == "mydb" + assert client.branch == "dev" + assert client.repo == "origin" + assert client.ref == "abc123" + + @mock.patch.object(requests.Session, "get", side_effect=_mock({})) + def test_ok_reports_connection_state(self, _m): + client = Client("http://localhost:6363") + assert client.ok() is False + _connect(client) + assert client.ok() is True + + +class TestClientMethods: + @mock.patch.object( + requests.Session, + "get", + side_effect=_mock([{"timestamp": 1, "identifier": "abc"}]), + ) + def test_log_and_histories(self, _m): + client = _client() + commits = client.log() + assert commits[0]["identifier"] == "abc" + assert commits[0]["commit"] == "abc" + assert isinstance(commits[0]["timestamp"], datetime) + assert client.log(team="t", db="d", start=1, count=5)[0]["identifier"] == "abc" + assert isinstance(client.get_commit_history(), (dict, list)) + assert isinstance( + client.get_document_history("doc/x", start=1, count=3, created=True), + (dict, list), + ) + assert isinstance( + client.get_document_history("doc/x", updated=True), (dict, list) + ) + + @mock.patch.object( + requests.Session, + "get", + side_effect=_route( + [ + ("prefix/", {"api:prefix_uri": "http://ex/"}), + ("prefix", {"ex": "http://ex/"}), + ] + ), + ) + @mock.patch.object(requests.Session, "post", side_effect=_mock({"inserts": 0})) + @mock.patch.object(requests.Session, "put", side_effect=_mock({"inserts": 0})) + @mock.patch.object(requests.Session, "delete", side_effect=_mock({"inserts": 0})) + def test_prefix_crud(self, _d, _u, _p, _g): + client = _client() + assert client._get_prefixes() == {"ex": "http://ex/"} + assert client.get_prefix("ex") == "http://ex/" + client.add_prefix("ex", "http://x/") + client.update_prefix("ex", "http://y/") + client.upsert_prefix("ex", "http://z/") + client.delete_prefix("ex") + + @mock.patch.object( + requests.Session, + "get", + side_effect=_mock([], text="[]"), + ) + @mock.patch.object(requests.Session, "put", side_effect=_mock({"inserts": 0})) + @mock.patch.object(requests.Session, "post", side_effect=_mock({"inserts": 0})) + def test_triples_methods(self, _p, _u, _g): + client = _client() + client.get_triples(GraphType.INSTANCE) + client.update_triples(GraphType.INSTANCE, " ", "msg") + client.insert_triples(GraphType.INSTANCE, " ", "msg") + + @mock.patch.object( + requests.Session, + "get", + side_effect=_mock({"@id": "doc/x"}, text='{"@id": "doc/x"}'), + ) + @mock.patch.object( + requests.Session, + "post", + side_effect=_mock({"@id": "doc/x"}, text='{"@id": "doc/x"}'), + ) + def test_document_reads(self, _p, _g): + client = _client() + assert client.query_document({"@type": "Person"}, as_list=True) == [ + {"@id": "doc/x"} + ] + assert client.get_document("doc/x") == {"@id": "doc/x"} + assert client.get_documents_by_type("Person", as_list=True) == [ + {"@id": "doc/x"} + ] + assert client.get_all_documents(as_list=True, doc_type="Person") == [ + {"@id": "doc/x"} + ] + assert client.get_class_frame("Person") is not None + assert client.get_existing_classes() == {"doc/x": {"@id": "doc/x"}} + + @mock.patch.object(requests.Session, "get", side_effect=_mock({"@id": "doc/x"})) + def test_has_doc_true(self, _g): + client = _client() + assert client.has_doc("doc/x") is True + + @mock.patch.object( + requests.Session, + "get", + side_effect=_mock({"api:error": {"@type": "api:DocumentNotFound"}}, status=404), + ) + def test_has_doc_not_found(self, _g): + client = _client() + assert client.has_doc("doc/missing") is False + + @mock.patch.object( + requests.Session, + "get", + side_effect=_mock({"api:error": {"@type": "api:Other"}}, status=500), + ) + def test_has_doc_reraises_other_errors(self, _g): + client = _client() + with pytest.raises(DatabaseError): + client.has_doc("doc/x") + + @mock.patch.object(requests.Session, "get", side_effect=_mock({})) + @mock.patch.object(requests.Session, "post", side_effect=_mock({"inserts": 1})) + @mock.patch.object(requests.Session, "put", side_effect=_mock({"inserts": 1})) + @mock.patch.object(requests.Session, "delete", side_effect=_mock({"deletes": 1})) + def test_document_writes(self, _d, _u, _p, _g): + client = _client() + client.insert_document({"@id": "doc/x", "name": "n"}) + client.insert_document([{"@id": "doc/a"}, {"@id": "doc/b"}]) + client.insert_document( + [{"@type": "@context", "@base": "x/"}, {"@id": "doc/x"}], + full_replace=True, + ) + client.replace_document({"@id": "doc/x"}) + client.update_document({"@id": "doc/x", "name": "m"}) + client.delete_document("doc/x") + client.delete_document(["doc/x", "doc/y"]) + client.delete_document({"@id": "doc/z"}) + + @mock.patch.object(requests.Session, "get", side_effect=_mock({})) + @mock.patch.object( + requests.Session, "post", side_effect=_mock({"inserts": 0, "deletes": 0}) + ) + def test_query_variants(self, _p, _g): + client = _client() + client.query({"@type": "Triple"}) + client.query({"@type": "Triple"}, commit_msg="cm") + result, version = client.query({"@type": "Triple"}, get_data_version=True) + assert version == "v0" + + @mock.patch.object(requests.Session, "get", side_effect=_mock({})) + @mock.patch.object( + requests.Session, "post", side_effect=_mock({"api:status": "api:success"}) + ) + def test_vcs_operations(self, _p, _g): + client = _client() + client.pull() + client.pull(remote="other", remote_branch="dev", message="m") + client.fetch("origin") + client.push() + client.push(remote="other", remote_branch="dev", message="m", author="a") + client.rebase(branch="dev") + client.rebase(commit="abc123") + client.rebase(rebase_source="admin/db/local/branch/src") + client.squash(message="m", author="a") + client.squash(reset=True) + client.apply("v1", "v2", branch="dev", message="m", author="a") + client.clonedb("newdb", "admin") + + @mock.patch.object(requests.Session, "get", side_effect=_mock({})) + @mock.patch.object( + requests.Session, "post", side_effect=_mock({"api:status": "api:success"}) + ) + def test_reset_and_optimize(self, _p, _g): + client = _client() + client.reset("commit123") + client.reset("commit123", soft=True) + client.optimize("admin/db") + + @mock.patch.object(requests.Session, "get", side_effect=_mock({})) + @mock.patch.object( + requests.Session, "post", side_effect=_mock({"api:status": "api:success"}) + ) + def test_diff_and_versions(self, _p, _g): + client = _client() + client.diff({"a": 1}, {"a": 2}) + client.diff_version("v1", "v2") + client.diff_object({"a": 1}, {"a": 2}) + + @mock.patch.object(requests.Session, "get", side_effect=_mock({})) + @mock.patch.object( + requests.Session, "post", side_effect=_mock({"api:status": "api:success"}) + ) + def test_patch_method(self, _p, _g): + client = _client() + patch = Patch(json.dumps({"name": {"@op": "SwapValue", "@after": "b"}})) + result = client.patch({"name": "a"}, patch) + assert result is not None + + @mock.patch.object( + requests.Session, + "get", + side_effect=_route( + [ + ("databas", [{"name": "admin/db"}]), + ("organiz", {"name": "admin"}), + ("api/", [{"name": "admin/db"}]), + ] + ), + ) + def test_organizations_and_databases(self, _g): + client = _client() + assert client.get_organization("admin") == {"name": "admin"} + assert client.get_organization_user_databases("admin", "admin") == [ + {"name": "admin/db"} + ] + assert client.get_databases() == [{"name": "admin/db"}] + assert client.list_databases() == ["admin/db"] + + def test_check_connection_raises_when_disconnected(self): + client = Client("http://localhost:6363") + with pytest.raises(InterfaceError): + client.get_databases() + + +class TestClientWave2: + def test_auth_variants(self): + client = _client() + assert client._auth() == ("admin", "root") + + jwt_client = _connect( + Client("http://localhost:6363"), jwt_token="jwt", use_token=True + ) + assert isinstance(jwt_client._auth(), JWTAuth) + + token_client = _connect( + Client("http://localhost:6363"), api_token="tok" + ) + assert isinstance(token_client._auth(), APITokenAuth) + + with mock.patch.dict( + "os.environ", {"TERMINUSDB_ACCESS_TOKEN": "envtok"} + ): + env_client = _connect( + Client("http://localhost:6363"), key=None, user=None + ) + assert isinstance(env_client._auth(), APITokenAuth) + + client.close() + with pytest.raises(RuntimeError): + client._auth() + + @mock.patch.object(requests.Session, "get", side_effect=_mock({})) + def test_query_streaming(self, _g): + client = _client() + lines = [ + json.dumps({"@type": "PrefaceRecord", "names": ["v:x"]}), + json.dumps({"@type": "Binding", "v:x": 1}), + ] + with mock.patch.object( + requests.Session, + "post", + side_effect=lambda *a, **k: _resp({}, lines=lines), + ): + result = client.query({"@type": "Triple"}, streaming=True) + assert list(result) == [{"@type": "Binding", "v:x": 1}] + + @mock.patch.object(requests.Session, "get", side_effect=_mock({})) + @mock.patch.object( + requests.Session, "post", side_effect=_mock({"inserts": 0, "deletes": 0}) + ) + def test_query_woql_object_and_last_version(self, _p, _g): + from terminusdb_client.woqlquery.woql_query import WOQLQuery + + client = _client() + client.query(WOQLQuery().star()) + client.query({"@type": "Triple"}, last_data_version="v1") + + @mock.patch.object(requests.Session, "get", side_effect=_mock({})) + @mock.patch.object(requests.Session, "delete", side_effect=_mock({})) + def test_delete_database(self, _d, _g): + client = _client() + with pytest.raises(UserWarning): + client.delete_database() + + client = _client() + with pytest.warns(UserWarning): + client.delete_database("otherdb") + assert client.db is None + + client = _client() + client.delete_database("db", "admin", force=True) + assert client.db is None + + @mock.patch.object(requests.Session, "get", side_effect=_mock({})) + @mock.patch.object(requests.Session, "post", side_effect=_mock({})) + @mock.patch.object(requests.Session, "delete", side_effect=_mock({})) + def test_branch_management(self, _d, _p, _g): + client = _client() + client.create_branch("dev") + client.create_branch("empty", empty=True) + client.ref = "commit1" + client.create_branch("fromref") + client.delete_branch("dev") + + @mock.patch.object(requests.Session, "get", side_effect=_mock({})) + @mock.patch.object(requests.Session, "post", side_effect=_mock({})) + def test_patch_resource(self, _p, _g): + client = _client() + patch = Patch(json.dumps({"name": {"@op": "SwapValue", "@after": "b"}})) + client.patch_resource(patch, branch="dev", message="m", author="a") + + @mock.patch.object( + requests.Session, + "get", + side_effect=_mock({"@id": "doc/x"}, text='{"@id": "doc/x"}'), + ) + @mock.patch.object( + requests.Session, + "post", + side_effect=_mock({"@id": "doc/x"}, text='{"@id": "doc/x"}'), + ) + def test_document_version_paths(self, _p, _g): + client = _client() + docs, v = client.query_document({"@type": "T"}, get_data_version=True) + assert v == "v0" + docs, v = client.query_document( + {"@type": "T"}, get_data_version=True, as_list=True, skip=1, count=2 + ) + doc, v = client.get_document("doc/x", get_data_version=True) + assert v == "v0" + docs, v = client.get_documents_by_type("T", get_data_version=True) + assert v == "v0" + docs, v = client.get_all_documents( + get_data_version=True, as_list=True + ) + assert v == "v0" + it = client.query_document({"@type": "T"}) + assert list(it) == [{"@id": "doc/x"}] + client.get_documents_by_type("T", prefixed=True, unfold=True) + + @mock.patch.object(requests.Session, "get", side_effect=_mock({})) + @mock.patch.object(requests.Session, "delete", side_effect=_mock({})) + def test_iterable_delete(self, _d, _g): + client = _client() + client.delete_document(iter(["doc/x", "doc/y"])) + + def test_reset_and_rebase_guards(self): + client = _client() + assert client.reset(None) is None + with pytest.raises(RuntimeError): + client.rebase() + with pytest.raises(RuntimeError): + client.rebase(branch="a", commit="b") + + def test_prefix_url_system_db(self): + client = _client() + client.db = "_system" + url = client._prefix_url("ex") + assert "prefix/_system/ex" in url + assert client._prefix_url() is not None + + @mock.patch.object(requests.Session, "get", side_effect=_mock({"api:info": {}})) + @mock.patch.object(requests.Session, "head", side_effect=_mock({})) + def test_connect_with_db(self, _h, _g): + client = Client("http://localhost:6363") + client.connect(user="admin", key="root", team="admin", db="db") + assert client.db == "db" + client.close() + assert client._connected is False + + +class TestClientWave3: + def test_url_builders(self): + client = _client() + assert "capabilities" in client._capabilities_url() + assert "organizations" in client._organization_url() + assert "users" in client._users_url() + assert "roles" in client._roles_url() + + client.db = "_system" + assert client._db_url_fragment() == "_system" + assert "woql" in client._query_url() + assert "schema" in client._class_frame_url() + assert "document" in client._documents_url() + + client = _client() + client.repo = "_meta" + assert "_meta" in client._branch_base("document") + client.repo = "local" + client.branch = "_commits" + assert "_commits" in client._branch_base("document") + client.branch = "main" + client.ref = "abc" + assert "commit/abc" in client._branch_base("document") + client.ref = None + assert "branch/other" in client._branch_base("document", branch="other") + + @mock.patch.object( + requests.Session, + "get", + side_effect=_mock( + [{"timestamp": 1, "identifier": "abc"}], + text='[{"timestamp": 1, "identifier": "abc"}]', + ), + ) + def test_branches_and_commit_helpers(self, _g): + client = _client() + assert client._get_current_commit() == "abc" + assert client._get_target_commit(1) == "abc" + branches = client.get_all_branches() + assert isinstance(branches, list) + branches, version = client.get_all_branches(get_data_version=True) + assert version == "v0" + + def test_conv_to_dict_branches(self): + client = _client() + + with_to_dict = mock.Mock() + with_to_dict.to_dict.return_value = {"a": 1} + del with_to_dict._isinstance + assert client._conv_to_dict(with_to_dict) == {"a": 1} + + with__to_dict = mock.Mock(spec=[]) + with__to_dict._to_dict = mock.Mock(return_value={"b": 2}) + with__to_dict._isinstance = False + assert client._conv_to_dict(with__to_dict) == {"b": 2} + + with pytest.raises(ValueError): + client._conv_to_dict(object()) + + def test_insert_document_edges(self): + client = _client() + with mock.patch.object( + requests.Session, "post", side_effect=_mock({"inserts": 1}) + ): + with pytest.warns(UserWarning): + client.insert_document( + [{"@type": "@context", "@base": "x/"}, {"@id": "doc/x"}] + ) + assert client.insert_document([]) is None + + class SchemaObj: + pass + + obj = SchemaObj() + obj.to_dict = lambda: {"@type": "Class"} + with pytest.raises(InterfaceError): + client.insert_document(obj) + + @mock.patch.object(requests.Session, "get", side_effect=_mock({"api:info": {}})) + @mock.patch.object( + requests.Session, + "head", + side_effect=_mock({"api:error": {"@type": "x"}}, status=404), + ) + def test_connect_db_missing(self, _h, _g): + client = Client("http://localhost:6363") + with pytest.raises(InterfaceError): + client.connect(user="admin", key="root", team="admin", db="missing") + + @mock.patch.object(requests.Session, "get", side_effect=_mock({})) + @mock.patch.object( + requests.Session, "post", side_effect=_mock({"api:status": "api:success"}) + ) + def test_remote_auth_and_push(self, _p, _g): + client = _client() + client.push(remote_auth={"type": "basic", "user": "u", "key": "k"}) + client = _connect( + Client("http://localhost:6363"), + remote_auth={"type": "basic", "user": "u", "key": "k"}, + ) + client.repo = "local" + client.branch = "main" + client.db = "db" + client.push() + client.fetch("origin") + + @mock.patch.object(requests.Session, "get", side_effect=_mock({})) + @mock.patch.object( + requests.Session, "post", side_effect=_mock({"api:status": "api:success"}) + ) + def test_reset_use_path_and_soft(self, _p, _g): + client = _client() + client.reset("admin/db/local/commit/abc", use_path=True) + client.reset("abc", soft=True, use_path=True) + + @mock.patch.object(requests.Session, "get", side_effect=_mock({})) + @mock.patch.object( + requests.Session, "post", side_effect=_mock({"api:status": "api:success"}) + ) + def test_diff_document_id(self, _p, _g): + client = _client() + client.diff("v1", "v2", document_id="doc/x") + with pytest.raises(ValueError): + client.diff({"a": 1}, {"a": 2}, document_id="doc/x") From 87880c930e8604635e475cdb98e31f716ed0b10a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20H=C3=B6ij?= Date: Wed, 11 Nov 2026 06:36:10 +0100 Subject: [PATCH 2/3] Fix test_has_doc relying on server-echoed @id Cherry-picked from triple-relation (ccc825f). Engine commit f87a3b57 changed sys:JSONDocument reads to omit @id by default (raw_id=false) so @-prefixed raw JSON keys survive intact. The test inserted a doc without @id and read it back expecting @id in the payload, which now KeyErrors on the dev image and fails every matrix run. Insert with an explicit @id and assert has_doc against it directly - same False-then-True contract, no dependence on read shape. --- terminusdb_client/tests/integration_tests/test_client.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/terminusdb_client/tests/integration_tests/test_client.py b/terminusdb_client/tests/integration_tests/test_client.py index e87caa0e..fa68f364 100644 --- a/terminusdb_client/tests/integration_tests/test_client.py +++ b/terminusdb_client/tests/integration_tests/test_client.py @@ -435,9 +435,10 @@ def test_has_doc(docker_url): client.create_database(db_name, team="admin") client.connect(db=db_name) assert not client.has_doc("THIS_DOCUMENT_DOES_NOT_EXIST") - client.insert_document({"test": "test"}, raw_json=True) - doc_id = list(client.get_all_documents())[0]["@id"] - assert client.has_doc(doc_id) + client.insert_document( + {"@id": "test_document_has_doc", "test": "test"}, raw_json=True + ) + assert client.has_doc("test_document_has_doc") def test_get_organization_user_databases(docker_url): From a3c6940dc542f68a2496aef625cecc7ee511b326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20H=C3=B6ij?= Date: Wed, 11 Nov 2026 06:39:16 +0100 Subject: [PATCH 3/3] Fix E302 blank line separation at merged test block boundary The main merge placed the appended coverage tests flush against the incoming test_diff_version; flake8 requires two blank lines between top-level definitions. --- terminusdb_client/tests/test_Client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/terminusdb_client/tests/test_Client.py b/terminusdb_client/tests/test_Client.py index 40b0a3e5..50b9dfa2 100644 --- a/terminusdb_client/tests/test_Client.py +++ b/terminusdb_client/tests/test_Client.py @@ -1404,6 +1404,8 @@ def test_diff_document_id(self, _p, _g): client.diff("v1", "v2", document_id="doc/x") with pytest.raises(ValueError): client.diff({"a": 1}, {"a": 2}, document_id="doc/x") + + @mock.patch.object(requests.Session, "head", side_effect=mocked_request_success) @mock.patch.object(requests.Session, "get", side_effect=mocked_request_success) @mock.patch.object(requests.Session, "post", side_effect=mocked_request_success)