import pytest from marshmallow import ValidationError from playlist.queries.fetch_queries import fetch_sound_recording_top_placements def test_minimal(mock_execute): query_params = { "isrc": "QMFME2004132", "limit": 50, "offset": 0, "sort_key": "streams_all_time", "sort_direction": "DESC", } permissions = { "permission_label_ids": ["1", "2", "3"], } fetch_sound_recording_top_placements(query_params, permissions) assert mock_execute.call_count == 1 def test_with_unknown_key(mock_execute): query_params = { "isrc": "QMFME2004132", "limit": 50, "offset": 0, "sort_key": "streams_all_time", "sort_direction": "DESC", "a": 5, } fetch_sound_recording_top_placements(query_params, {}) assert mock_execute.call_count == 1 def test_with_incorrect_data_type(mock_execute): query_params = { "isrc": "QMFME2004132", "limit": 50, "offset": "abcdef", "sort_key": "streams_all_time", "sort_direction": "DESC", } with pytest.raises(ValidationError): fetch_sound_recording_top_placements(query_params, {}) assert mock_execute.call_count == 0 def test_with_incorrect_sort_direction(mock_execute): query_params = { "isrc": "QMFME2004132", "limit": 50, "offset": 100, "sort_key": "streams_all_time", "sort_direction": "asdsad", } with pytest.raises(ValidationError): fetch_sound_recording_top_placements(query_params, {}) assert mock_execute.call_count == 0 def test_with_permission_label_ids(mock_execute): query_params = { "isrc": "QMFME2004132", "limit": 50, "offset": 100, "sort_key": "streams_all_time", "sort_direction": "ASC", } permissions = { "permission_label_ids": ["1", "2", "3", "4"], } fetch_sound_recording_top_placements(query_params, permissions) assert mock_execute.call_count == 1 def test_with_permission_subaccount_ids(mock_execute): query_params = { "isrc": "QMFME2004132", "limit": 50, "offset": 100, "sort_key": "streams_all_time", "sort_direction": "ASC", } permissions = { "permission_subaccount_ids": ["5", "6", "7", "8"], } fetch_sound_recording_top_placements(query_params, permissions) assert mock_execute.call_count == 1 def test_with_permission_label_participant_ids(mock_execute): query_params = { "isrc": "QMFME2004132", "limit": 50, "offset": 100, "sort_key": "streams_all_time", "sort_direction": "ASC", } permissions = { "permission_label_participant_ids": ["5", "6", "7", "8"], } fetch_sound_recording_top_placements(query_params, permissions) assert mock_execute.call_count == 1 def test_with_label_and_permission_subaccount_ids(mock_execute): query_params = { "isrc": "QMFME2004132", "limit": 50, "offset": 100, "sort_key": "streams_all_time", "sort_direction": "ASC", } permissions = { "permission_label_ids": ["1", "2", "3", "4"], "permission_subaccount_ids": ["5", "6", "7", "8"], } fetch_sound_recording_top_placements(query_params, permissions) assert mock_execute.call_count == 1 def test_with_subaccount_and_permission_label_participant_ids(mock_execute): query_params = { "isrc": "QMFME2004132", "limit": 50, "offset": 100, "sort_key": "streams_all_time", "sort_direction": "ASC", } permissions = { "permission_label_participant_ids": ["1", "2", "3", "4"], "permission_subaccount_ids": ["5", "6", "7", "8"], } fetch_sound_recording_top_placements(query_params, permissions) assert mock_execute.call_count == 1 def test_with_label_and_permission_label_participant_ids(mock_execute): query_params = { "isrc": "QMFME2004132", "limit": 50, "offset": 100, "sort_key": "streams_all_time", "sort_direction": "ASC", } permissions = { "permission_label_ids": ["1", "2", "3", "4"], "permission_label_participant_ids": ["5", "6", "7", "8"], } fetch_sound_recording_top_placements(query_params, permissions) assert mock_execute.call_count == 1 def test_with_stream_countries(mock_execute): query_params = { "isrc": "QMFME2004132", "limit": 50, "offset": 100, "sort_key": "streams_all_time", "sort_direction": "ASC", "stream_countries": ["US", "MX"], } fetch_sound_recording_top_placements(query_params, {}) assert mock_execute.call_count == 1 def test_with_curator_countries(mock_execute): query_params = { "isrc": "QMFME2004132", "limit": 50, "offset": 100, "sort_key": "streams_all_time", "sort_direction": "ASC", "curator_countries": ["US", "MX"], } fetch_sound_recording_top_placements(query_params, {}) assert mock_execute.call_count == 1 def test_with_playlist_appearances(mock_execute): query_params = { "isrc": "QMFME2004132", "limit": 50, "offset": 100, "sort_key": "streams_all_time", "sort_direction": "ASC", "playlist_appearances": "current", } fetch_sound_recording_top_placements(query_params, {}) assert mock_execute.call_count == 1