"""Tests for VideoSingleParticipantHandler.""" from mock import patch from switchboard_consumer.logic.participant.video_single_participant_handler \ import VideoSingleParticipantHandler def test_video_single_handler_is_compound_display_artist_no_members( display_artist_no_members): """Test for not compound if no members.""" result = VideoSingleParticipantHandler._is_compound_participant( display_artist_no_members['participant']) assert result is False def test_video_single_handler_is_compound_display_artist( display_artist_compound_members): """Test for compound if all members in 'Primary', 'Featured', 'With'.""" result = VideoSingleParticipantHandler._is_compound_participant( display_artist_compound_members['participant']) assert result is True def test_video_single_handler_is_not_compound_display_artist( display_artist_not_compound_members): """Test for non compound if any member has extra role.""" result = VideoSingleParticipantHandler._is_compound_participant( display_artist_not_compound_members['participant']) assert result is False @patch.object(VideoSingleParticipantHandler, 'handle_participant') def test_video_single_handler_process_track_display_artists( mock_handler, mock_logger, orchard_client, create_product_message, video_single_product_with_compound_and_not_track_display_artists): """Test for correct processing of video display_artists.""" handler = VideoSingleParticipantHandler( mock_logger, orchard_client, create_product_message, video_single_product_with_compound_and_not_track_display_artists, 12345, None) display_artists = ( video_single_product_with_compound_and_not_track_display_artists[ 'productTracks'][0]['track']['displayArtists'] ) handle_participants_results = [ ( None, { 'artistName': 'Name Single', 'artistType': 'performer' } ), ( None, { 'artistName': 'Name SubCompound 1', 'artistType': 'performer' } ), ( None, { 'artistName': 'Name SubCompound 2', 'artistType': 'performer' } ), ( None, { 'artistName': 'Name Non Compound', 'artistType': 'performer' } ), ] mock_handler.side_effect = handle_participants_results result = handler._process_track_display_artists(display_artists) assert mock_handler.call_count == 4 participant_args = [ call_arg[0][0] for call_arg in mock_handler.call_args_list ] assert participant_args == [ { 'ids': [{'localId': '10001', 'system': 'SONY'}], 'members': [], 'name': 'Name Single' }, { 'ids': [{'localId': '10003', 'system': 'SONY'}], 'members': [], 'name': 'Name SubCompound 1' }, { 'ids': [{'localId': '10004', 'system': 'SONY'}], 'members': [], 'name': 'Name SubCompound 2' }, { 'ids': [{'localId': '10005', 'system': 'SONY'}], 'members': [ { 'participant': { 'ids': [{'localId': '10006', 'system': 'SONY'}], 'members': [], 'name': 'Name NonSubCompound 1' }, 'role': 'Primary' }, { 'participant': { 'ids': [{'localId': '10007', 'system': 'SONY'}], 'members': [], 'name': 'Name NonSubCompound 2' }, 'role': 'Original' } ], 'name': 'Name Non Compound' } ] assert result == handle_participants_results @patch.object(VideoSingleParticipantHandler, 'handle_participant') def test_video_single_handler_process_track_compound_participant( mock_handler, mock_logger, orchard_client, create_product_message, video_single_product_with_track_compound_contributor): """Test for processing compound participant.""" handler = VideoSingleParticipantHandler( mock_logger, orchard_client, create_product_message, video_single_product_with_track_compound_contributor, 12345, None) contributor = video_single_product_with_track_compound_contributor[ 'productTracks'][0]['track']['contributors'][0] handle_participants_results = [ ( None, { 'artistName': 'Primary Composer', 'artistType': 'composer' } ), ( None, { 'artistName': 'With Composer', 'artistType': 'featuring' } ), ( None, { 'artistName': 'Featured Composer', 'artistType': 'featuring' } ) ] mock_handler.side_effect = handle_participants_results result = handler._process_track_compound_participant( contributor['participant'], 'composer') assert result == handle_participants_results assert mock_handler.call_count == 3 call_args = mock_handler.call_args_list name_roles = [(call_arg[0][0], call_arg[0][1]) for call_arg in call_args] assert name_roles == [ ( { 'ids': [{'localId': '101', 'system': 'SONY'}], 'members': [], 'name': 'Primary Composer' }, 'composer' ), ( { 'ids': [{'localId': '102', 'system': 'SONY'}], 'members': [], 'name': 'With Composer' }, 'featuring' ), ( { 'ids': [{'localId': '103', 'system': 'SONY'}], 'members': [], 'name': 'Featured Composer' }, 'featuring' ) ] @patch.object(VideoSingleParticipantHandler, 'handle_participant') def test_video_single_handler_process_contributors( mock_handler, mock_logger, orchard_client, create_product_message, video_single_product_with_track_contributors): """Test for processing contributors.""" handler = VideoSingleParticipantHandler( mock_logger, orchard_client, create_product_message, video_single_product_with_track_contributors, 12345, None) video = video_single_product_with_track_contributors contributors = video['productTracks'][0]['track']['contributors'] handle_participants_results = [ ( None, { 'artistName': 'Primary Composer', 'artistType': 'composer' } ), ( None, { 'artistName': 'With Composer', 'artistType': 'featuring' } ), ( None, { 'artistName': 'Featured Composer', 'artistType': 'featuring' } ), ( None, { 'artistName': 'Regular Producer', 'artistType': 'producer' } ) ] mock_handler.side_effect = handle_participants_results result = handler._process_contributors(contributors) assert result == handle_participants_results assert mock_handler.call_count == 4 args = mock_handler.call_args_list participant_roles = [(call_arg[0][0], call_arg[0][1]) for call_arg in args] assert participant_roles == [ ( { 'ids': [{'localId': '101', 'system': 'SONY'}], 'members': [], 'name': 'Primary Composer' }, 'composer' ), ( { 'ids': [{'localId': '102', 'system': 'SONY'}], 'members': [], 'name': 'With Composer' }, 'featuring' ), ( { 'ids': [{'localId': '103', 'system': 'SONY'}], 'members': [], 'name': 'Featured Composer' }, 'featuring' ), ( { 'ids': [{'localId': '1000001', 'system': 'SONY'}], 'members': [], 'name': 'Regular Producer' }, 'producer' ) ] @patch.object(VideoSingleParticipantHandler, 'handle_participant') def test_video_single_process_product_display_artist( mock_handler, mock_logger, orchard_client, create_product_message, video_single_product_with_display_artist): """Test for handling display artist.""" handler = VideoSingleParticipantHandler( mock_logger, orchard_client, create_product_message, video_single_product_with_display_artist, 12345, None) display_artist = video_single_product_with_display_artist['displayArtist'] handle_participants_results = [ ( None, { 'artistName': 'Primary Composer', 'artistType': 'composer' } ) ] mock_handler.side_effect = handle_participants_results result = handler._process_product_display_artist(display_artist) assert result == handle_participants_results assert mock_handler.call_count == 1 assert mock_handler.call_args_list[0][0][0] == { 'ids': [{'localId': '10001', 'system': 'SONY'}], 'name': 'Michael Jackson', 'members': [] } assert mock_handler.call_args_list[0][0][1] == 'performer' @patch.object(VideoSingleParticipantHandler, '_process_contributors') @patch.object(VideoSingleParticipantHandler, '_process_product_display_artist') @patch.object(VideoSingleParticipantHandler, '_process_track_display_artists') def test_video_single_process( mock_process_track_display_artist, mock_process_product_display_artist, mock_process_contributors, mock_logger, orchard_client, create_product_message, video_single_product_with_display_artist): """Test for handling display artist.""" handler = VideoSingleParticipantHandler( mock_logger, orchard_client, create_product_message, { 'displayArtist': {}, 'contributors': [], 'components': [{ 'sides': [{ 'productTracks': [ { 'track': { 'displayArtists': [], 'contributors': [], } } ], }] }], 'project': { 'labelAccount': { 'companyCode': 12345 } } }, 12345, None) mock_process_track_display_artist.return_value = [ ( 'processing_result_1', { 'artistName': 'Unique Track Performer', 'artistType': 'performer' } ), ( 'processing_result_2', { 'artistName': 'Common Performer', 'artistType': 'performer' } ) ] mock_process_product_display_artist.return_value = [ ( 'processing_result_3', { 'artistName': 'Unique Product Performer', 'artistType': 'performer' } ), ( None, { 'artistName': 'Common Performer', 'artistType': 'performer' } ) ] mock_process_contributors.side_effect = [ [ ( 'processing_result_4', { 'artistName': 'Contributor Track Producer', 'artistType': 'producer' } ), ], [] ] result = handler.process() processing_results = result[0] participants = result[1] assert processing_results == [ 'processing_result_1', 'processing_result_2', 'processing_result_3', 'processing_result_4'] assert participants == [ {'artistName': 'Unique Track Performer', 'artistType': 'performer'}, {'artistName': 'Common Performer', 'artistType': 'performer'}, {'artistName': 'Unique Product Performer', 'artistType': 'performer'}, {'artistName': 'Contributor Track Producer', 'artistType': 'producer'} ]