"""Unit tests for sound recording streams_by_country logic layer.""" from unittest.mock import patch import pytest from sound_recordings.logic import performance_by_country @pytest.fixture def isrc(): """ISRC test value.""" return "ISRC" @pytest.fixture def db_result(): """DB test result.""" return ["JSON payload"] @pytest.fixture def mock_snowflake_fetchone(db_result): """Mock Snowflake fetchone.""" with patch( "sound_recordings.models.performance_by_country.snowflake.fetchone" ) as fetchone: fetchone.return_value = db_result yield fetchone @pytest.fixture def expected_payload(isrc, db_result): """Return expected payload from performance_by_country logic.""" return {"isrc": isrc, "countries": db_result[0]} class TestGetPerformanceByCountry: """Test get_streams_by_country with label.""" @pytest.fixture def response( self, mock_snowflake_fetchone, request_context_for_label, mock_permissions_for_label, isrc, ): """Run get_performance_by_country.""" return performance_by_country.get_performance_by_country( request_context_for_label, isrc, ["theorchard"] ) def test_succeeds(self, response, expected_payload): """Test successful response.""" assert response.status == 200 assert response.message == expected_payload