"""unit tests for base model.""" from unittest.mock import MagicMock import pytest from src import base def test_run_cypher_query(neo4j_driver_mock): """Test run_cypher_query using fixture-based neo4j_driver_mock.""" query = 'MATCH (i:Tracks) RETURN i' params = {} expected_result = [{'foo': 'bar'}] # Setup the mocks transaction_mock = MagicMock() result_mock = MagicMock() result_mock.data.return_value = expected_result transaction_mock.run.return_value = result_mock neo4j_driver_mock.execute_read.side_effect = lambda func, *args, **kwargs: func(transaction_mock, *args, **kwargs) result = base.run_cypher_query(query, params) assert result == expected_result def test_run_cypher_query_execute_read_raises(neo4j_driver_mock): """Test that run_cypher_query raises an exception when execute_read fails.""" query = 'MATCH (i:Tracks) RETURN i' params = {} neo4j_driver_mock.execute_read.side_effect = Exception('Execute read failure') with pytest.raises(Exception, match='Execute read failure'): base.run_cypher_query(query, params) def test_execute_cypher_transaction_success(): """Test that execute_cypher_transaction successfully executes and returns the expected result.""" query = 'MATCH (i:Tracks) RETURN i' params = {} expected_result = [{'foo': 'bar'}] tx_mock = MagicMock() result_mock = MagicMock() result_mock.data.return_value = expected_result tx_mock.run.return_value = result_mock result = base.execute_cypher_transaction(tx_mock, query, params) assert result == expected_result def test_execute_cypher_transaction_raises(): """Test that execute_cypher_transaction raises an exception when Cypher run fails.""" query = 'MATCH (i:Tracks) RETURN i' params = {} tx_mock = MagicMock() tx_mock.run.side_effect = Exception('Cypher run failed') with pytest.raises(Exception, match='Cypher run failed'): base.execute_cypher_transaction(tx_mock, query, params)