|
1 | 1 | """Integration tests for prefix management operations.""" |
| 2 | +import time |
| 3 | + |
2 | 4 | import pytest |
3 | | -from terminusdb_client.client import Client |
| 5 | + |
| 6 | +from terminusdb_client import Client |
4 | 7 |
|
5 | 8 |
|
6 | 9 | @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() |
11 | 14 | return client |
12 | 15 |
|
13 | 16 |
|
14 | 17 | @pytest.fixture |
15 | | -def test_db(client): |
| 18 | +def test_db(prefix_client): |
16 | 19 | """Create and cleanup a test database.""" |
17 | | - import time |
18 | 20 | db_name = f"test_prefix_{int(time.time() * 1000)}" |
19 | 21 |
|
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) |
22 | 24 |
|
23 | 25 | yield db_name |
24 | 26 |
|
25 | 27 | # Cleanup |
26 | 28 | try: |
27 | | - client.delete_database(db_name) |
| 29 | + prefix_client.delete_database(db_name) |
28 | 30 | except Exception: |
29 | 31 | pass |
30 | 32 |
|
31 | 33 |
|
32 | 34 | class TestPrefixManagement: |
33 | 35 | """Test suite for prefix management operations.""" |
34 | 36 |
|
35 | | - def test_add_prefix_success(self, client, test_db): |
| 37 | + def test_add_prefix_success(self, prefix_client, test_db): |
36 | 38 | """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/") |
38 | 40 | assert result["api:status"] == "api:success" |
39 | 41 | assert result["api:prefix_name"] == "ex" |
40 | 42 | assert result["api:prefix_uri"] == "http://example.org/" |
41 | 43 |
|
42 | | - def test_add_prefix_duplicate(self, client, test_db): |
| 44 | + def test_add_prefix_duplicate(self, prefix_client, test_db): |
43 | 45 | """Test that adding duplicate prefix fails.""" |
44 | | - client.add_prefix("ex", "http://example.org/") |
| 46 | + prefix_client.add_prefix("ex", "http://example.org/") |
45 | 47 |
|
46 | 48 | with pytest.raises(Exception) as exc_info: |
47 | | - client.add_prefix("ex", "http://example.com/") |
| 49 | + prefix_client.add_prefix("ex", "http://example.com/") |
48 | 50 |
|
49 | 51 | # Should get 400 error with PrefixAlreadyExists |
50 | 52 | assert exc_info.value.response.status_code == 400 |
51 | 53 |
|
52 | | - def test_add_prefix_invalid_iri(self, client, test_db): |
| 54 | + def test_add_prefix_invalid_iri(self, prefix_client, test_db): |
53 | 55 | """Test that invalid IRI is rejected.""" |
54 | 56 | 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") |
56 | 58 |
|
57 | 59 | assert exc_info.value.response.status_code == 400 |
58 | 60 |
|
59 | | - def test_add_prefix_reserved(self, client, test_db): |
| 61 | + def test_add_prefix_reserved(self, prefix_client, test_db): |
60 | 62 | """Test that reserved prefix names are rejected.""" |
61 | 63 | with pytest.raises(Exception) as exc_info: |
62 | | - client.add_prefix("@custom", "http://example.org/") |
| 64 | + prefix_client.add_prefix("@custom", "http://example.org/") |
63 | 65 |
|
64 | 66 | assert exc_info.value.response.status_code == 400 |
65 | 67 |
|
66 | | - def test_get_prefix_success(self, client, test_db): |
| 68 | + def test_get_prefix_success(self, prefix_client, test_db): |
67 | 69 | """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") |
70 | 72 | assert uri == "http://example.org/" |
71 | 73 |
|
72 | | - def test_get_prefix_not_found(self, client, test_db): |
| 74 | + def test_get_prefix_not_found(self, prefix_client, test_db): |
73 | 75 | """Test that getting non-existent prefix fails.""" |
74 | 76 | with pytest.raises(Exception) as exc_info: |
75 | | - client.get_prefix("nonexistent") |
| 77 | + prefix_client.get_prefix("nonexistent") |
76 | 78 |
|
77 | 79 | assert exc_info.value.response.status_code == 404 |
78 | 80 |
|
79 | | - def test_update_prefix_success(self, client, test_db): |
| 81 | + def test_update_prefix_success(self, prefix_client, test_db): |
80 | 82 | """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/") |
83 | 85 |
|
84 | 86 | assert result["api:status"] == "api:success" |
85 | 87 | assert result["api:prefix_uri"] == "http://example.com/" |
86 | 88 |
|
87 | 89 | # Verify the update |
88 | | - uri = client.get_prefix("ex") |
| 90 | + uri = prefix_client.get_prefix("ex") |
89 | 91 | assert uri == "http://example.com/" |
90 | 92 |
|
91 | | - def test_update_prefix_not_found(self, client, test_db): |
| 93 | + def test_update_prefix_not_found(self, prefix_client, test_db): |
92 | 94 | """Test that updating non-existent prefix fails.""" |
93 | 95 | with pytest.raises(Exception) as exc_info: |
94 | | - client.update_prefix("nonexistent", "http://example.org/") |
| 96 | + prefix_client.update_prefix("nonexistent", "http://example.org/") |
95 | 97 |
|
96 | 98 | assert exc_info.value.response.status_code == 404 |
97 | 99 |
|
98 | | - def test_upsert_prefix_create(self, client, test_db): |
| 100 | + def test_upsert_prefix_create(self, prefix_client, test_db): |
99 | 101 | """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/") |
101 | 103 | assert result["api:status"] == "api:success" |
102 | 104 | assert result["api:prefix_uri"] == "http://example.org/" |
103 | 105 |
|
104 | | - def test_upsert_prefix_update(self, client, test_db): |
| 106 | + def test_upsert_prefix_update(self, prefix_client, test_db): |
105 | 107 | """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/") |
108 | 110 |
|
109 | 111 | assert result["api:status"] == "api:success" |
110 | 112 | assert result["api:prefix_uri"] == "http://example.com/" |
111 | 113 |
|
112 | | - def test_delete_prefix_success(self, client, test_db): |
| 114 | + def test_delete_prefix_success(self, prefix_client, test_db): |
113 | 115 | """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") |
116 | 118 | assert result["api:status"] == "api:success" |
117 | 119 |
|
118 | 120 | # Verify deletion |
119 | 121 | with pytest.raises(Exception) as exc_info: |
120 | | - client.get_prefix("ex") |
| 122 | + prefix_client.get_prefix("ex") |
121 | 123 | assert exc_info.value.response.status_code == 404 |
122 | 124 |
|
123 | | - def test_delete_prefix_not_found(self, client, test_db): |
| 125 | + def test_delete_prefix_not_found(self, prefix_client, test_db): |
124 | 126 | """Test that deleting non-existent prefix fails.""" |
125 | 127 | with pytest.raises(Exception) as exc_info: |
126 | | - client.delete_prefix("nonexistent") |
| 128 | + prefix_client.delete_prefix("nonexistent") |
127 | 129 |
|
128 | 130 | assert exc_info.value.response.status_code == 404 |
129 | 131 |
|
130 | | - def test_delete_prefix_reserved(self, client, test_db): |
| 132 | + def test_delete_prefix_reserved(self, prefix_client, test_db): |
131 | 133 | """Test that deleting reserved prefix fails.""" |
132 | 134 | with pytest.raises(Exception) as exc_info: |
133 | | - client.delete_prefix("@base") |
| 135 | + prefix_client.delete_prefix("@base") |
134 | 136 |
|
135 | 137 | assert exc_info.value.response.status_code == 400 |
0 commit comments