"""Tests for formatters/video_single_product.""" import pytest from switchboard_consumer.formatters.video_single_product import \ _format_channel_selection, _get_associated_track_id, \ _get_language_of_video_title, format_type_of_video, \ format_video_single_create_input, format_video_single_update_input @pytest.fixture def video_single_preprocessed_data(): """Video single product data.""" return { 'ids': [ { 'localId': 'G010000529422G', 'system': 'SONY' } ], 'upc': '111110191721', 'displayArtist': { 'ids': [ { 'localId': '89120', 'system': 'SONY' } ], 'name': 'Cyndi Lauper', 'members': [] }, 'contributors': [], 'formalTitle': { 'titleText': 'The Goonies 'R' Good Enough', 'subTitle': 'VERSION_SUB_TITLE' }, 'localizedTitles': [], 'localizedSubTitles': [], 'catalogNumber': 'G010000529422G', 'releaseType': 'VIDEO_SINGLE', 'originalReleaseDate': None, 'salesStartDate': '2004-09-01', 'preOrderDate': None, 'productType': 'DIGITAL', 'metaLanguage': 'en', 'commercialType': 'COMMERCIAL', 'genres': [ { 'system': 'ORCHARD', 'genreId': 1, 'subGenres': [{'subGenreId': 10}] }, { 'system': 'SONY', 'genreId': 20, 'subGenres': [{'subGenreId': 47}] } ], 'cLine': { 'cLineText': '1985 C_LINE' }, 'pLine': { 'pLineText': '1995 P_LINE' }, 'labelAccount': { 'companyCode': '10203040' }, 'subAccount': { 'companyCode': '50607080' }, 'maintenanceOwner': { 'companyCode': 'C285', 'companyType': 'SME_MAINTENANCE_OWNER', 'territoryCode': 'US', 'name': 'Legacy Recordings', 'catalogOriginalOwner': None }, 'repertoireOwner': { 'companyCode': 'D670', 'companyType': 'SME_REPERTOIRE_OWNER', 'territoryCode': 'US', 'name': 'Epic', 'catalogOriginalOwner': None }, 'imprint': { 'companyCode': 'AAHR:0000', 'companyType': 'SME_IMPRINT_LABEL', 'territoryCode': None, 'name': 'Epic', 'catalogOriginalOwner': None }, 'lastChanged': '2016-05-18 16:01:05.287', 'labelName': None, 'project': { 'ids': [ { 'localId': '1000072', 'system': 'SONY' }, { 'localId': 'ORCHARD_PROJECT_ID', 'system': 'ORCHARD' } ], 'artist': { 'ids': [ { 'localId': '99999', 'system': 'SONY' }, { 'localId': 'AIID:1751741', 'system': 'ORCHARD' } ], 'name': 'Various' }, 'labelAccount': None, 'subAccount': None }, 'components': [{ 'sides': [{ 'productTracks': [ { 'componentNumber': 1, 'sequenceNumber': 1, 'track': { 'ids': [ { 'localId': 'J1249443420050610:', 'system': 'SONY' } ], 'isrc': 'USSM20301425', 'grid': None, 'displayTitle': 'The Goonies 'r' Good Enough', 'formalTitle': { 'titleText': 'The Goonies 'r' Good Enough', 'subTitle': None }, 'displayArtists': [], 'contributors': [], 'metaLanguage': 'en', 'lyrics': 'SOME_LYRICS', 'trackMedia': 'VIDEO', 'trackType': 'TRACK', 'videoType': 'OFFICIAL_MUSIC_VIDEO', 'durationInSeconds': 217, 'parentalWarningType': 'EXPLICIT', 'pLine': { 'pLineText': None }, 'recordingCountry': 'US', 'masterOwnershipType': 'OWNED', 'copyrightOwnerCountry': None, 'samples': None, 'publishers': [], 'languageOfPerformance': 'ru', 'relatedAudioTrack': None }, 'displayTitle': None, 'localTrackId': None, 'localTrackTerritoryCode': None } ], }] }], 'switchboardExtensions': { 'governingDeal': { 'dealResponsibilities': [ { 'dealResponsibilityType': { 'name': 'Digital Distribution' }, 'appliesTo': 'WORLDWIDE', 'assignments': [ { 'system': 'ORCHARD' } ] } ] } }, 'description': 'DESCRIPTION' } def test_format_video_single_create_input(video_single_preprocessed_data): """Test for correct formatting for create product.""" artists = [{ 'artistName': 'NAME', 'artistType': 'ROLE'}] result = format_video_single_create_input( video_single_preprocessed_data, artists) assert result == { 'accountId': 10203040, 'associatedTrackId': None, 'channelSelection': None, 'clineCopyrightHolder': 'C_LINE', 'clineYear': 1985, 'description': 'DESCRIPTION', 'genreId': 1, 'imprint': 'Epic', 'isrc': 'USSM20301425', 'languageOfVideoContent': 'RUS', 'languageOfVideoTitle': 'ENG', 'lyrics': 'SOME_LYRICS', 'parentalAdvisory': 'Yes', 'plineCopyrightHolder': 'P_LINE', 'plineYear': 1995, 'primaryArtists': artists, 'productCode': 'G010000529422G', 'projectId': 'ORCHARD_PROJECT_ID', 'subaccountId': 50607080, 'subgenreId': 10, 'typeOfVideo': 'Official Music Video', 'upc': '111110191721', 'version': 'VERSION_SUB_TITLE', 'videoTitle': 'The Goonies Good Enough', 'specialInstructions': 'Switchboard Deal Summary:\n' 'Digital Distribution: ORCHARD WORLDWIDE', 'notForDistribution': 'N' } def test_format_video_single_create_input_no_pline( video_single_preprocessed_data): """Test for correct formatting for create product with no pline.""" artists = [{ 'artistName': 'NAME', 'artistType': 'ROLE'}] video_single_preprocessed_data['pLine'] = None result = format_video_single_create_input( video_single_preprocessed_data, artists) assert result == { 'accountId': 10203040, 'associatedTrackId': None, 'channelSelection': None, 'clineCopyrightHolder': 'C_LINE', 'clineYear': 1985, 'description': 'DESCRIPTION', 'genreId': 1, 'imprint': 'Epic', 'isrc': 'USSM20301425', 'languageOfVideoContent': 'RUS', 'languageOfVideoTitle': 'ENG', 'lyrics': 'SOME_LYRICS', 'parentalAdvisory': 'Yes', 'plineCopyrightHolder': 'C_LINE', 'plineYear': 1985, 'primaryArtists': artists, 'productCode': 'G010000529422G', 'projectId': 'ORCHARD_PROJECT_ID', 'subaccountId': 50607080, 'subgenreId': 10, 'typeOfVideo': 'Official Music Video', 'upc': '111110191721', 'version': 'VERSION_SUB_TITLE', 'videoTitle': 'The Goonies Good Enough', 'specialInstructions': 'Switchboard Deal Summary:\n' 'Digital Distribution: ORCHARD WORLDWIDE', 'notForDistribution': 'N' } def test_format_video_single_update_input(video_single_preprocessed_data): """Test for correct formatting for update product.""" artists = [{ 'artistName': 'NAME', 'artistType': 'ROLE'}] video_single_preprocessed_data['ids'] = [ { 'system': 'SONY', 'localId': 'SONY_PRODUCT_ID' }, { 'system': 'ORCHARD', 'localId': 'ORCHARD_PRODUCT_ID' } ] result = format_video_single_update_input( video_single_preprocessed_data, artists) assert result == { 'accountId': 10203040, 'associatedTrackId': None, 'channelSelection': None, 'clineCopyrightHolder': 'C_LINE', 'clineYear': 1985, 'description': 'DESCRIPTION', 'genreId': 1, 'imprint': 'Epic', 'languageOfVideoContent': 'RUS', 'languageOfVideoTitle': 'ENG', 'lyrics': 'SOME_LYRICS', 'parentalAdvisory': 'Yes', 'plineCopyrightHolder': 'P_LINE', 'plineYear': 1995, 'primaryArtists': artists, 'productId': 'ORCHARD_PRODUCT_ID', 'subaccountId': 50607080, 'subgenreId': 10, 'typeOfVideo': 'Official Music Video', 'version': 'VERSION_SUB_TITLE', 'videoTitle': 'The Goonies Good Enough', 'specialInstructions': 'Switchboard Deal Summary:\n' 'Digital Distribution: ORCHARD WORLDWIDE', 'notForDistribution': 'N' } def test_get_language_of_video_title_from_product(): """Extracting from product first.""" product = {'metaLanguage': 'en'} track = {'metaLanguage': 'ru'} result = _get_language_of_video_title(product, track) assert result == 'ENG' def test_get_language_of_video_title_from_track(): """Extracting from track if not found in product.""" product = {'metaLanguage': None} track = {'metaLanguage': 'ru'} result = _get_language_of_video_title(product, track) assert result == 'RUS' def test_get_language_of_video_title_not_found(): """Failed to extract from track and product.""" product = {'metaLanguage': None} track = {'metaLanguage': None} result = _get_language_of_video_title(product, track) assert result is None def test_format_channel_selection_not_found(): """Test for channel extraction.""" product_data = { 'channelSet': None } result = _format_channel_selection(product_data) assert result is None def test_format_channel_selection_found(): """Test for channel extraction.""" product_data = { 'channelSet': [ { 'storeId': 100, 'channelCode': 'channelVEVO' } ] } result = _format_channel_selection(product_data) assert result == 'channelVEVO' def test_get_associated_track_id_not_found(): """Test for None is track not found.""" result = _get_associated_track_id({ 'relatedAudioTrack': None }) assert result is None def test_get_associated_track_id_found(): """Test for correct extraction.""" result = _get_associated_track_id( { 'relatedAudioTrack': { 'ids': [ { 'localId': '100001', 'system': 'SONY' }, { 'localId': '12345', 'system': 'ORCHARD' } ] } } ) assert result == 12345 @pytest.mark.parametrize('type_of_video,expected', [ (None, None), ('OFFICIAL_MUSIC_VIDEO', 'Official Music Video'), ]) def test_format_type_of_video(type_of_video, expected): """Test format type of video.""" actual = format_type_of_video(type_of_video) assert actual == expected