Skip to content

Commit f9ee6af

Browse files
committed
Fix new tests
1 parent 70a7cb1 commit f9ee6af

File tree

1 file changed

+45
-43
lines changed

1 file changed

+45
-43
lines changed
Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,137 @@
11
"""Integration tests for prefix management operations."""
2+
import time
3+
24
import pytest
3-
from terminusdb_client.client import Client
5+
6+
from terminusdb_client import Client
47

58

69
@pytest.fixture
7-
def client():
8-
"""Create a test client connected to TerminusDB."""
9-
client = Client("http://127.0.0.1:6363")
10-
client.connect(user="admin", key="root", team="admin")
10+
def prefix_client(docker_url):
11+
"""Create a test client connected to TerminusDB using shared docker_url fixture."""
12+
client = Client(docker_url)
13+
client.connect()
1114
return client
1215

1316

1417
@pytest.fixture
15-
def test_db(client):
18+
def test_db(prefix_client):
1619
"""Create and cleanup a test database."""
17-
import time
1820
db_name = f"test_prefix_{int(time.time() * 1000)}"
1921

20-
client.create_database(db_name, label="Test Prefix DB", description="Database for testing prefix operations")
21-
client.connect(db=db_name)
22+
prefix_client.create_database(db_name, label="Test Prefix DB", description="Database for testing prefix operations")
23+
prefix_client.connect(db=db_name)
2224

2325
yield db_name
2426

2527
# Cleanup
2628
try:
27-
client.delete_database(db_name)
29+
prefix_client.delete_database(db_name)
2830
except Exception:
2931
pass
3032

3133

3234
class TestPrefixManagement:
3335
"""Test suite for prefix management operations."""
3436

35-
def test_add_prefix_success(self, client, test_db):
37+
def test_add_prefix_success(self, prefix_client, test_db):
3638
"""Test adding a new prefix successfully."""
37-
result = client.add_prefix("ex", "http://example.org/")
39+
result = prefix_client.add_prefix("ex", "http://example.org/")
3840
assert result["api:status"] == "api:success"
3941
assert result["api:prefix_name"] == "ex"
4042
assert result["api:prefix_uri"] == "http://example.org/"
4143

42-
def test_add_prefix_duplicate(self, client, test_db):
44+
def test_add_prefix_duplicate(self, prefix_client, test_db):
4345
"""Test that adding duplicate prefix fails."""
44-
client.add_prefix("ex", "http://example.org/")
46+
prefix_client.add_prefix("ex", "http://example.org/")
4547

4648
with pytest.raises(Exception) as exc_info:
47-
client.add_prefix("ex", "http://example.com/")
49+
prefix_client.add_prefix("ex", "http://example.com/")
4850

4951
# Should get 400 error with PrefixAlreadyExists
5052
assert exc_info.value.response.status_code == 400
5153

52-
def test_add_prefix_invalid_iri(self, client, test_db):
54+
def test_add_prefix_invalid_iri(self, prefix_client, test_db):
5355
"""Test that invalid IRI is rejected."""
5456
with pytest.raises(Exception) as exc_info:
55-
client.add_prefix("ex", "not-a-valid-uri")
57+
prefix_client.add_prefix("ex", "not-a-valid-uri")
5658

5759
assert exc_info.value.response.status_code == 400
5860

59-
def test_add_prefix_reserved(self, client, test_db):
61+
def test_add_prefix_reserved(self, prefix_client, test_db):
6062
"""Test that reserved prefix names are rejected."""
6163
with pytest.raises(Exception) as exc_info:
62-
client.add_prefix("@custom", "http://example.org/")
64+
prefix_client.add_prefix("@custom", "http://example.org/")
6365

6466
assert exc_info.value.response.status_code == 400
6567

66-
def test_get_prefix_success(self, client, test_db):
68+
def test_get_prefix_success(self, prefix_client, test_db):
6769
"""Test retrieving an existing prefix."""
68-
client.add_prefix("ex", "http://example.org/")
69-
uri = client.get_prefix("ex")
70+
prefix_client.add_prefix("ex", "http://example.org/")
71+
uri = prefix_client.get_prefix("ex")
7072
assert uri == "http://example.org/"
7173

