Skip to content

Commit 31261fd

Browse files
Merge pull request #347 from terminusdb/remove_old_code
Remove old/unused code and test more
2 parents 6972d24 + 0779fe4 commit 31261fd

File tree

5 files changed

+37
-396
lines changed

5 files changed

+37
-396
lines changed

terminusdb_client/client/Client.py

-54
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import warnings
99
from collections.abc import Iterable
1010
from datetime import datetime
11-
from enum import Enum
1211
from typing import Any, Dict, List, Optional, Union
1312

1413
import requests
@@ -51,17 +50,6 @@ def __call__(self, r):
5150
return r
5251

5352

54-
class ResourceType(Enum):
55-
"""Enum for the different TerminusDB resources"""
56-
57-
DB = 1
58-
META = 2
59-
REPO = 3
60-
COMMITS = 4
61-
REF = 5
62-
BRANCH = 6
63-
64-
6553
class Patch:
6654
def __init__(self, json=None):
6755
if json:
@@ -582,48 +570,6 @@ def set_db(self, dbid: str, team: Optional[str] = None) -> str:
582570
repo=self.repo,
583571
)
584572

585-
def resource(self, ttype: ResourceType, val: Optional[str] = None) -> str:
586-
"""Create a resource identifier string based on the current config.
587-
588-
Parameters
589-
----------
590-
ttype : ResourceType
591-
Type of resource.
592-
val : str, optional
593-
Branch or commit identifier.
594-
595-
Returns
596-
-------
597-
str
598-
The constructed resource string.
599-
600-
Examples
601-
--------
602-
>>> client = Client("http://127.0.0.1:6363")
603-
>>> client.resource(ResourceType.DB)
604-
'<team>/<db>/'
605-
>>> client.resource(ResourceType.META)
606-
'<team>/<db>/_meta'
607-
>>> client.resource(ResourceType.COMMITS)
608-
'<team>/<db>/<repo>/_commits'
609-
>>> client.resource(ResourceType.REF, "<reference>")
610-
'<team>/<db>/<repo>/commit/<reference>'
611-
>>> client.resource(ResourceType.BRANCH, "<branch>")
612-
'<team>/<db>/<repo>/branch/<branch>'
613-
"""
614-
base = self.team + "/" + self.db + "/"
615-
ref_value = val if val else self.ref
616-
branch_value = val if val else self.branch
617-
urls = {
618-
ResourceType.DB: base,
619-
ResourceType.META: f"{base}_meta",
620-
ResourceType.REPO: f"{base}{self.repo}/_meta",
621-
ResourceType.COMMITS: f"{base}{self.repo}/_commits",
622-
ResourceType.REF: f"{base}{self.repo}/commit/{ref_value}",
623-
ResourceType.BRANCH: f"{base}{self.repo}/{branch_value}",
624-
}
625-
return urls[ttype]
626-
627573
def _get_prefixes(self):
628574
"""Get the prefixes for a given database"""
629575
self._check_connection()

terminusdb_client/tests/integration_tests/test_client.py

+37-94
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
from terminusdb_client.client.Client import Patch, Client
1111
from terminusdb_client.woqlquery.woql_query import WOQLQuery
1212

13-
# from terminusdb_client.woqlquery.woql_query import WOQLQuery
14-
1513
test_user_agent = "terminusdb-client-python-tests"
1614

1715

@@ -276,6 +274,32 @@ def test_has_doc(docker_url):
276274
assert client.has_doc(doc_id)
277275

278276

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+
279303
def test_has_database(docker_url):
280304
client = Client(docker_url, user_agent=test_user_agent, team="admin")
281305
client.connect()
@@ -285,6 +309,17 @@ def test_has_database(docker_url):
285309
assert not client.has_database("DOES_NOT_EXISTDB")
286310

287311

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+
288323
def test_add_get_remove_user(docker_url):
289324
# create client
290325
client = Client(docker_url, user_agent=test_user_agent)
@@ -387,34 +422,6 @@ def test_diff_ops(docker_url, test_schema):
387422
my_schema = test_schema.copy()
388423
my_schema.object.pop("Employee")
389424
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()
418425

419426

420427
@pytest.mark.skipif(
@@ -524,67 +531,3 @@ def test_terminusx_crazy_path(terminusx_token):
524531
client.delete_database(testdb, "TerminusDBTest")
525532
assert client.db is None
526533
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")

terminusdb_client/tests/test_Client.py

-11
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@
1515
from .conftest import mocked_request_insert_delete, mocked_request_success
1616
from .woqljson.woqlStarJson import WoqlStar
1717

18-
# def mock_func_with_1arg(_):
19-
# return True
20-
#
21-
#
22-
# def mock_func_with_2arg(first, second):
23-
# return True
24-
#
25-
#
26-
# def mock_func_no_arg():
27-
# return True
28-
2918

3019
@mock.patch("requests.get", side_effect=mocked_request_success)
3120
def test_connection(mocked_requests):

0 commit comments

Comments
 (0)