Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "terminusdb"
version = "12.0.4"
description = "Terminus DB Python client"
version = "12.0.5"
description = "TerminusDB Python client"
authors = ["TerminusDB group", "DFRNT AB"]
license = "Apache Software License"
readme = "README.md"
Expand Down
37 changes: 10 additions & 27 deletions terminusdb_client/tests/integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@
def is_local_server_running():
"""Check if local TerminusDB server is running at http://127.0.0.1:6363"""
try:
requests.get("http://127.0.0.1:6363/api/", timeout=2)
# Any HTTP response means server is running (200, 302, 401, 404, 500, etc.)
# We only care that we got a response, not what the response is
requests.get("http://127.0.0.1:6363/api/ok", timeout=2)
# Any HTTP response means server is running
return True
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
return False


def is_docker_server_running():
"""Check if Docker TerminusDB server is already running at http://127.0.0.1:6366"""
"""Check if Docker TerminusDB server is already running at http://127.0.0.1:6363"""
try:
requests.get("http://127.0.0.1:6366/api/", timeout=2)
requests.get("http://127.0.0.1:6363/api/ok", timeout=2)
# Any HTTP response means server is running
return True
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
Expand Down Expand Up @@ -143,33 +142,17 @@ def docker_url_jwt(pytestconfig):
def docker_url(pytestconfig):
"""
Provides a TerminusDB server URL for integration tests.
Prefers local test server if running, otherwise starts Docker container.

NOTE: This fixture returns just the URL. Tests expect AUTOLOGIN mode (no authentication).
If using local server with authentication, use TERMINUSDB_AUTOLOGIN=true when starting it.
Uses port 6363 with admin:root authentication by default.
Prefers an already-running server, otherwise starts a Docker container.
"""
# Check if local test server is already running (port 6363)
# Check if a server is already running (port 6363)
if is_local_server_running():
print(
"\n✓ Using existing local TerminusDB test server at http://127.0.0.1:6363"
)
print(
"⚠️ WARNING: Local server should be started with TERMINUSDB_AUTOLOGIN=true"
)
print(
" Or use: TERMINUSDB_SERVER_AUTOLOGIN=true ./tests/terminusdb-test-server.sh restart"
)
print("\n✓ Using existing TerminusDB server at http://127.0.0.1:6363")
yield "http://127.0.0.1:6363"
return # Don't clean up - server was already running

# Check if Docker container is already running (port 6366)
if is_docker_server_running():
print("\n✓ Using existing Docker TerminusDB server at http://127.0.0.1:6366")
yield "http://127.0.0.1:6366"
return # Don't clean up - server was already running

# No server found, start Docker container
print("\n⚠ No server found, starting Docker container with AUTOLOGIN...")
print("\n⚠ No server found, starting Docker container...")
pytestconfig.getoption("docker_compose")
output = subprocess.run(
[
Expand All @@ -185,7 +168,7 @@ def docker_url(pytestconfig):
if output.returncode != 0:
raise RuntimeError(output.stderr)

test_url = "http://127.0.0.1:6366"
test_url = "http://127.0.0.1:6363"
is_server_started = False

seconds_waited = 0
Expand Down
16 changes: 11 additions & 5 deletions terminusdb_client/tests/integration_tests/test-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@ services:
hostname: terminusdb-server
tty: true
ports:
- 6366:6366
- 6363:6363
environment:
- TERMINUSDB_SERVER_NAME=http://127.0.0.1
- TERMINUSDB_SERVER_PORT=6366
- TERMINUSDB_SERVER_PORT=6363

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

# Security Option 1 (default): Assumes TerminusDB is only accessible from
# Security Option 1 (default): Use a password for the login
- TERMINUSDB_ADMIN_PASS=root
- TERMINUSDB_AUTOLOGIN=false
- TERMINUSDB_SERVER_PORT=6363
- TERMINUSDB_HTTPS_ENABLED=false

# Security Option 2: Assumes TerminusDB is only accessible from
# the machine it's running on and all access to port 6363 is considered
# authorized.
- TERMINUSDB_HTTPS_ENABLED=false
- TERMINUSDB_AUTOLOGIN=true
# - TERMINUSDB_HTTPS_ENABLED=false
# - TERMINUSDB_AUTOLOGIN=true

# Security Option 2: TerminusDB is set up behind a TLS-terminating reverse
# proxy with admin authentication provided by password.
Expand Down
59 changes: 59 additions & 0 deletions terminusdb_client/tests/integration_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,65 @@

test_user_agent = "terminusdb-client-python-tests"

_CLIENT_TEST_DBS = ["test_diff_ops"]
_CLIENT_TEST_ORGS = ["testOrg235091"]


@pytest.fixture(scope="module", autouse=True)
def cleanup_client_resources(docker_url):
"""Delete stale databases and organizations before the module and clean up after."""
client = Client(docker_url, user_agent=test_user_agent)
client.connect()

def _cleanup():
for db in _CLIENT_TEST_DBS:
try:
client.delete_database(db)
except Exception:
pass
for org in _CLIENT_TEST_ORGS:
# Ensure admin has access so we can list and delete databases
try:
client.change_capabilities(
{
"operation": "grant",
"scope": f"Organization/{org}",
"user": "User/admin",
"roles": ["Role/admin"],
}
)
except Exception:
pass
try:
dbs = client.get_organization_user_databases(org=org, username="admin")
for db in dbs:
try:
client.delete_database(db["name"], team=org)
except Exception:
pass
except Exception:
pass
# Revoke capabilities before deleting org
try:
client.change_capabilities(
{
"operation": "revoke",
"scope": f"Organization/{org}",
"user": "User/admin",
"roles": ["Role/admin"],
}
)
except Exception:
pass
try:
client.delete_organization(org)
except Exception:
pass

_cleanup()
yield
_cleanup()


def test_not_ok():
client = Client("http://localhost:6363")
Expand Down
12 changes: 6 additions & 6 deletions terminusdb_client/tests/integration_tests/test_conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def test_local_server_running_any_response(self, mock_get):
mock_get.return_value = Mock()

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

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

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

@patch("terminusdb_client.tests.integration_tests.conftest.requests.get")
def test_docker_server_running_401(self, mock_get):
"""Test Docker server detection returns True for HTTP 401 (unauthorized)"""
def test_docker_server_running_not_200(self, mock_get):
"""Test Docker server detection returns True for non-200 status (server is running)"""
mock_response = Mock()
mock_response.status_code = 401
mock_get.return_value = mock_response
Expand Down
27 changes: 27 additions & 0 deletions terminusdb_client/tests/integration_tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@

test_user_agent = "terminusdb-client-python-tests"

_SCHEMA_TEST_DBS = [
"test_docapi",
"test_docapi2",
"test_datetime",
"test_compress_data",
"test_repeated_load",
"test_repeated_load_fails",
]


@pytest.fixture(scope="module", autouse=True)
def cleanup_schema_databases(docker_url):
"""Delete stale databases before the module and clean up after."""
client = Client(docker_url, user_agent=test_user_agent)
client.connect()
for db in _SCHEMA_TEST_DBS:
try:
client.delete_database(db)
except Exception:
pass
yield
for db in _SCHEMA_TEST_DBS:
try:
client.delete_database(db)
except Exception:
pass


# Static prefix for test databases - unique enough to avoid clashes with real databases
TEST_DB_PREFIX = "pyclient_test_xk7q_"
Expand Down
Loading