Skip to content

Commit e77fe02

Browse files
committed
Make tests run again. Remove cloud dependency.
1 parent 30fe395 commit e77fe02

File tree

4 files changed

+74
-33
lines changed

4 files changed

+74
-33
lines changed

terminusdb_client/tests/integration_tests/conftest.py

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,37 @@
55
import pytest
66
import requests
77

8-
MAX_CONTAINER_STARTUP_TIME = 30
8+
MAX_CONTAINER_STARTUP_TIME = 120 # Increased from 30 to 120 seconds for slower systems
9+
10+
# Check if a local TerminusDB test server is already running
11+
def is_local_server_running():
12+
"""Check if local TerminusDB server is running at http://127.0.0.1:6363"""
13+
try:
14+
response = requests.get("http://127.0.0.1:6363", timeout=2)
15+
# Server responds with 404 for root path, which means it's running
16+
return response.status_code in [200, 404]
17+
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
18+
return False
19+
20+
21+
def is_docker_server_running():
22+
"""Check if Docker TerminusDB server is already running at http://127.0.0.1:6366"""
23+
try:
24+
response = requests.get("http://127.0.0.1:6366", timeout=2)
25+
# Server responds with 404 for root path, which means it's running
26+
return response.status_code in [200, 404]
27+
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
28+
return False
29+
30+
31+
def is_jwt_server_running():
32+
"""Check if JWT Docker TerminusDB server is already running at http://127.0.0.1:6367"""
33+
try:
34+
response = requests.get("http://127.0.0.1:6367", timeout=2)
35+
# Server responds with 404 for root path, which means it's running
36+
return response.status_code in [200, 404]
37+
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
38+
return False
939

1040

1141
def is_docker_installed():
@@ -39,6 +69,13 @@ def docker_url_jwt(pytestconfig):
3969
# we are using subprocess in case we need to access some of the outputs
4070
# most likely
4171
jwt_token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InRlc3RrZXkifQ.eyJodHRwOi8vdGVybWludXNkYi5jb20vc2NoZW1hL3N5c3RlbSNhZ2VudF9uYW1lIjoiYWRtaW4iLCJodHRwOi8vdGVybWludXNkYi5jb20vc2NoZW1hL3N5c3RlbSN1c2VyX2lkZW50aWZpZXIiOiJhZG1pbkB1c2VyLmNvbSIsImlzcyI6Imh0dHBzOi8vdGVybWludXNodWIuZXUuYXV0aDAuY29tLyIsInN1YiI6ImFkbWluIiwiYXVkIjpbImh0dHBzOi8vdGVybWludXNodWIvcmVnaXN0ZXJVc2VyIiwiaHR0cHM6Ly90ZXJtaW51c2h1Yi5ldS5hdXRoMC5jb20vdXNlcmluZm8iXSwiaWF0IjoxNTkzNzY5MTgzLCJhenAiOiJNSkpuZEdwMHpVZE03bzNQT1RRUG1SSkltWTJobzBhaSIsInNjb3BlIjoib3BlbmlkIHByb2ZpbGUgZW1haWwifQ.Ru03Bi6vSIQ57bC41n6fClSdxlb61m0xX6Q34Yh91gql0_CyfYRWTuqzqPMFoCefe53hPC5E-eoSFdID_u6w1ih_pH-lTTqus9OWgi07Qou3QNs8UZBLiM4pgLqcBKs0N058jfg4y6h9GjIBGVhX9Ni2ez3JGNcz1_U45BhnreE"
72+
73+
# Check if JWT server is already running (port 6367)
74+
if is_jwt_server_running():
75+
print("\n✓ Using existing JWT Docker TerminusDB server at http://127.0.0.1:6367")
76+
yield ("http://127.0.0.1:6367", jwt_token)
77+
return # Don't clean up - server was already running
78+
4279
pytestconfig.getoption("docker_compose")
4380
output = subprocess.run(
4481
[
@@ -77,7 +114,8 @@ def docker_url_jwt(pytestconfig):
77114
if service.stdout == b"terminusdb-server\n":
78115
try:
79116
response = requests.get(test_url)
80-
assert response.status_code == 200
117+
# Server responds with 404 for root path, which means it's running
118+
assert response.status_code in [200, 404]
81119
break
82120
except (requests.exceptions.ConnectionError, AssertionError):
83121
pass
@@ -87,16 +125,37 @@ def docker_url_jwt(pytestconfig):
87125

88126
if seconds_waited > MAX_CONTAINER_STARTUP_TIME:
89127
clean_up_container()
90-
raise RuntimeError("Container was to slow to startup")
128+
raise RuntimeError(f"JWT Container was too slow to startup (waited {MAX_CONTAINER_STARTUP_TIME}s)")
91129

92130
yield (test_url, jwt_token)
93131
clean_up_container()
94132

95133

96134
@pytest.fixture(scope="module")
97135
def docker_url(pytestconfig):
98-
# we are using subprocess in case we need to access some of the outputs
99-
# most likely
136+
"""
137+
Provides a TerminusDB server URL for integration tests.
138+
Prefers local test server if running, otherwise starts Docker container.
139+
140+
NOTE: This fixture returns just the URL. Tests expect AUTOLOGIN mode (no authentication).
141+
If using local server with authentication, use TERMINUSDB_AUTOLOGIN=true when starting it.
142+
"""
143+
# Check if local test server is already running (port 6363)
144+
if is_local_server_running():
145+
print("\n✓ Using existing local TerminusDB test server at http://127.0.0.1:6363")
146+
print("⚠️ WARNING: Local server should be started with TERMINUSDB_AUTOLOGIN=true")
147+
print(" Or use: TERMINUSDB_SERVER_AUTOLOGIN=true ./tests/terminusdb-test-server.sh restart")
148+
yield "http://127.0.0.1:6363"
149+
return # Don't clean up - server was already running
150+
151+
# Check if Docker container is already running (port 6366)
152+
if is_docker_server_running():
153+
print("\n✓ Using existing Docker TerminusDB server at http://127.0.0.1:6366")
154+
yield "http://127.0.0.1:6366"
155+
return # Don't clean up - server was already running
156+
157+
# No server found, start Docker container
158+
print("\n⚠ No server found, starting Docker container with AUTOLOGIN...")
100159
pytestconfig.getoption("docker_compose")
101160
output = subprocess.run(
102161
[
@@ -134,7 +193,9 @@ def docker_url(pytestconfig):
134193
if service.stdout == b"terminusdb-server\n":
135194
try:
136195
response = requests.get(test_url)
137-
assert response.status_code == 200
196+
# Server responds with 404 for root path, which means it's running
197+
assert response.status_code in [200, 404]
198+
print(f"✓ Docker container started successfully after {seconds_waited}s")
138199
break
139200
except (requests.exceptions.ConnectionError, AssertionError):
140201
pass
@@ -144,7 +205,7 @@ def docker_url(pytestconfig):
144205

145206
if seconds_waited > MAX_CONTAINER_STARTUP_TIME:
146207
clean_up_container()
147-
raise RuntimeError("Container was to slow to startup")
208+
raise RuntimeError(f"Container was too slow to startup (waited {MAX_CONTAINER_STARTUP_TIME}s)")
148209

149210
yield test_url
150211
clean_up_container()

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3"
2-
31
volumes:
42
terminusdb_storage:
53

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3"
2-
31
volumes:
42
terminusdb_storage:
53

terminusdb_client/tests/integration_tests/test_client.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -414,25 +414,16 @@ def test_diff_ops(docker_url, test_schema):
414414
client = Client(docker_url, user_agent=test_user_agent)
415415
client.connect(user="admin", team="admin")
416416
client.create_database("test_diff_ops")
417-
public_diff = Client(
418-
"https://cloud.terminusdb.com/jsondiff", user_agent=test_user_agent
419-
)
420-
public_patch = Client(
421-
"https://cloud.terminusdb.com/jsonpatch", user_agent=test_user_agent
422-
)
417+
# NOTE: Public API endpoints (jsondiff/jsonpatch) no longer exist
418+
# Testing authenticated diff/patch only
423419
result_patch = Patch(
424420
json='{"@id": "Person/Jane", "name" : { "@op" : "SwapValue", "@before" : "Jane", "@after": "Janine" }}'
425421
)
426422
result = client.diff(
427423
{"@id": "Person/Jane", "@type": "Person", "name": "Jane"},
428424
{"@id": "Person/Jane", "@type": "Person", "name": "Janine"},
429425
)
430-
public_result = public_diff.diff(
431-
{"@id": "Person/Jane", "@type": "Person", "name": "Jane"},
432-
{"@id": "Person/Jane", "@type": "Person", "name": "Janine"},
433-
)
434426
assert result.content == result_patch.content
435-
assert public_result.content == result_patch.content
436427

437428
Person = test_schema.object.get("Person")
438429
jane = Person(
@@ -446,7 +437,6 @@ def test_diff_ops(docker_url, test_schema):
446437
age=18,
447438
)
448439
result = client.diff(jane, janine)
449-
public_result = public_diff.diff(jane, janine)
450440
# test commit_id and data_version with after obj
451441
test_schema.commit(client)
452442
jane_id = client.insert_document(jane)[0]
@@ -466,7 +456,6 @@ def test_diff_ops(docker_url, test_schema):
466456
commit_id_result_all = client.diff(current_commit, new_commit)
467457
data_version_result_all = client.diff(data_version, new_data_version)
468458
assert result.content == result_patch.content
469-
assert public_result.content == result_patch.content
470459
assert commit_id_result.content == result_patch.content
471460
assert commit_id_result2.content == result_patch.content
472461
assert data_version_result.content == result_patch.content
@@ -476,21 +465,12 @@ def test_diff_ops(docker_url, test_schema):
476465
assert client.patch(
477466
{"@id": "Person/Jane", "@type": "Person", "name": "Jane"}, result_patch
478467
) == {"@id": "Person/Jane", "@type": "Person", "name": "Janine"}
479-
assert public_patch.patch(
480-
{"@id": "Person/Jane", "@type": "Person", "name": "Jane"}, result_patch
481-
) == {"@id": "Person/Jane", "@type": "Person", "name": "Janine"}
482468
assert client.patch(jane, result_patch) == {
483469
"@id": "Person/Jane",
484470
"@type": "Person",
485471
"name": "Janine",
486472
"age": 18,
487473
}
488-
assert public_patch.patch(jane, result_patch) == {
489-
"@id": "Person/Jane",
490-
"@type": "Person",
491-
"name": "Janine",
492-
"age": 18,
493-
}
494474
my_schema = test_schema.copy()
495475
my_schema.object.pop("Employee")
496476
assert my_schema.to_dict() != test_schema.to_dict()
@@ -545,6 +525,10 @@ def test_diff_ops_no_auth(test_schema, terminusx_token):
545525
# assert client.patch(test_schema, result) == my_schema.to_dict()
546526

547527

528+
@pytest.mark.skipif(
529+
os.environ.get("TERMINUSDB_TEST_JWT") is None,
530+
reason="JWT testing not enabled. Set TERMINUSDB_TEST_JWT=1 to enable JWT tests."
531+
)
548532
def test_jwt(docker_url_jwt):
549533
# create client
550534
url = docker_url_jwt[0]

0 commit comments

Comments
 (0)