diff --git a/tests/unit/test_config_e2e.py b/tests/unit/test_config_e2e.py index 572fe2f..8f890ec 100644 --- a/tests/unit/test_config_e2e.py +++ b/tests/unit/test_config_e2e.py @@ -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 diff --git a/tests/unit/test_config_repositories.py b/tests/unit/test_config_repositories.py index 2c7bd95..1339956 100644 --- a/tests/unit/test_config_repositories.py +++ b/tests/unit/test_config_repositories.py @@ -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 diff --git a/tests/unit/test_config_service.py b/tests/unit/test_config_service.py index a58ace0..bbdc316 100644 --- a/tests/unit/test_config_service.py +++ b/tests/unit/test_config_service.py @@ -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