72-
def test_get_prefix_not_found(self, client, test_db):
74+
def test_get_prefix_not_found(self, prefix_client, test_db):
7375
"""Test that getting non-existent prefix fails."""
7476
with pytest.raises(Exception) as exc_info:
75-
client.get_prefix("nonexistent")
77+
prefix_client.get_prefix("nonexistent")
7678

7779
assert exc_info.value.response.status_code == 404
7880

79-
def test_update_prefix_success(self, client, test_db):
81+
def test_update_prefix_success(self, prefix_client, test_db):
8082
"""Test updating an existing prefix."""
81-
client.add_prefix("ex", "http://example.org/")
82-
result = client.update_prefix("ex", "http://example.com/")
83+
prefix_client.add_prefix("ex", "http://example.org/")
84+
result = prefix_client.update_prefix("ex", "http://example.com/")
8385

8486
assert result["api:status"] == "api:success"
8587
assert result["api:prefix_uri"] == "http://example.com/"
8688

8789
# Verify the update
88-
uri = client.get_prefix("ex")
90+
uri = prefix_client.get_prefix("ex")
8991
assert uri == "http://example.com/"
9092

91-
def test_update_prefix_not_found(self, client, test_db):
93+
def test_update_prefix_not_found(self, prefix_client, test_db):
9294
"""Test that updating non-existent prefix fails."""
9395
with pytest.raises(Exception) as exc_info:
94-
client.update_prefix("nonexistent", "http://example.org/")
96+
prefix_client.update_prefix("nonexistent", "http://example.org/")
9597

9698
assert exc_info.value.response.status_code == 404
9799

98-
def test_upsert_prefix_create(self, client, test_db):
100+
def test_upsert_prefix_create(self, prefix_client, test_db):
99101
"""Test upsert creates prefix if it doesn't exist."""
100-
result = client.upsert_prefix("ex", "http://example.org/")
102+
result = prefix_client.upsert_prefix("ex", "http://example.org/")
101103
assert result["api:status"] == "api:success"
102104
assert result["api:prefix_uri"] == "http://example.org/"
103105

104-
def test_upsert_prefix_update(self, client, test_db):
106+
def test_upsert_prefix_update(self, prefix_client, test_db):
105107
"""Test upsert updates prefix if it already exists."""
106-
client.add_prefix("ex", "http://example.org/")
107-
result = client.upsert_prefix("ex", "http://example.com/")
108+
prefix_client.add_prefix("ex", "http://example.org/")
109+
result = prefix_client.upsert_prefix("ex", "http://example.com/")
108110

109111
assert result["api:status"] == "api:success"
110112
assert result["api:prefix_uri"] == "http://example.com/"
111113

112-
def test_delete_prefix_success(self, client, test_db):
114+
def test_delete_prefix_success(self, prefix_client, test_db):
113115
"""Test deleting an existing prefix."""
114-
client.add_prefix("ex", "http://example.org/")
115-
result = client.delete_prefix("ex")
116+
prefix_client.add_prefix("ex", "http://example.org/")
117+
result = prefix_client.delete_prefix("ex")
116118
assert result["api:status"] == "api:success"
117119

118120
# Verify deletion
119121
with pytest.raises(Exception) as exc_info:
120-
client.get_prefix("ex")
122+
prefix_client.get_prefix("ex")
121123
assert exc_info.value.response.status_code == 404
122124

123-
def test_delete_prefix_not_found(self, client, test_db):
125+
def test_delete_prefix_not_found(self, prefix_client, test_db):
124126
"""Test that deleting non-existent prefix fails."""
125127
with pytest.raises(Exception) as exc_info:
126-
client.delete_prefix("nonexistent")
128+
prefix_client.delete_prefix("nonexistent")
127129

128130
assert exc_info.value.response.status_code == 404
129131

130-
def test_delete_prefix_reserved(self, client, test_db):
132+
def test_delete_prefix_reserved(self, prefix_client, test_db):
131133
"""Test that deleting reserved prefix fails."""
132134
with pytest.raises(Exception) as exc_info:
133-
client.delete_prefix("@base")
135+
prefix_client.delete_prefix("@base")
134136

135137
assert exc_info.value.response.status_code == 400

0 commit comments

Comments
 (0)