Skip to content

Commit f972cef

Browse files
authored
Merge pull request #467 from terminusdb/iso8601-predicates
Iso8601 predicates
2 parents efd5239 + 7264c1a commit f972cef

15 files changed

+1615
-50
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "terminusdb"
3-
version = "12.0.4"
4-
description = "Terminus DB Python client"
3+
version = "12.0.5"
4+
description = "TerminusDB Python client"
55
authors = ["TerminusDB group", "DFRNT AB"]
66
license = "Apache Software License"
77
readme = "README.md"

terminusdb_client/tests/integration_tests/conftest.py

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@
1212
def is_local_server_running():
1313
"""Check if local TerminusDB server is running at http://127.0.0.1:6363"""
1414
try:
15-
requests.get("http://127.0.0.1:6363/api/", timeout=2)
16-
# Any HTTP response means server is running (200, 302, 401, 404, 500, etc.)
17-
# We only care that we got a response, not what the response is
15+
requests.get("http://127.0.0.1:6363/api/ok", timeout=2)
16+
# Any HTTP response means server is running
1817
return True
1918
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
2019
return False
2120

2221

2322
def is_docker_server_running():
24-
"""Check if Docker TerminusDB server is already running at http://127.0.0.1:6366"""
23+
"""Check if Docker TerminusDB server is already running at http://127.0.0.1:6363"""
2524
try:
26-
requests.get("http://127.0.0.1:6366/api/", timeout=2)
25+
requests.get("http://127.0.0.1:6363/api/ok", timeout=2)
2726
# Any HTTP response means server is running
2827
return True
2928
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
@@ -143,33 +142,17 @@ def docker_url_jwt(pytestconfig):
143142
def docker_url(pytestconfig):
144143
"""
145144
Provides a TerminusDB server URL for integration tests.
146-
Prefers local test server if running, otherwise starts Docker container.
147-
148-
NOTE: This fixture returns just the URL. Tests expect AUTOLOGIN mode (no authentication).
149-
If using local server with authentication, use TERMINUSDB_AUTOLOGIN=true when starting it.
145+
Uses port 6363 with admin:root authentication by default.
146+
Prefers an already-running server, otherwise starts a Docker container.
150147
"""
151-
# Check if local test server is already running (port 6363)
148+
# Check if a server is already running (port 6363)
152149
if is_local_server_running():
153-
print(
154-
"\n✓ Using existing local TerminusDB test server at http://127.0.0.1:6363"
155-
)
156-
print(
157-
"⚠️ WARNING: Local server should be started with TERMINUSDB_AUTOLOGIN=true"
158-
)
159-
print(
160-
" Or use: TERMINUSDB_SERVER_AUTOLOGIN=true ./tests/terminusdb-test-server.sh restart"
161-
)
150+
print("\n✓ Using existing TerminusDB server at http://127.0.0.1:6363")
162151
yield "http://127.0.0.1:6363"
163152
return # Don't clean up - server was already running
164153

165-
# Check if Docker container is already running (port 6366)
166-
if is_docker_server_running():
167-
print("\n✓ Using existing Docker TerminusDB server at http://127.0.0.1:6366")
168-
yield "http://127.0.0.1:6366"
169-
return # Don't clean up - server was already running
170-
171154
# No server found, start Docker container
172-
print("\n⚠ No server found, starting Docker container with AUTOLOGIN...")
155+
print("\n⚠ No server found, starting Docker container...")
173156
pytestconfig.getoption("docker_compose")
174157
output = subprocess.run(
175158
[
@@ -185,7 +168,7 @@ def docker_url(pytestconfig):
185168
if output.returncode != 0:
186169
raise RuntimeError(output.stderr)
187170

188-
test_url = "http://127.0.0.1:6366"
171+
test_url = "http://127.0.0.1:6363"
189172
is_server_started = False
190173

191174
seconds_waited = 0

terminusdb_client/tests/integration_tests/test-docker-compose.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,27 @@ services:
99
hostname: terminusdb-server
1010
tty: true
1111
ports:
12-
- 6366:6366
12+
- 6363:6363
1313
environment:
1414
- TERMINUSDB_SERVER_NAME=http://127.0.0.1
15-
- TERMINUSDB_SERVER_PORT=6366
15+
- TERMINUSDB_SERVER_PORT=6363
1616

1717
# There are multiple ways to configure TerminusDB security through
1818
# environment variables. Several reasonable options are included below.
1919
# Uncomment the option you decide on and comment out others.
2020
# Don't forget to change the default password!
2121

22-
# Security Option 1 (default): Assumes TerminusDB is only accessible from
22+
# Security Option 1 (default): Use a password for the login
23+
- TERMINUSDB_ADMIN_PASS=root
24+
- TERMINUSDB_AUTOLOGIN=false
25+
- TERMINUSDB_SERVER_PORT=6363
26+
- TERMINUSDB_HTTPS_ENABLED=false
27+
28+
# Security Option 2: Assumes TerminusDB is only accessible from
2329
# the machine it's running on and all access to port 6363 is considered
2430
# authorized.
25-
- TERMINUSDB_HTTPS_ENABLED=false
26-
- TERMINUSDB_AUTOLOGIN=true
31+
# - TERMINUSDB_HTTPS_ENABLED=false
32+
# - TERMINUSDB_AUTOLOGIN=true
2733

2834
# Security Option 2: TerminusDB is set up behind a TLS-terminating reverse
2935
# proxy with admin authentication provided by password.

terminusdb_client/tests/integration_tests/test_client.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,65 @@
1212

1313
test_user_agent = "terminusdb-client-python-tests"
1414

15+
_CLIENT_TEST_DBS = ["test_diff_ops"]
16+
_CLIENT_TEST_ORGS = ["testOrg235091"]
17+
18+
19+
@pytest.fixture(scope="module", autouse=True)
20+
def cleanup_client_resources(docker_url):
21+
"""Delete stale databases and organizations before the module and clean up after."""
22+
client = Client(docker_url, user_agent=test_user_agent)
23+
client.connect()
24+
25+
def _cleanup():
26+
for db in _CLIENT_TEST_DBS:
27+
try:
28+
client.delete_database(db)
29+
except Exception:
30+
pass
31+
for org in _CLIENT_TEST_ORGS:
32+
# Ensure admin has access so we can list and delete databases
33+
try:
34+
client.change_capabilities(
35+
{
36+
"operation": "grant",
37+
"scope": f"Organization/{org}",
38+
"user": "User/admin",
39+
"roles": ["Role/admin"],
40+
}
41+
)
42+
except Exception:
43+
pass
44+
try:
45+
dbs = client.get_organization_user_databases(org=org, username="admin")
46+
for db in dbs:
47+
try:
48+
client.delete_database(db["name"], team=org)
49+
except Exception:
50+
pass
51+
except Exception:
52+
pass
53+
# Revoke capabilities before deleting org
54+
try:
55+
client.change_capabilities(
56+
{
57+
"operation": "revoke",
58+
"scope": f"Organization/{org}",
59+
"user": "User/admin",
60+
"roles": ["Role/admin"],
61+
}
62+
)
63+
except Exception:
64+
pass
65+
try:
66+
client.delete_organization(org)
67+
except Exception:
68+
pass
69+
70+
_cleanup()
71+
yield
72+
_cleanup()
73+
1574

1675
def test_not_ok():
1776
client = Client("http://localhost:6363")

terminusdb_client/tests/integration_tests/test_conftest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def test_local_server_running_any_response(self, mock_get):
1919
mock_get.return_value = Mock()
2020

2121
assert is_local_server_running() is True
22-
mock_get.assert_called_once_with("http://127.0.0.1:6363/api/", timeout=2)
22+
mock_get.assert_called_once_with("http://127.0.0.1:6363/api/ok", timeout=2)
2323

2424
@patch("terminusdb_client.tests.integration_tests.conftest.requests.get")
25-
def test_local_server_running_401(self, mock_get):
26-
"""Test local server detection returns True for HTTP 401 (unauthorized)"""
25+
def test_local_server_running_not_200(self, mock_get):
26+
"""Test local server detection returns True for non-200 status (server is running)"""
2727
mock_response = Mock()
2828
mock_response.status_code = 401
2929
mock_get.return_value = mock_response
@@ -50,11 +50,11 @@ def test_docker_server_running_any_response(self, mock_get):
5050
mock_get.return_value = Mock()
5151

5252
assert is_docker_server_running() is True
53-
mock_get.assert_called_once_with("http://127.0.0.1:6366/api/", timeout=2)
53+
mock_get.assert_called_once_with("http://127.0.0.1:6363/api/ok", timeout=2)
5454

5555
@patch("terminusdb_client.tests.integration_tests.conftest.requests.get")
56-
def test_docker_server_running_401(self, mock_get):
57-
"""Test Docker server detection returns True for HTTP 401 (unauthorized)"""
56+
def test_docker_server_running_not_200(self, mock_get):
57+
"""Test Docker server detection returns True for non-200 status (server is running)"""
5858
mock_response = Mock()
5959
mock_response.status_code = 401
6060
mock_get.return_value = mock_response

terminusdb_client/tests/integration_tests/test_schema.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,33 @@
88

99
test_user_agent = "terminusdb-client-python-tests"
1010

11+
_SCHEMA_TEST_DBS = [
12+
"test_docapi",
13+
"test_docapi2",
14+
"test_datetime",
15+
"test_compress_data",
16+
"test_repeated_load",
17+
"test_repeated_load_fails",
18+
]
19+
20+
21+
@pytest.fixture(scope="module", autouse=True)
22+
def cleanup_schema_databases(docker_url):
23+
"""Delete stale databases before the module and clean up after."""
24+
client = Client(docker_url, user_agent=test_user_agent)
25+
client.connect()
26+
for db in _SCHEMA_TEST_DBS:
27+
try:
28+
client.delete_database(db)
29+
except Exception:
30+
pass
31+
yield
32+
for db in _SCHEMA_TEST_DBS:
33+
try:
34+
client.delete_database(db)
35+
except Exception:
36+
pass
37+
1138

1239
# Static prefix for test databases - unique enough to avoid clashes with real databases
1340
TEST_DB_PREFIX = "pyclient_test_xk7q_"

0 commit comments

Comments
 (0)