mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-24 12:41:02 +02:00
Fixing tests
This commit is contained in:
parent
9aaeec9a61
commit
02a908e46f
3 changed files with 42 additions and 16 deletions
|
|
@ -44,8 +44,10 @@ class TestEndToEndConfigurationFlow:
|
||||||
mock_message.metadata.collection = 'test_collection'
|
mock_message.metadata.collection = 'test_collection'
|
||||||
mock_message.triples = []
|
mock_message.triples = []
|
||||||
|
|
||||||
# This should create TrustGraph with environment config
|
# Mock collection_exists to return True
|
||||||
await processor.store_triples(mock_message)
|
with patch.object(processor.tg, 'collection_exists', return_value=True):
|
||||||
|
# This should create TrustGraph with environment config
|
||||||
|
await processor.store_triples(mock_message)
|
||||||
|
|
||||||
# Verify Cluster was created with correct hosts
|
# Verify Cluster was created with correct hosts
|
||||||
mock_cluster.assert_called_once()
|
mock_cluster.assert_called_once()
|
||||||
|
|
@ -146,7 +148,9 @@ class TestConfigurationPriorityEndToEnd:
|
||||||
mock_message.metadata.collection = 'test_collection'
|
mock_message.metadata.collection = 'test_collection'
|
||||||
mock_message.triples = []
|
mock_message.triples = []
|
||||||
|
|
||||||
await processor.store_triples(mock_message)
|
# Mock collection_exists to return True
|
||||||
|
with patch.object(processor.tg, 'collection_exists', return_value=True):
|
||||||
|
await processor.store_triples(mock_message)
|
||||||
|
|
||||||
# Should use CLI parameters, not environment
|
# Should use CLI parameters, not environment
|
||||||
mock_cluster.assert_called_once()
|
mock_cluster.assert_called_once()
|
||||||
|
|
@ -244,7 +248,9 @@ class TestNoBackwardCompatibilityEndToEnd:
|
||||||
mock_message.metadata.collection = 'legacy_collection'
|
mock_message.metadata.collection = 'legacy_collection'
|
||||||
mock_message.triples = []
|
mock_message.triples = []
|
||||||
|
|
||||||
await processor.store_triples(mock_message)
|
# Mock collection_exists to return True
|
||||||
|
with patch.object(processor.tg, 'collection_exists', return_value=True):
|
||||||
|
await processor.store_triples(mock_message)
|
||||||
|
|
||||||
# Should use defaults since old parameters are not recognized
|
# Should use defaults since old parameters are not recognized
|
||||||
mock_cluster.assert_called_once()
|
mock_cluster.assert_called_once()
|
||||||
|
|
@ -300,7 +306,9 @@ class TestNoBackwardCompatibilityEndToEnd:
|
||||||
mock_message.metadata.collection = 'precedence_collection'
|
mock_message.metadata.collection = 'precedence_collection'
|
||||||
mock_message.triples = []
|
mock_message.triples = []
|
||||||
|
|
||||||
await processor.store_triples(mock_message)
|
# Mock collection_exists to return True
|
||||||
|
with patch.object(processor.tg, 'collection_exists', return_value=True):
|
||||||
|
await processor.store_triples(mock_message)
|
||||||
|
|
||||||
# Should use new parameters, not old ones
|
# Should use new parameters, not old ones
|
||||||
mock_cluster.assert_called_once()
|
mock_cluster.assert_called_once()
|
||||||
|
|
@ -350,7 +358,9 @@ class TestMultipleHostsHandling:
|
||||||
mock_message.metadata.collection = 'single_collection'
|
mock_message.metadata.collection = 'single_collection'
|
||||||
mock_message.triples = []
|
mock_message.triples = []
|
||||||
|
|
||||||
await processor.store_triples(mock_message)
|
# Mock collection_exists to return True
|
||||||
|
with patch.object(processor.tg, 'collection_exists', return_value=True):
|
||||||
|
await processor.store_triples(mock_message)
|
||||||
|
|
||||||
# Single host should be converted to list
|
# Single host should be converted to list
|
||||||
mock_cluster.assert_called_once()
|
mock_cluster.assert_called_once()
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,18 @@ class TestObjectsCassandraIntegration:
|
||||||
def mock_cassandra_session(self):
|
def mock_cassandra_session(self):
|
||||||
"""Mock Cassandra session for integration tests"""
|
"""Mock Cassandra session for integration tests"""
|
||||||
session = MagicMock()
|
session = MagicMock()
|
||||||
session.execute = MagicMock()
|
|
||||||
|
# Mock the execute method to return a valid result for keyspace checks
|
||||||
|
def execute_mock(query, *args, **kwargs):
|
||||||
|
result = MagicMock()
|
||||||
|
# For keyspace existence checks, return a row (keyspace exists)
|
||||||
|
if "system_schema.keyspaces" in str(query):
|
||||||
|
result.one.return_value = MagicMock() # Non-None means exists
|
||||||
|
else:
|
||||||
|
result.one.return_value = None
|
||||||
|
return result
|
||||||
|
|
||||||
|
session.execute = MagicMock(side_effect=execute_mock)
|
||||||
return session
|
return session
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
|
||||||
|
|
@ -295,6 +295,8 @@ class Processor(FlowProcessor):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.session.execute(create_table_cql)
|
self.session.execute(create_table_cql)
|
||||||
|
if keyspace not in self.known_tables:
|
||||||
|
self.known_tables[keyspace] = set()
|
||||||
self.known_tables[keyspace].add(table_key)
|
self.known_tables[keyspace].add(table_key)
|
||||||
logger.info(f"Ensured table exists: {safe_keyspace}.{safe_table}")
|
logger.info(f"Ensured table exists: {safe_keyspace}.{safe_table}")
|
||||||
|
|
||||||
|
|
@ -362,7 +364,8 @@ class Processor(FlowProcessor):
|
||||||
WHERE keyspace_name = %s
|
WHERE keyspace_name = %s
|
||||||
"""
|
"""
|
||||||
result = self.session.execute(check_keyspace_cql, (safe_keyspace,))
|
result = self.session.execute(check_keyspace_cql, (safe_keyspace,))
|
||||||
if not result.one():
|
# Check if result is None (mock case) or has no rows
|
||||||
|
if result is None or not result.one():
|
||||||
error_msg = (
|
error_msg = (
|
||||||
f"Collection {obj.metadata.collection} does not exist. "
|
f"Collection {obj.metadata.collection} does not exist. "
|
||||||
f"Create it first with tg-set-collection."
|
f"Create it first with tg-set-collection."
|
||||||
|
|
@ -371,6 +374,8 @@ class Processor(FlowProcessor):
|
||||||
raise ValueError(error_msg)
|
raise ValueError(error_msg)
|
||||||
# Cache it if it exists
|
# Cache it if it exists
|
||||||
self.known_keyspaces.add(safe_keyspace)
|
self.known_keyspaces.add(safe_keyspace)
|
||||||
|
if safe_keyspace not in self.known_tables:
|
||||||
|
self.known_tables[safe_keyspace] = set()
|
||||||
|
|
||||||
# Get schema definition
|
# Get schema definition
|
||||||
schema = self.schemas.get(obj.schema_name)
|
schema = self.schemas.get(obj.schema_name)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue