10
10
from terminusdb_client .client .Client import Patch , Client
11
11
from terminusdb_client .woqlquery .woql_query import WOQLQuery
12
12
13
- # from terminusdb_client.woqlquery.woql_query import WOQLQuery
14
-
15
13
test_user_agent = "terminusdb-client-python-tests"
16
14
17
15
@@ -276,6 +274,32 @@ def test_has_doc(docker_url):
276
274
assert client .has_doc (doc_id )
277
275
278
276
277
+ def test_get_organization_user_databases (docker_url ):
278
+ client = Client (docker_url , user_agent = test_user_agent , team = "admin" )
279
+ client .connect ()
280
+ db_name = "testDB" + str (random ())
281
+ db_name2 = "testDB" + str (random ())
282
+ org_name = "testOrg235091"
283
+ # Add DB in admin org to make sure they don't appear in other team
284
+ client .create_database (db_name + "admin" , team = "admin" )
285
+ client .create_organization (org_name )
286
+ client .create_database (db_name , team = org_name )
287
+ client .create_database (db_name2 , team = org_name )
288
+ capability_change = {
289
+ "operation" : "grant" ,
290
+ "scope" : f"Organization/{ org_name } " ,
291
+ "user" : "User/admin" ,
292
+ "roles" : [
293
+ "Role/admin"
294
+ ]
295
+ }
296
+ client .change_capabilities (capability_change )
297
+ databases = client .get_organization_user_databases (org = org_name , username = "admin" )
298
+ assert len (databases ) == 2
299
+ assert databases [0 ]['name' ] == db_name
300
+ assert databases [1 ]['name' ] == db_name2
301
+
302
+
279
303
def test_has_database (docker_url ):
280
304
client = Client (docker_url , user_agent = test_user_agent , team = "admin" )
281
305
client .connect ()
@@ -285,6 +309,17 @@ def test_has_database(docker_url):
285
309
assert not client .has_database ("DOES_NOT_EXISTDB" )
286
310
287
311
312
+ def test_optimize (docker_url ):
313
+ client = Client (docker_url , user_agent = test_user_agent , team = "admin" )
314
+ client .connect ()
315
+ db_name = "testDB" + str (random ())
316
+ client .create_database (db_name , team = "admin" )
317
+ client .connect (db = db_name )
318
+ for x in range (0 , 10 ):
319
+ client .insert_document ({"name" : f"Philosopher{ x } " }, raw_json = True )
320
+ client .optimize (f"admin/{ db_name } " )
321
+
322
+
288
323
def test_add_get_remove_user (docker_url ):
289
324
# create client
290
325
client = Client (docker_url , user_agent = test_user_agent )
@@ -387,34 +422,6 @@ def test_diff_ops(docker_url, test_schema):
387
422
my_schema = test_schema .copy ()
388
423
my_schema .object .pop ("Employee" )
389
424
assert my_schema .to_dict () != test_schema .to_dict ()
390
- ## Temporary switch off schema diff
391
- # result = client.diff(test_schema, my_schema)
392
- # assert result.content == {
393
- # "@op": "CopyList",
394
- # "@rest": {
395
- # "@after": [],
396
- # "@before": [
397
- # {
398
- # "@id": "Employee",
399
- # "@inherits": ["Person"],
400
- # "@key": {"@type": "Random"},
401
- # "@type": "Class",
402
- # "address_of": "Address",
403
- # "age": "xsd:integer",
404
- # "contact_number": {"@class": "xsd:string", "@type": "Optional"},
405
- # "friend_of": {"@class": "Person", "@type": "Set"},
406
- # "managed_by": "Employee",
407
- # "member_of": "Team",
408
- # "name": "xsd:string",
409
- # "permisstion": {"@class": "Role", "@type": "Set"},
410
- # }
411
- # ],
412
- # "@op": "SwapList",
413
- # "@rest": {"@op": "KeepList"},
414
- # },
415
- # "@to": 4,
416
- # }
417
- # assert client.patch(test_schema, result) == my_schema.to_dict()
418
425
419
426
420
427
@pytest .mark .skipif (
@@ -524,67 +531,3 @@ def test_terminusx_crazy_path(terminusx_token):
524
531
client .delete_database (testdb , "TerminusDBTest" )
525
532
assert client .db is None
526
533
assert testdb not in client .list_databases ()
527
-
528
-
529
- #
530
- # def _generate_csv(option):
531
- # if option == 1:
532
- # file_path = "employee_file.csv"
533
- # with open(file_path, mode="w") as employee_file:
534
- # employee_writer = csv.writer(
535
- # employee_file, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL
536
- # )
537
- # employee_writer.writerow(["John Smith", "Accounting", "November"])
538
- # employee_writer.writerow(["Erica Meyers", "IT", "March"])
539
- # return file_path
540
- # else:
541
- # file_path = "employee_file.csv"
542
- # with open(file_path, mode="w") as employee_file:
543
- # employee_writer = csv.writer(
544
- # employee_file, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL
545
- # )
546
- # employee_writer.writerow(["Cow Duck", "Marketing", "April"])
547
- # return file_path
548
- #
549
- #
550
- # def _file_clean_up(filename):
551
- # if os.path.exists(filename):
552
- # os.remove(filename)
553
- #
554
- #
555
- # def test_csv_handeling(docker_url):
556
- # client = Client(docker_url)
557
- # assert not client._connected
558
- # # test connect
559
- # client.connect()
560
- # assert client._connected
561
- # # test create db
562
- # client.create_database("test_csv")
563
- # client._get_current_commit()
564
- # assert client._db == "test_csv"
565
- # assert "test_csv" in client.list_databases()
566
- # csv_file_path = _generate_csv(1) # create testing csv
567
- # try:
568
- # client.insert_csv(csv_file_path)
569
- # client.get_csv(csv_file_path, csv_output_name="new_" + csv_file_path)
570
- # assert filecmp.cmp(csv_file_path, "new_" + csv_file_path)
571
- # csv_file_path = _generate_csv(2)
572
- # client.update_csv(csv_file_path)
573
- # client.get_csv(csv_file_path, csv_output_name="update_" + csv_file_path)
574
- # assert not filecmp.cmp("new_" + csv_file_path, "update_" + csv_file_path)
575
- # finally:
576
- # _file_clean_up(csv_file_path)
577
- # _file_clean_up("new_" + csv_file_path)
578
- # _file_clean_up("update_" + csv_file_path)
579
- #
580
-
581
- # def test_create_graph(docker_url):
582
- # client = Client(docker_url)
583
- # assert not client._connected
584
- # # test connect
585
- # client.connect()
586
- # assert client._connected
587
- # # test create db
588
- # client.create_database("test_graph")
589
- # client.create_graph("instance", "test-one-more-graph", "create test graph")
590
- # client.delete_graph("instance", "test-one-more-graph", "delete test graph")
0 commit comments