feat: enhance mock database store with context manager support and improve cursor behavior
CI / lint-test-build (push) Failing after 52s
CI / lint-test-build (push) Failing after 52s
This commit is contained in:
@@ -12,7 +12,14 @@ def test_end_to_end_config_workflow():
|
|||||||
"""Test complete configuration workflow."""
|
"""Test complete configuration workflow."""
|
||||||
# Create mocks
|
# Create mocks
|
||||||
settings = Mock(spec=Settings)
|
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 = Mock(spec=DuckDBStore)
|
||||||
|
store.connect.return_value = context
|
||||||
audit_repo = Mock(spec=AuditRepository)
|
audit_repo = Mock(spec=AuditRepository)
|
||||||
|
|
||||||
# Create service
|
# Create service
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ def test_config_setting_repository_create_setting(mock_store):
|
|||||||
# Mock database connection
|
# Mock database connection
|
||||||
with patch.object(mock_store, "connect") as mock_connect:
|
with patch.object(mock_store, "connect") as mock_connect:
|
||||||
mock_cursor = Mock()
|
mock_cursor = Mock()
|
||||||
|
mock_cursor.execute.return_value = mock_cursor
|
||||||
mock_connect.return_value.__enter__.return_value = mock_cursor
|
mock_connect.return_value.__enter__.return_value = mock_cursor
|
||||||
|
|
||||||
# Mock the return value
|
# Mock the return value
|
||||||
@@ -79,6 +80,7 @@ def test_config_setting_repository_get_setting(mock_store):
|
|||||||
# Mock database connection
|
# Mock database connection
|
||||||
with patch.object(mock_store, "connect") as mock_connect:
|
with patch.object(mock_store, "connect") as mock_connect:
|
||||||
mock_cursor = Mock()
|
mock_cursor = Mock()
|
||||||
|
mock_cursor.execute.return_value = mock_cursor
|
||||||
mock_connect.return_value.__enter__.return_value = mock_cursor
|
mock_connect.return_value.__enter__.return_value = mock_cursor
|
||||||
|
|
||||||
# Mock the return value
|
# Mock the return value
|
||||||
@@ -112,6 +114,7 @@ def test_config_setting_repository_update_setting(mock_store):
|
|||||||
# Mock database connection
|
# Mock database connection
|
||||||
with patch.object(mock_store, "connect") as mock_connect:
|
with patch.object(mock_store, "connect") as mock_connect:
|
||||||
mock_cursor = Mock()
|
mock_cursor = Mock()
|
||||||
|
mock_cursor.execute.return_value = mock_cursor
|
||||||
mock_connect.return_value.__enter__.return_value = mock_cursor
|
mock_connect.return_value.__enter__.return_value = mock_cursor
|
||||||
|
|
||||||
# Mock the return value
|
# Mock the return value
|
||||||
@@ -155,6 +158,7 @@ def test_config_setting_repository_list_settings(mock_store):
|
|||||||
# Mock database connection
|
# Mock database connection
|
||||||
with patch.object(mock_store, "connect") as mock_connect:
|
with patch.object(mock_store, "connect") as mock_connect:
|
||||||
mock_cursor = Mock()
|
mock_cursor = Mock()
|
||||||
|
mock_cursor.execute.return_value = mock_cursor
|
||||||
mock_connect.return_value.__enter__.return_value = mock_cursor
|
mock_connect.return_value.__enter__.return_value = mock_cursor
|
||||||
|
|
||||||
# Mock the return value
|
# Mock the return value
|
||||||
@@ -198,6 +202,7 @@ def test_config_setting_repository_get_latest_updated_at(mock_store):
|
|||||||
# Mock database connection
|
# Mock database connection
|
||||||
with patch.object(mock_store, "connect") as mock_connect:
|
with patch.object(mock_store, "connect") as mock_connect:
|
||||||
mock_cursor = Mock()
|
mock_cursor = Mock()
|
||||||
|
mock_cursor.execute.return_value = mock_cursor
|
||||||
mock_connect.return_value.__enter__.return_value = mock_cursor
|
mock_connect.return_value.__enter__.return_value = mock_cursor
|
||||||
|
|
||||||
# Mock the return value
|
# Mock the return value
|
||||||
@@ -224,6 +229,7 @@ def test_config_pairing_repository_create_pairing(mock_store):
|
|||||||
# Mock database connection
|
# Mock database connection
|
||||||
with patch.object(mock_store, "connect") as mock_connect:
|
with patch.object(mock_store, "connect") as mock_connect:
|
||||||
mock_cursor = Mock()
|
mock_cursor = Mock()
|
||||||
|
mock_cursor.execute.return_value = mock_cursor
|
||||||
mock_connect.return_value.__enter__.return_value = mock_cursor
|
mock_connect.return_value.__enter__.return_value = mock_cursor
|
||||||
|
|
||||||
# Mock the return value
|
# Mock the return value
|
||||||
@@ -238,7 +244,8 @@ def test_config_pairing_repository_create_pairing(mock_store):
|
|||||||
]
|
]
|
||||||
|
|
||||||
# Create pairing
|
# 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)
|
result = repo.create_pairing(pairing)
|
||||||
|
|
||||||
@@ -257,6 +264,7 @@ def test_config_pairing_repository_get_pairing(mock_store):
|
|||||||
# Mock database connection
|
# Mock database connection
|
||||||
with patch.object(mock_store, "connect") as mock_connect:
|
with patch.object(mock_store, "connect") as mock_connect:
|
||||||
mock_cursor = Mock()
|
mock_cursor = Mock()
|
||||||
|
mock_cursor.execute.return_value = mock_cursor
|
||||||
mock_connect.return_value.__enter__.return_value = mock_cursor
|
mock_connect.return_value.__enter__.return_value = mock_cursor
|
||||||
|
|
||||||
# Mock the return value
|
# Mock the return value
|
||||||
|
|||||||
@@ -20,8 +20,17 @@ def mock_settings():
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_store():
|
def mock_store():
|
||||||
"""Create a mock database store."""
|
"""Create a mock database store with context manager support."""
|
||||||
store = Mock(spec=DuckDBStore)
|
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
|
return store
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user