"""Test logic layer for acrids.""" from unittest.mock import patch import pytest from sound_recordings.api import app from sound_recordings.logic import acrids @pytest.mark.parametrize( 'model_returns, exception', [ ( (False, [], False, False), acrids.AssetNotFound ), ( (True, ['acr789'], False, False), acrids.AlreadyFingerprinted ) ] ) @patch('connector_neo4j.neo4j_driver') @patch('sound_recordings.models.acrids.upsert') def test_upsert_exceptions(mock_model, mock_neo4j_driver, model_returns, exception): """Test handling model response as exceptions.""" mock_model.return_value = model_returns with app.app_context(): with pytest.raises(exception): acrids.upsert('acr123', 'asset456') mock_neo4j_driver.session.assert_called_once() @pytest.mark.parametrize( 'model_returns, expected_result', [ # new acrid node inserted and connected ( (True, [], True, True), ([123], True) ), # existing acrid node connected ( (True, [], False, True), ([123], True) ), # already linked ( (True, [], False, False), ([123], False) ) ] ) @patch('connector_neo4j.neo4j_driver') @patch('sound_recordings.models.orchard_assets.get_track_ids') @patch('sound_recordings.models.acrids.upsert') def test_upsert_success( mock_upsert, mock_get_tuids, mock_neo4j_driver, model_returns, expected_result): """Test handling model response as success.""" mock_upsert.return_value = model_returns mock_get_tuids.return_value = [123] with app.app_context(): result = acrids.upsert('acr123', 'asset456') mock_neo4j_driver.session.assert_called_once() assert result == expected_result