mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-06-06 21:35:13 +02:00
Collection management (#520)
* Tech spec * Refactored Cassanda knowledge graph for single table * Collection management, librarian services to manage metadata and collection deletion
This commit is contained in:
parent
48016d8fb2
commit
13ff7d765d
48 changed files with 2941 additions and 425 deletions
|
|
@ -21,7 +21,7 @@ class TestEndToEndConfigurationFlow:
|
|||
"""Test complete configuration flow from environment to processors."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch('trustgraph.direct.cassandra.Cluster')
|
||||
@patch('trustgraph.direct.cassandra_kg.Cluster')
|
||||
async def test_triples_writer_env_to_connection(self, mock_cluster):
|
||||
"""Test complete flow from environment variables to TrustGraph connection."""
|
||||
env_vars = {
|
||||
|
|
@ -117,7 +117,7 @@ class TestConfigurationPriorityEndToEnd:
|
|||
"""Test configuration priority chains end-to-end."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch('trustgraph.direct.cassandra.Cluster')
|
||||
@patch('trustgraph.direct.cassandra_kg.Cluster')
|
||||
async def test_cli_override_env_end_to_end(self, mock_cluster):
|
||||
"""Test that CLI parameters override environment variables end-to-end."""
|
||||
env_vars = {
|
||||
|
|
@ -184,7 +184,7 @@ class TestConfigurationPriorityEndToEnd:
|
|||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch('trustgraph.direct.cassandra.Cluster')
|
||||
@patch('trustgraph.direct.cassandra_kg.Cluster')
|
||||
async def test_no_config_defaults_end_to_end(self, mock_cluster):
|
||||
"""Test that defaults are used when no configuration provided end-to-end."""
|
||||
mock_cluster_instance = MagicMock()
|
||||
|
|
@ -222,7 +222,7 @@ class TestNoBackwardCompatibilityEndToEnd:
|
|||
"""Test that backward compatibility with old parameter names is removed."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch('trustgraph.direct.cassandra.Cluster')
|
||||
@patch('trustgraph.direct.cassandra_kg.Cluster')
|
||||
async def test_old_graph_params_no_longer_work_end_to_end(self, mock_cluster):
|
||||
"""Test that old graph_* parameters no longer work end-to-end."""
|
||||
mock_cluster_instance = MagicMock()
|
||||
|
|
@ -275,7 +275,7 @@ class TestNoBackwardCompatibilityEndToEnd:
|
|||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch('trustgraph.direct.cassandra.Cluster')
|
||||
@patch('trustgraph.direct.cassandra_kg.Cluster')
|
||||
async def test_new_params_override_old_params_end_to_end(self, mock_cluster):
|
||||
"""Test that new parameters override old ones when both are present end-to-end."""
|
||||
mock_cluster_instance = MagicMock()
|
||||
|
|
@ -334,7 +334,7 @@ class TestMultipleHostsHandling:
|
|||
assert call_args.kwargs['contact_points'] == ['host1', 'host2', 'host3', 'host4', 'host5']
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch('trustgraph.direct.cassandra.Cluster')
|
||||
@patch('trustgraph.direct.cassandra_kg.Cluster')
|
||||
async def test_single_host_converted_to_list(self, mock_cluster):
|
||||
"""Test that single host is converted to list for TrustGraph."""
|
||||
mock_cluster_instance = MagicMock()
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import time
|
|||
from unittest.mock import MagicMock
|
||||
|
||||
from .cassandra_test_helper import cassandra_container
|
||||
from trustgraph.direct.cassandra import TrustGraph
|
||||
from trustgraph.direct.cassandra_kg import KnowledgeGraph
|
||||
from trustgraph.storage.triples.cassandra.write import Processor as StorageProcessor
|
||||
from trustgraph.query.triples.cassandra.service import Processor as QueryProcessor
|
||||
from trustgraph.schema import Triple, Value, Metadata, Triples, TriplesQueryRequest
|
||||
|
|
@ -62,29 +62,29 @@ class TestCassandraIntegration:
|
|||
print("=" * 60)
|
||||
|
||||
# =====================================================
|
||||
# Test 1: Basic TrustGraph Operations
|
||||
# Test 1: Basic KnowledgeGraph Operations
|
||||
# =====================================================
|
||||
print("\n1. Testing basic TrustGraph operations...")
|
||||
|
||||
client = TrustGraph(
|
||||
print("\n1. Testing basic KnowledgeGraph operations...")
|
||||
|
||||
client = KnowledgeGraph(
|
||||
hosts=[host],
|
||||
keyspace="test_basic",
|
||||
table="test_table"
|
||||
keyspace="test_basic"
|
||||
)
|
||||
self.clients_to_close.append(client)
|
||||
|
||||
# Insert test data
|
||||
client.insert("http://example.org/alice", "knows", "http://example.org/bob")
|
||||
client.insert("http://example.org/alice", "age", "25")
|
||||
client.insert("http://example.org/bob", "age", "30")
|
||||
|
||||
collection = "test_collection"
|
||||
client.insert(collection, "http://example.org/alice", "knows", "http://example.org/bob")
|
||||
client.insert(collection, "http://example.org/alice", "age", "25")
|
||||
client.insert(collection, "http://example.org/bob", "age", "30")
|
||||
|
||||
# Test get_all
|
||||
all_results = list(client.get_all(limit=10))
|
||||
all_results = list(client.get_all(collection, limit=10))
|
||||
assert len(all_results) == 3
|
||||
print(f"✓ Stored and retrieved {len(all_results)} triples")
|
||||
|
||||
# Test get_s (subject query)
|
||||
alice_results = list(client.get_s("http://example.org/alice", limit=10))
|
||||
alice_results = list(client.get_s(collection, "http://example.org/alice", limit=10))
|
||||
assert len(alice_results) == 2
|
||||
alice_predicates = [r.p for r in alice_results]
|
||||
assert "knows" in alice_predicates
|
||||
|
|
@ -110,7 +110,7 @@ class TestCassandraIntegration:
|
|||
keyspace="test_storage",
|
||||
table="test_triples"
|
||||
)
|
||||
# Track the TrustGraph instance that will be created
|
||||
# Track the KnowledgeGraph instance that will be created
|
||||
self.storage_processor = storage_processor
|
||||
|
||||
# Create test message
|
||||
|
|
@ -202,7 +202,7 @@ class TestCassandraIntegration:
|
|||
# Debug: Check what was actually stored
|
||||
print("Debug: Checking what was stored for Alice...")
|
||||
direct_results = list(query_storage_processor.tg.get_s("http://example.org/alice", limit=10))
|
||||
print(f"Direct TrustGraph results: {len(direct_results)}")
|
||||
print(f"Direct KnowledgeGraph results: {len(direct_results)}")
|
||||
for result in direct_results:
|
||||
print(f" S=http://example.org/alice, P={result.p}, O={result.o}")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue