feat: enhance mock database store with context manager support and improve cursor behavior
CI / lint-test-build (push) Failing after 52s

This commit is contained in:
2026-06-04 20:28:06 +02:00
parent 170f59eb89
commit df59f5ad7c
3 changed files with 26 additions and 2 deletions
+7
View File
@@ -12,7 +12,14 @@ def test_end_to_end_config_workflow():
"""Test complete configuration workflow."""
# Create mocks
settings = Mock(spec=Settings)
cursor = Mock()
cursor.fetchone.return_value = None
cursor.fetchall.return_value = []
cursor.execute.return_value = cursor
context = Mock()
context.__enter__.return_value = cursor
store = Mock(spec=DuckDBStore)
store.connect.return_value = context
audit_repo = Mock(spec=AuditRepository)
# Create service
+9 -1
View File
@@ -36,6 +36,7 @@ def test_config_setting_repository_create_setting(mock_store):
# Mock database connection
with patch.object(mock_store, "connect") as mock_connect:
mock_cursor = Mock()
mock_cursor.execute.return_value = mock_cursor
mock_connect.return_value.__enter__.return_value = mock_cursor
# Mock the return value
@@ -79,6 +80,7 @@ def test_config_setting_repository_get_setting(mock_store):
# Mock database connection
with patch.object(mock_store, "connect") as mock_connect:
mock_cursor = Mock()
mock_cursor.execute.return_value = mock_cursor
mock_connect.return_value.__enter__.return_value = mock_cursor
# Mock the return value
@@ -112,6 +114,7 @@ def test_config_setting_repository_update_setting(mock_store):
# Mock database connection
with patch.object(mock_store, "connect") as mock_connect:
mock_cursor = Mock()
mock_cursor.execute.return_value = mock_cursor
mock_connect.return_value.__enter__.return_value = mock_cursor
# Mock the return value
@@ -155,6 +158,7 @@ def test_config_setting_repository_list_settings(mock_store):
# Mock database connection
with patch.object(mock_store, "connect") as mock_connect:
mock_cursor = Mock()
mock_cursor.execute.return_value = mock_cursor
mock_connect.return_value.__enter__.return_value = mock_cursor
# Mock the return value
@@ -198,6 +202,7 @@ def test_config_setting_repository_get_latest_updated_at(mock_store):
# Mock database connection
with patch.object(mock_store, "connect") as mock_connect:
mock_cursor = Mock()
mock_cursor.execute.return_value = mock_cursor
mock_connect.return_value.__enter__.return_value = mock_cursor
# Mock the return value
@@ -224,6 +229,7 @@ def test_config_pairing_repository_create_pairing(mock_store):
# Mock database connection
with patch.object(mock_store, "connect") as mock_connect:
mock_cursor = Mock()
mock_cursor.execute.return_value = mock_cursor
mock_connect.return_value.__enter__.return_value = mock_cursor
# Mock the return value
@@ -238,7 +244,8 @@ def test_config_pairing_repository_create_pairing(mock_store):
]
# Create pairing
pairing = ConfigPairing(base_asset="BTC", quote_asset="USD", enabled=True, source="Kraken")
pairing = ConfigPairing(
base_asset="BTC", quote_asset="USD", enabled=True, source="Kraken")
result = repo.create_pairing(pairing)
@@ -257,6 +264,7 @@ def test_config_pairing_repository_get_pairing(mock_store):
# Mock database connection
with patch.object(mock_store, "connect") as mock_connect:
mock_cursor = Mock()
mock_cursor.execute.return_value = mock_cursor
mock_connect.return_value.__enter__.return_value = mock_cursor
# Mock the return value
+10 -1
View File
@@ -20,8 +20,17 @@ def mock_settings():
@pytest.fixture
def mock_store():
"""Create a mock database store."""
"""Create a mock database store with context manager support."""
store = Mock(spec=DuckDBStore)
cursor = Mock()
cursor.fetchone.return_value = None
cursor.fetchall.return_value = []
cursor.execute.return_value = cursor
# Set up context manager via mock_connect property
store.connect.side_effect = None # disable side effect
context_mock = Mock()
context_mock.__enter__.return_value = cursor
store.connect.return_value = context_mock
return store