Skip to content

Commit d3288f0

Browse files
committed
Standardized test configuration
1 parent b601d8f commit d3288f0

4 files changed

Lines changed: 36 additions & 47 deletions

File tree

terminusdb_client/tests/integration_tests/conftest.py

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +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-
response = requests.get("http://127.0.0.1:6363", timeout=2)
16-
# Server responds with 200 (success) or 404 (not found but server is up)
17-
# 401 (unauthorized) also indicates server is running but needs auth
18-
return response.status_code in [200, 404]
15+
response = requests.get("http://127.0.0.1:6363/api/ok", timeout=2)
16+
return response.status_code == 200
1917
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
2018
return False
2119

2220

2321
def is_docker_server_running():
24-
"""Check if Docker TerminusDB server is already running at http://127.0.0.1:6366"""
22+
"""Check if Docker TerminusDB server is already running at http://127.0.0.1:6363"""
2523
try:
26-
response = requests.get("http://127.0.0.1:6366", timeout=2)
27-
# Server responds with 404 for root path, which means it's running
28-
return response.status_code in [200, 404]
24+
response = requests.get("http://127.0.0.1:6363/api/ok", timeout=2)
25+
return response.status_code == 200
2926
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
3027
return False
3128

@@ -143,33 +140,19 @@ def docker_url_jwt(pytestconfig):
143140
def docker_url(pytestconfig):
144141
"""
145142
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.
143+
Uses port 6363 with admin:root authentication by default.
144+
Prefers an already-running server, otherwise starts a Docker container.
150145
"""
151-
# Check if local test server is already running (port 6363)
146+
# Check if a server is already running (port 6363)
152147
if is_local_server_running():
153148
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"
149+
"\n✓ Using existing TerminusDB server at http://127.0.0.1:6363"
161150
)
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_conftest.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ def test_local_server_running_200(self, mock_get):
2121
mock_get.return_value = mock_response
2222

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

2626
@patch("terminusdb_client.tests.integration_tests.conftest.requests.get")
27-
def test_local_server_running_404(self, mock_get):
28-
"""Test local server detection returns True for HTTP 404"""
27+
def test_local_server_running_not_200(self, mock_get):
28+
"""Test local server detection returns False for non-200 status"""
2929
mock_response = Mock()
3030
mock_response.status_code = 404
3131
mock_get.return_value = mock_response
3232

33-
assert is_local_server_running() is True
33+
assert is_local_server_running() is False
3434

3535
@patch("terminusdb_client.tests.integration_tests.conftest.requests.get")
3636
def test_local_server_not_running_connection_error(self, mock_get):
@@ -54,16 +54,16 @@ def test_docker_server_running_200(self, mock_get):
5454
mock_get.return_value = mock_response
5555

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

5959
@patch("terminusdb_client.tests.integration_tests.conftest.requests.get")
60-
def test_docker_server_running_404(self, mock_get):
61-
"""Test Docker server detection returns True for HTTP 404"""
60+
def test_docker_server_running_not_200(self, mock_get):
61+
"""Test Docker server detection returns False for non-200 status"""
6262
mock_response = Mock()
6363
mock_response.status_code = 404
6464
mock_get.return_value = mock_response
6565

66-
assert is_docker_server_running() is True
66+
assert is_docker_server_running() is False
6767

6868
@patch("terminusdb_client.tests.integration_tests.conftest.requests.get")
6969
def test_docker_server_not_running(self, mock_get):

terminusdb_client/tests/test_Schema.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def test_embedded_object(test_schema):
200200
),
201201
friend_of={Person(name="Katy", age=51)},
202202
)
203-
client = Client("http://127.0.0.1:6366")
203+
client = Client("http://127.0.0.1:6363")
204204
result = client._convert_document(gavin, "instance")
205205
# Finds the internal object and splays it out properly
206206
assert len(result) == 2
@@ -334,11 +334,11 @@ def test_compress_data(patched, patched2, patched3, patched4):
334334
weeks=2,
335335
)
336336
test_obj = [CheckDatetime(datetime=datetime_obj, duration=delta) for _ in range(10)]
337-
client = Client("http://127.0.0.1:6366")
337+
client = Client("http://127.0.0.1:6363")
338338
client.connect(db="test_compress_data")
339339
client.insert_document(test_obj, compress=0)
340340
client._session.post.assert_called_once_with(
341-
"http://127.0.0.1:6366/api/document/admin/test_compress_data/local/branch/main",
341+
"http://127.0.0.1:6363/api/document/admin/test_compress_data/local/branch/main",
342342
auth=("admin", "root"),
343343
headers={
344344
"user-agent": f"terminusdb-client-python/{__version__}",
@@ -357,7 +357,7 @@ def test_compress_data(patched, patched2, patched3, patched4):
357357
client._session.post.reset_mock()
358358
client.insert_document(test_obj, compress="never")
359359
client._session.post.assert_called_once_with(
360-
"http://127.0.0.1:6366/api/document/admin/test_compress_data/local/branch/main",
360+
"http://127.0.0.1:6363/api/document/admin/test_compress_data/local/branch/main",
361361
auth=("admin", "root"),
362362
headers={"user-agent": f"terminusdb-client-python/{__version__}"},
363363
params={
@@ -371,7 +371,7 @@ def test_compress_data(patched, patched2, patched3, patched4):
371371
)
372372
client.replace_document(test_obj, compress=0)
373373
client._session.put.assert_called_once_with(
374-
"http://127.0.0.1:6366/api/document/admin/test_compress_data/local/branch/main",
374+
"http://127.0.0.1:6363/api/document/admin/test_compress_data/local/branch/main",
375375
auth=("admin", "root"),
376376
headers={
377377
"user-agent": f"terminusdb-client-python/{__version__}",
@@ -390,7 +390,7 @@ def test_compress_data(patched, patched2, patched3, patched4):
390390
client._session.put.reset_mock()
391391
client.replace_document(test_obj, compress="never")
392392
client._session.put.assert_called_once_with(
393-
"http://127.0.0.1:6366/api/document/admin/test_compress_data/local/branch/main",
393+
"http://127.0.0.1:6363/api/document/admin/test_compress_data/local/branch/main",
394394
auth=("admin", "root"),
395395
headers={"user-agent": f"terminusdb-client-python/{__version__}"},
396396
params={

0 commit comments

Comments
 (0)