Skip to content

Commit b9b01a1

Browse files
committed
Add insert triples function back
1 parent 77a0a06 commit b9b01a1

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

terminusdb_client/client/Client.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -829,16 +829,16 @@ def update_triples(self, graph_type: str, content: str, commit_msg: str) -> None
829829
return json.loads(_finish_response(result))
830830

831831
def insert_triples(
832-
self, graph_type: str, turtle, commit_msg: Optional[str] = None
832+
self, graph_type: str, content: str, commit_msg: Optional[str] = None
833833
) -> None:
834834
"""Inserts into the specified graph with the triples encoded in turtle format.
835835
836836
Parameters
837837
----------
838838
graph_type : str
839839
Graph type, either "instance" or "schema".
840-
turtle
841-
Valid set of triples in Turtle format.
840+
content
841+
Valid set of triples in Turtle or Trig format.
842842
commit_msg : str
843843
Commit message.
844844
@@ -847,19 +847,15 @@ def insert_triples(
847847
InterfaceError
848848
if the client does not connect to a database
849849
"""
850-
### TODO: make triples works again
851-
raise InterfaceError(
852-
"insert_triples is temporary not avaliable in this version"
853-
)
854-
855850
self._check_connection()
856851
self._validate_graph_type(graph_type)
857-
params = {"commit_info": self._generate_commit(commit_msg)}
858-
params["turtle"] = turtle
852+
params = {"commit_info": self._generate_commit(commit_msg),
853+
"turtle": content
854+
}
859855
result = requests.put(
860856
self._triples_url(graph_type),
861857
headers=self._default_headers,
862-
params=params,
858+
json=params,
863859
auth=self._auth(),
864860
)
865861
return json.loads(_finish_response(result))

terminusdb_client/tests/integration_tests/test_client.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,40 @@ def test_update_triples(docker_url):
217217
assert len(list(client.get_all_documents())) == 1
218218

219219

220+
def test_insert_triples(docker_url):
221+
ttl = """
222+
@base <terminusdb:///schema#> .
223+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
224+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
225+
@prefix woql: <http://terminusdb.com/schema/woql#> .
226+
@prefix json: <http://terminusdb.com/schema/json#> .
227+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
228+
@prefix xdd: <http://terminusdb.com/schema/xdd#> .
229+
@prefix vio: <http://terminusdb.com/schema/vio#> .
230+
@prefix sys: <http://terminusdb.com/schema/sys#> .
231+
@prefix api: <http://terminusdb.com/schema/api#> .
232+
@prefix owl: <http://www.w3.org/2002/07/owl#> .
233+
@prefix doc: <data/> .
234+
235+
<schema#Philosopher>
236+
a sys:Class ;
237+
<schema#name> xsd:string .
238+
239+
<terminusdb://context>
240+
a sys:Context ;
241+
sys:base "terminusdb:///data/"^^xsd:string ;
242+
sys:schema "terminusdb:///schema#"^^xsd:string .
243+
"""
244+
client = Client(docker_url, user_agent=test_user_agent, team="admin")
245+
client.connect()
246+
db_name = "testDB" + str(random())
247+
client.create_database(db_name, team="admin")
248+
client.connect(db=db_name)
249+
client.insert_triples(graph_type='schema', content=ttl, commit_msg="Insert triples")
250+
client.insert_document({"name": "Socrates"})
251+
assert len(list(client.get_all_documents())) == 1
252+
253+
220254
def test_get_database(docker_url):
221255
client = Client(docker_url, user_agent=test_user_agent, team="admin")
222256
client.connect()

0 commit comments

Comments
 (0)