Skip to content

Commit 4e50954

Browse files
committed
Merge branch 'fix/update-test-configuration' into align/align-idgen-random
2 parents 6155f87 + 0df5e9f commit 4e50954

File tree

3 files changed

+175
-0
lines changed

3 files changed

+175
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
"""Unit tests for conftest.py helper functions"""
2+
import pytest
3+
from unittest.mock import patch, Mock
4+
import requests
5+
6+
from .conftest import (
7+
is_local_server_running,
8+
is_docker_server_running,
9+
is_jwt_server_running,
10+
)
11+
12+
13+
class TestServerDetection:
14+
"""Test server detection helper functions"""
15+
16+
@patch('terminusdb_client.tests.integration_tests.conftest.requests.get')
17+
def test_local_server_running_200(self, mock_get):
18+
"""Test local server detection returns True for HTTP 200"""
19+
mock_response = Mock()
20+
mock_response.status_code = 200
21+
mock_get.return_value = mock_response
22+
23+
assert is_local_server_running() is True
24+
mock_get.assert_called_once_with("http://127.0.0.1:6363", timeout=2)
25+
26+
@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"""
29+
mock_response = Mock()
30+
mock_response.status_code = 404
31+
mock_get.return_value = mock_response
32+
33+
assert is_local_server_running() is True
34+
35+
@patch('terminusdb_client.tests.integration_tests.conftest.requests.get')
36+
def test_local_server_not_running_connection_error(self, mock_get):
37+
"""Test local server detection returns False on connection error"""
38+
mock_get.side_effect = requests.exceptions.ConnectionError()
39+
40+
assert is_local_server_running() is False
41+
42+
@patch('terminusdb_client.tests.integration_tests.conftest.requests.get')
43+
def test_local_server_not_running_timeout(self, mock_get):
44+
"""Test local server detection returns False on timeout"""
45+
mock_get.side_effect = requests.exceptions.Timeout()
46+
47+
assert is_local_server_running() is False
48+
49+
@patch('terminusdb_client.tests.integration_tests.conftest.requests.get')
50+
def test_docker_server_running_200(self, mock_get):
51+
"""Test Docker server detection returns True for HTTP 200"""
52+
mock_response = Mock()
53+
mock_response.status_code = 200
54+
mock_get.return_value = mock_response
55+
56+
assert is_docker_server_running() is True
57+
mock_get.assert_called_once_with("http://127.0.0.1:6366", timeout=2)
58+
59+
@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"""
62+
mock_response = Mock()
63+
mock_response.status_code = 404
64+
mock_get.return_value = mock_response
65+
66+
assert is_docker_server_running() is True
67+
68+
@patch('terminusdb_client.tests.integration_tests.conftest.requests.get')
69+
def test_docker_server_not_running(self, mock_get):
70+
"""Test Docker server detection returns False on connection error"""
71+
mock_get.side_effect = requests.exceptions.ConnectionError()
72+
73+
assert is_docker_server_running() is False
74+
75+
@patch('terminusdb_client.tests.integration_tests.conftest.requests.get')
76+
def test_jwt_server_running_200(self, mock_get):
77+
"""Test JWT server detection returns True for HTTP 200"""
78+
mock_response = Mock()
79+
mock_response.status_code = 200
80+
mock_get.return_value = mock_response
81+
82+
assert is_jwt_server_running() is True
83+
mock_get.assert_called_once_with("http://127.0.0.1:6367", timeout=2)
84+
85+
@patch('terminusdb_client.tests.integration_tests.conftest.requests.get')
86+
def test_jwt_server_running_404(self, mock_get):
87+
"""Test JWT server detection returns True for HTTP 404"""
88+
mock_response = Mock()
89+
mock_response.status_code = 404
90+
mock_get.return_value = mock_response
91+
92+
assert is_jwt_server_running() is True
93+
94+
@patch('terminusdb_client.tests.integration_tests.conftest.requests.get')
95+
def test_jwt_server_not_running(self, mock_get):
96+
"""Test JWT server detection returns False on connection error"""
97+
mock_get.side_effect = requests.exceptions.ConnectionError()
98+
99+
assert is_jwt_server_running() is False
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""Unit tests for Client initialization"""
2+
import pytest
3+
from terminusdb_client.client import Client
4+
from terminusdb_client.errors import InterfaceError
5+
6+
7+
class TestClientInitialization:
8+
"""Test Client initialization and basic properties"""
9+
10+
def test_client_init_basic(self):
11+
"""Test basic Client initialization"""
12+
client = Client("http://localhost:6363")
13+
assert client.server_url == "http://localhost:6363"
14+
assert client._connected is False
15+
16+
def test_client_init_with_user_agent(self):
17+
"""Test Client initialization with custom user agent"""
18+
client = Client("http://localhost:6363", user_agent="test-agent/1.0")
19+
assert "test-agent/1.0" in client._default_headers.get("user-agent", "")
20+
21+
def test_client_init_with_trailing_slash(self):
22+
"""Test Client handles URLs with trailing slashes"""
23+
client = Client("http://localhost:6363/")
24+
# Should work without errors
25+
assert client.server_url in ["http://localhost:6363", "http://localhost:6363/"]
26+
27+
def test_client_copy(self):
28+
"""Test Client copy method creates independent instance"""
29+
client1 = Client("http://localhost:6363")
30+
client1.team = "test_team"
31+
client1.db = "test_db"
32+
33+
client2 = client1.copy()
34+
35+
assert client2.server_url == client1.server_url
36+
assert client2.team == client1.team
37+
assert client2.db == client1.db
38+
# Ensure it's a different object
39+
assert client2 is not client1
40+
41+
def test_client_copy_modifications_independent(self):
42+
"""Test modifications to copied client don't affect original"""
43+
client1 = Client("http://localhost:6363")
44+
client1.team = "team1"
45+
46+
client2 = client1.copy()
47+
client2.team = "team2"
48+
49+
assert client1.team == "team1"
50+
assert client2.team == "team2"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""Unit tests for GraphType enum"""
2+
from terminusdb_client.client import GraphType
3+
4+
5+
class TestGraphType:
6+
"""Test GraphType enum values"""
7+
8+
def test_graphtype_instance(self):
9+
"""Test GraphType.INSTANCE value"""
10+
assert GraphType.INSTANCE == "instance"
11+
12+
def test_graphtype_schema(self):
13+
"""Test GraphType.SCHEMA value"""
14+
assert GraphType.SCHEMA == "schema"
15+
16+
def test_graphtype_enum_members(self):
17+
"""Test GraphType has exactly two members"""
18+
members = list(GraphType)
19+
assert len(members) == 2
20+
assert GraphType.INSTANCE in members
21+
assert GraphType.SCHEMA in members
22+
23+
def test_graphtype_values(self):
24+
"""Test all GraphType enum values exist"""
25+
assert hasattr(GraphType, 'INSTANCE')
26+
assert hasattr(GraphType, 'SCHEMA')

0 commit comments

Comments
 (0)