"""Test release correction.""" import json from mock import Mock import pytest from switchboard_consumer.constants.exceptions import ( ReleaseCorrectionError) from switchboard_consumer.logic.release_correction.release_correction import ( create_release_correction, create_release_correction_detail, delete_release_correction, diff_list_of_dicts, diff_product_artists, diff_products_for_release_correction, diff_track_artists, diff_track_writers, diff_tracks_for_release_correction, update_non_release_correctable_fields) from tests.conftest import correlation_id def test_successful_create_release_correction(orchard_client): """Test successful release correction.""" product_id = 12345 release_correction_response = { 'releaseCorrectionId': 67890 } orchard_client.create_release_correction.return_value = \ release_correction_response response = create_release_correction( product_id, orchard_client, correlation_id, Mock() ) assert response == release_correction_response['releaseCorrectionId'] def test_create_release_correction(orchard_client): """Test create release correction.""" product_id = 12345 expected = 67890 orchard_client.create_release_correction.return_value = { 'releaseCorrectionId': expected } response = create_release_correction( product_id, orchard_client, correlation_id, Mock() ) assert response == expected def test_create_release_correction_error(orchard_client): """Test create release correction.""" product_id = 12345 orchard_client.create_release_correction.return_value = { 'errors': ['Something'] } with pytest.raises(ReleaseCorrectionError): create_release_correction( product_id, orchard_client, correlation_id, Mock() ) def test_delete_release_correction(orchard_client): """Test delete release correction.""" product_id = 12345 release_correction_id = 67890 orchard_client.delete_release_correction.return_value = {'message': 'ok'} response = delete_release_correction( product_id, release_correction_id, orchard_client, correlation_id, Mock() ) assert not response def test_delete_release_correction_error(orchard_client): """Test delete release correction throws an exception on error.""" product_id = 12345 release_correction_id = 67890 orchard_client.delete_release_correction.return_value = {'errors': 'oh no'} with pytest.raises(ReleaseCorrectionError): delete_release_correction( product_id, release_correction_id, orchard_client, correlation_id, Mock() ) def test_create_release_correction_detail(orchard_client): """Test release correction detail.""" product_id = 12345 release_correction_id = 67890 orchard_client.create_release_correction_detail.return_value = {} response = create_release_correction_detail( product_id, release_correction_id, {}, orchard_client, correlation_id, Mock() ) assert not response def test_create_release_correction_detail_error(orchard_client): """Test release correction detail with errors.""" product_id = 12345 release_correction_id = 67890 orchard_client.create_release_correction_detail.return_value = ( {'errors': ['some_error']}) with pytest.raises(ReleaseCorrectionError): create_release_correction_detail( product_id, release_correction_id, {}, orchard_client, correlation_id, Mock() ) def test_diff_products_for_release_correction( orchard_product, switchboard_product_with_tracks): """Test for correct compare of SWB and Orchard product.""" switchboard_product_with_tracks['genres'] = [ { 'system': 'ORCHARD', 'genreId': 1, 'subGenres': [ { 'system': 'ORCHARD', 'subGenreId': 2 } ] }] switchboard_product_with_tracks['formalTitle'] = { 'titleText': 'NEW_PRODUCT_NAME', 'subTitle': 'NEW_VERSION'} switchboard_product_with_tracks['cLine']['cLineText'] = ( '2020 NEW_CLINE_TEXT') switchboard_product_with_tracks['metaLanguage'] = 'EN' updates = diff_products_for_release_correction( orchard_product, switchboard_product_with_tracks, None) assert updates == {'cLine': '"2020 NEW_CLINE_TEXT"', 'productName': '"NEW_PRODUCT_NAME"', 'imprint': '"Parkwood Entertainment/Columbia"', 'metaLanguage': '"ENG"', 'genreId': '1', 'subgenreId': '[2]', 'deliveredVersion': '"NEW_VERSION"'} def test_diff_products_for_release_correction_with_existing_rc( orchard_product, switchboard_product_with_tracks): """Test for correct compare of SWB and Orchard product with exiting rc.""" switchboard_product_with_tracks['genres'] = [ { 'system': 'ORCHARD', 'genreId': 1, 'subGenres': [ { 'system': 'ORCHARD', 'subGenreId': 2 } ] }] # Switchboard specifically has the same Product name as the Orchard switchboard_product_with_tracks['formalTitle'] = { 'titleText': 'OLD_PRODUCT_NAME', 'subTitle': 'NEW_VERSION'} switchboard_product_with_tracks['cLine']['cLineText'] = ( '2020 NEW_CLINE_TEXT') switchboard_product_with_tracks['metaLanguage'] = 'EN' # There is a release correction active with a new Product name existing_rc_items = [ { "releaseCorrectionDetailId": 4242969, "tableName": "releases", "fieldName": "release_name", "keyId": 2811782, "keyValue": "\"Ride on Cowboy 2\"" } ] updates = diff_products_for_release_correction( orchard_product, switchboard_product_with_tracks, existing_rc_items) # a correction should be created to change back to the old # product name to replicate UI behaviour assert updates == {'cLine': '"2020 NEW_CLINE_TEXT"', 'productName': '"OLD_PRODUCT_NAME"', 'imprint': '"Parkwood Entertainment/Columbia"', 'metaLanguage': '"ENG"', 'genreId': '1', 'subgenreId': '[2]', 'deliveredVersion': '"NEW_VERSION"'} def test_diff_products_for_release_correction_with_multiple_existing_rc( orchard_product, switchboard_product_with_tracks): """Test for correct compare of SWB and Orchard product with exiting rc.""" switchboard_product_with_tracks['genres'] = [ { 'system': 'ORCHARD', 'genreId': 1, 'subGenres': [ { 'system': 'ORCHARD', 'subGenreId': 2 } ] }] # Switchboard specifically has the same Product name as the Orchard switchboard_product_with_tracks['formalTitle'] = { 'titleText': 'OLD_PRODUCT_NAME', 'subTitle': 'NEW_VERSION'} switchboard_product_with_tracks['cLine']['cLineText'] = ( '2020 NEW_CLINE_TEXT') switchboard_product_with_tracks['metaLanguage'] = 'EN' # There is a release correction active with a new Product name # We should be using the 'newest' one as our comparison existing_rc_items = [ { "releaseCorrectionDetailId": 5, "tableName": "releases", "fieldName": "release_name", "keyId": 2811782, "keyValue": "\"OLD_PRODUCT_NAME\"" }, { "releaseCorrectionDetailId": 4242969, "tableName": "releases", "fieldName": "release_name", "keyId": 2811782, "keyValue": "\"Newer Product Name\"" } ] updates = diff_products_for_release_correction( orchard_product, switchboard_product_with_tracks, existing_rc_items) # a correction should be created to change back to the old # product name to replicate UI behaviour assert updates == {'cLine': '"2020 NEW_CLINE_TEXT"', 'productName': '"OLD_PRODUCT_NAME"', 'imprint': '"Parkwood Entertainment/Columbia"', 'metaLanguage': '"ENG"', 'genreId': '1', 'subgenreId': '[2]', 'deliveredVersion': '"NEW_VERSION"'} def test_diff_products_for_release_correction_with_rc_equal_to_existing_value( orchard_product, switchboard_product_with_tracks): """Test for correct compare of SWB and Orchard product with exiting rc.""" switchboard_product_with_tracks['genres'] = [ { 'system': 'ORCHARD', 'genreId': 1, 'subGenres': [ { 'system': 'ORCHARD', 'subGenreId': 2 } ] }] # Switchboard specifically has the same Product name as the Orchard switchboard_product_with_tracks['formalTitle'] = { 'titleText': 'OLD_PRODUCT_NAME', 'subTitle': 'NEW_VERSION'} switchboard_product_with_tracks['cLine']['cLineText'] = ( '2020 NEW_CLINE_TEXT') switchboard_product_with_tracks['metaLanguage'] = 'EN' # There is a release correction active with a new Product name. # We should be using the 'newest' one as our comparison. existing_rc_items = [ { "releaseCorrectionDetailId": 5, "tableName": "releases", "fieldName": "release_name", "keyId": 2811782, "keyValue": "\"New Product Name\"" }, { "releaseCorrectionDetailId": 4242969, "tableName": "releases", "fieldName": "release_name", "keyId": 2811782, "keyValue": "\"OLD_PRODUCT_NAME\"" } ] updates = diff_products_for_release_correction( orchard_product, switchboard_product_with_tracks, existing_rc_items) # The 'newest' item for product name is the same as the SWB value # so we should not create another error correction. assert updates == {'cLine': '"2020 NEW_CLINE_TEXT"', 'imprint': '"Parkwood Entertainment/Columbia"', 'metaLanguage': '"ENG"', 'genreId': '1', 'subgenreId': '[2]', 'deliveredVersion': '"NEW_VERSION"'} def test_diff_products_for_release_correction_with_formatter_field( orchard_product, switchboard_product_with_tracks): """Test for correct compare of SWB and Orchard product with exiting rc.""" # Genre fields are the same between SWB and Orchard switchboard_product_with_tracks['genres'] = [ { 'system': 'ORCHARD', 'genreId': 100, 'subGenres': [ { 'system': 'ORCHARD', 'subGenreId': 200 } ] }] switchboard_product_with_tracks['cLine']['cLineText'] = ( '2020 NEW_CLINE_TEXT') # A release correction has been made for the subgenre # (subGenre uses a formatter) existing_rc_items = [ { "releaseCorrectionDetailId": 4246314, "tableName": "releases", "fieldName": "release_subgenre", "keyId": 3227411, "keyValue": "[223]" } ] updates = diff_products_for_release_correction( orchard_product, switchboard_product_with_tracks, existing_rc_items) # Correction item should be made changing subgenreId to match SWB assert updates == {'subgenreId': '[200]', 'cLine': '"2020 NEW_CLINE_TEXT"', 'deliveredVersion': 'null', 'imprint': '"Parkwood Entertainment/Columbia"', 'metaLanguage': '"ENG"', 'productName': '"FORMAL_TITLE_ARTIST_NAME"'} def test_diff_products_for_release_correction_with_matching_formatter_field( orchard_product, switchboard_product_with_tracks): """Test for correct compare of SWB and Orchard product with exiting rc.""" # Genre fields are the same between SWB and Orchard switchboard_product_with_tracks['genres'] = [ { 'system': 'ORCHARD', 'genreId': 100, 'subGenres': [ { 'system': 'ORCHARD', 'subGenreId': 200 } ] }] switchboard_product_with_tracks['cLine']['cLineText'] = ( '2020 NEW_CLINE_TEXT') # A release correction has been made for the subgenre # (subGenre uses a formatter) existing_rc_items = [ { "releaseCorrectionDetailId": 4246314, "tableName": "releases", "fieldName": "release_subgenre", "keyId": 3227411, "keyValue": "[200]" } ] updates = diff_products_for_release_correction( orchard_product, switchboard_product_with_tracks, existing_rc_items) # a new correction item should not be made for the subgenre id assert updates == {'cLine': '"2020 NEW_CLINE_TEXT"', 'deliveredVersion': 'null', 'imprint': '"Parkwood Entertainment/Columbia"', 'metaLanguage': '"ENG"', 'productName': '"FORMAL_TITLE_ARTIST_NAME"'} @pytest.mark.parametrize( 'orchard_artists, sony_artists, expected', [ ( [ { 'artistId': '6036995', 'artistName': 'Dr Zeus', 'artistType': 'primary_artist', 'artistInfoId': 1956160 }, { 'artistId': '6036996', 'artistName': 'Snoop Dogg', 'artistType': 'featuring', 'artistInfoId': 1956161 }, ], [ { 'artistId': '6036995', 'artistName': 'Dr Zeus', 'artistType': 'primary_artist', 'artistInfoId': 1956160 }, ], { 'performer': json.dumps([ {'artist_name': 'Dr Zeus', 'role': 'performer'} ]), 'remixer': json.dumps([]), 'producer': json.dumps([]), 'featuring': json.dumps([]) } ), ( [ { 'artistId': '6036995', 'artistName': 'Dr Zeus', 'artistType': 'primary_artist', 'artistInfoId': 1956160 }, { 'artistId': '6036996', 'artistName': 'Snoop Dogg', 'artistType': 'featuring', 'artistInfoId': 1956161 }, ], [ { 'artistId': '6036995', 'artistName': 'Dr Zeus', 'artistType': 'primary_artist', 'artistInfoId': 1956160 }, { 'artistId': '6036996', 'artistName': 'Snoop Dogg', 'artistType': 'producer', 'artistInfoId': 1956161 }, { 'artistId': '6036997', 'artistName': 'Dr Remixer', 'artistType': 'remixer', 'artistInfoId': 1956162 }, { 'artistId': '6036997', 'artistName': 'Ice Cube', 'artistType': 'featuring', 'artistInfoId': 1956162 } ], { 'performer': json.dumps([ { 'artist_name': 'Dr Zeus', 'role': 'performer', }, ]), 'producer': json.dumps([ { 'artist_name': 'Snoop Dogg', 'role': 'producer', }, ]), 'remixer': json.dumps([ { 'artist_name': 'Dr Remixer', 'role': 'remixer', }, ]), 'featuring': json.dumps([ { 'artist_name': 'Ice Cube', 'role': 'featuring', }, ]), } ), ( [ { 'artistId': '6036995', 'artistName': 'Dr Zeus', 'artistType': 'primary_artist', 'artistInfoId': 1956160 }, { 'artistId': '6036996', 'artistName': 'Snoop Dogg', 'artistType': 'featuring', 'artistInfoId': 1956161 }, ], [ { 'artistId': '6036995', 'artistName': 'Dr Zeus', 'artistType': 'primary_artist', 'artistInfoId': 1956160 }, { 'artistId': '6036996', 'artistName': 'Snoop Dogg', 'artistType': 'featuring', 'artistInfoId': 1956161 }, ], {} ), ( [ { 'artistId': '6036995', 'artistName': 'Dr Zeus', 'artistType': 'primary_artist', 'artistInfoId': 1956160 }, { 'artistId': '6036996', 'artistName': 'Snoop Dogg', 'artistType': 'featuring', 'artistInfoId': 1956161 }, ], [ { 'artistId': '6036995', 'artistName': 'Dr Zeus', 'artistType': 'primary_artist', 'artistInfoId': 1956160 }, { 'artistId': '6036996', 'artistName': 'Snoop Dogg', 'artistType': 'featuring', 'artistInfoId': 1956161 }, # Composer is not supported at the Product level for Orchard { 'artistId': '6036996', 'artistName': 'Snoop Dogg', 'artistType': 'composer', 'artistInfoId': 1956161 } ], # No difference detected {} ), ] ) def test_diff_product_artists(orchard_artists, sony_artists, expected): output = diff_product_artists(orchard_artists, sony_artists) assert output == expected @pytest.mark.parametrize( 'orchard_artists, sony_artists, expected', [ ( [ { 'artistId': '6036995', 'artistName': 'Dr Zeus', 'artistType': 'primary_artist', 'artistInfoId': 1956160 }, { 'artistId': '6036996', 'artistName': 'Snoop Dogg', 'artistType': 'featuring', 'artistInfoId': 1956161 }, ], [ { 'artistId': '6036995', 'artistName': 'Dr Zeus', 'artistType': 'primary_artist', 'artistInfoId': 1956160 }, ], [ { 'artistId': '6036996', 'artistName': 'Snoop Dogg', 'artistType': 'featuring', 'artistInfoId': 1956161 } ] ), ( [ { 'artistId': '6036995', 'artistName': 'Dr Zeus', 'artistType': 'primary_artist', 'artistInfoId': 1956160 }, { 'artistId': '6036996', 'artistName': 'Snoop Dogg', 'artistType': 'featuring', 'artistInfoId': 1956161 }, ], [ { 'artistId': '6036995', 'artistName': 'Dr Zeus', 'artistType': 'primary_artist', 'artistInfoId': 1956160 }, { 'artistId': '6036996', 'artistName': 'Snoop Dogg', 'artistType': 'producer', 'artistInfoId': 1956161 }, { 'artistId': '6036997', 'artistName': 'Dr Remixer', 'artistType': 'remixer', 'artistInfoId': 1956162 }, { 'artistId': '6036997', 'artistName': 'Ice Cube', 'artistType': 'featuring', 'artistInfoId': 1956162 } ], [ { 'artistId': '6036996', 'artistName': 'Snoop Dogg', 'artistType': 'featuring', 'artistInfoId': 1956161 }, { 'artistId': '6036996', 'artistName': 'Snoop Dogg', 'artistType': 'producer', 'artistInfoId': 1956161 }, { 'artistId': '6036997', 'artistName': 'Dr Remixer', 'artistType': 'remixer', 'artistInfoId': 1956162 }, { 'artistId': '6036997', 'artistName': 'Ice Cube', 'artistType': 'featuring', 'artistInfoId': 1956162 } ] ), ( [ { 'artistId': '6036995', 'artistName': 'Dr Zeus', 'artistType': 'primary_artist', 'artistInfoId': 1956160 }, { 'artistId': '6036996', 'artistName': 'Snoop Dogg', 'artistType': 'featuring', 'artistInfoId': 1956161 }, ], [ { 'artistId': '6036995', 'artistName': 'Dr Zeus', 'artistType': 'primary_artist', 'artistInfoId': 1956160 }, { 'artistId': '6036996', 'artistName': 'Snoop Dogg', 'artistType': 'featuring', 'artistInfoId': 1956161 }, ], [] ), ] ) def test_diff_list_of_dicts(orchard_artists, sony_artists, expected): output = diff_list_of_dicts(orchard_artists, sony_artists) assert output == expected def test_diff_tracks_for_release_correction( formatted_track): """Test release correct diff of SWB and Orchard track.""" orchard_tracks = [ formatted_track ] sony_tracks = [ { **formatted_track, 'lyrics': 'I am different lyrics', 'pInfo': '2020 different pInfo', 'trackName': 'Different', 'explicit': 'Y', 'metaLanguageCode': 'JPN' } ] updates = diff_tracks_for_release_correction(orchard_tracks, sony_tracks, Mock()) assert updates == { formatted_track['tuid']: [ ('trackName', '"Different"'), ('explicit', '"Y"'), ('pInfo', '"2020 different pInfo"'), ('metaLanguageCode', '"JPN"'), ('lyrics', '"I am different lyrics"') ], } def test_diff_tracks_for_release_correction_black_lyrics( formatted_track): """ Test release correct diff of SWB and Orchard track when there are no lyrics in SWB. """ orchard_tracks = [ formatted_track ] sony_tracks = [ { **formatted_track, 'pInfo': '2020 different pInfo', 'trackName': 'Different', 'explicit': 'Y', 'metaLanguageCode': 'JPN' } ] del sony_tracks[0]['lyrics'] updates = diff_tracks_for_release_correction(orchard_tracks, sony_tracks, Mock()) assert updates == { formatted_track['tuid']: [ ('trackName', '"Different"'), ('explicit', '"Y"'), ('pInfo', '"2020 different pInfo"'), ('metaLanguageCode', '"JPN"') ], } def test_diff_multiple_tracks_for_release_correction( formatted_track): """Test release correct diff of SWB and Orchard track.""" orchard_tracks = [ formatted_track, { **formatted_track, 'tuid': '4000', 'isrc': 'GBJCP1925202' }, { **formatted_track, 'tuid': '5000', 'isrc': 'GBJCP1925203' } ] sony_tracks = [ { **formatted_track, 'lyrics': 'I am different lyrics', 'pInfo': '2020 different pInfo', 'trackName': 'Different', 'explicit': 'Y', 'metaLanguageCode': 'JPN' }, # All changes { **formatted_track, 'tuid': '4000', 'isrc': 'GBJCP1925202', 'trackName': 'Very cool' }, # Partial changes { **formatted_track, 'tuid': '5000', 'isrc': 'GBJCP1925203' } # No changes ] updates = diff_tracks_for_release_correction(orchard_tracks, sony_tracks, Mock()) assert updates == { formatted_track['tuid']: [ ('trackName', '"Different"'), ('explicit', '"Y"'), ('pInfo', '"2020 different pInfo"'), ('metaLanguageCode', '"JPN"'), ('lyrics', '"I am different lyrics"') ], '4000': [ ('trackName', '"Very cool"'), ] } def test_diff_multiple_tracks_removed_track( formatted_track): """Test tracks removed from Sony""" orchard_tracks = [ formatted_track, { **formatted_track, 'tuid': '4000', 'isrc': 'GBJCP1925202' } # This track is missing from the Sony data ] sony_tracks = [ { **formatted_track, 'lyrics': 'I am different lyrics', 'pInfo': '2020 different pInfo', 'trackName': 'Different', 'explicit': 'Y', 'metaLanguageCode': 'JPN' } ] with pytest.raises(ReleaseCorrectionError): diff_tracks_for_release_correction(orchard_tracks, sony_tracks, Mock()) def test_diff_multiple_tracks_added_track( formatted_track): """Test tracks added to Sony.""" orchard_tracks = [ formatted_track, ] sony_tracks = [ { **formatted_track, 'lyrics': 'I am different lyrics', 'pInfo': '2020 different pInfo', 'trackName': 'Different', 'explicit': 'Y', 'metaLanguageCode': 'JPN' }, { **formatted_track, 'isrc': 'GBJCP1925203' } # This track is new ] with pytest.raises(ReleaseCorrectionError): diff_tracks_for_release_correction(orchard_tracks, sony_tracks, Mock()) def test_diff_track_artists_for_release_correction( formatted_track): """Test release correct diff of SWB and Orchard track artists.""" orchard_tracks = [ formatted_track, { **formatted_track, 'tuid': '4000', 'isrc': 'GBJCP1925202' }, { **formatted_track, 'tuid': '5000', 'isrc': 'GBJCP1925203' } ] sony_tracks = [ { **formatted_track, 'artists': [ {'artistName': 'New Performer', 'artistType': 'performer'}, {'artistName': 'New Performer 2', 'artistType': 'performer'}, {'artistName': 'New Featuring', 'artistType': 'featuring'}, {'artistName': 'New Remixer', 'artistType': 'remixer'}, {'artistName': 'New Producer', 'artistType': 'producer'}, ], }, # All changes { **formatted_track, 'tuid': '4000', 'isrc': 'GBJCP1925202', 'artists': [ *formatted_track['primaryArtists'], {'artistName': 'Snoop Dogg', 'artistType': 'featuring'}, ], }, # Partial changes { **formatted_track, 'artists': formatted_track['primaryArtists'], 'tuid': '5000', 'isrc': 'GBJCP1925203' } # No changes ] updates = diff_track_artists(orchard_tracks, sony_tracks) assert updates == { '30479462': [ ('track_artist', ('[{"name": "New Performer", "type": "performer"}, ' '{"name": "New Performer 2", "type": "performer"}]')), ('featuring', '[{"name": "New Featuring", "type": "featuring"}]'), ('remixer', '[{"name": "New Remixer", "type": "remixer"}]'), ('producer', '[{"name": "New Producer", "type": "producer"}]') ], '4000': [ ('track_artist', '[{"name": "Snoop Dogg", "type": "performer"}]'), ('featuring', ('[{"name": "Dr. Dre", "type": "featuring"}, ' '{"name": "Snoop Dogg", "type": "featuring"}]')), ('remixer', '[{"name": "Cool Remixer", "type": "remixer"}]'), ('producer', '[{"name": "Cool Producer", "type": "producer"}]') ]} def test_diff_track_writers_for_release_correction( formatted_track): """Test release correct diff of SWB and Orchard track writers.""" orchard_tracks = [ formatted_track, { **formatted_track, 'tuid': '4000', 'isrc': 'GBJCP1925202' }, { **formatted_track, 'tuid': '5000', 'isrc': 'GBJCP1925203' } ] sony_tracks = [ { **formatted_track, 'writers': [ {'writerName': 'New Writer', 'writerType': 'writer'}, {'writerName': 'New Writer 2', 'writerType': 'writer'}, ] }, # All changes { **formatted_track, 'tuid': '4000', 'isrc': 'GBJCP1925202', 'writers': [ *formatted_track['writers'], {'writerName': 'Appended Writer', 'writerType': 'writer'}, ], }, # Partial changes { **formatted_track, 'tuid': '5000', 'isrc': 'GBJCP1925203' } # No changes ] updates = diff_track_writers(orchard_tracks, sony_tracks) assert updates == { '30479462': [('track_writer', '["New Writer", "New Writer 2"]')], '4000': [ ('track_writer', '["Snoop Dogg", "Dr. Dre", "Appended Writer"]') ] } def test_update_non_release_correctable_fields( create_product_message, orchard_product, switchboard_product_with_tracks, formatted_track, orchard_client): orchard_client.update_non_release_correctable_product_fields = Mock() orchard_client.update_tracks = Mock() output = update_non_release_correctable_fields( orchard_product, switchboard_product_with_tracks, [formatted_track], create_product_message, orchard_client, Mock() ) orchard_client \ .update_non_release_correctable_product_fields.assert_called_once() orchard_client.update_tracks.assert_called_once() assert not output def test_update_non_release_correctable_fields_on_product_error( create_product_message, orchard_product, switchboard_product_with_tracks, formatted_track, orchard_client): orchard_client.\ update_non_release_correctable_product_fields.return_value = { 'errors': 'something' } orchard_client.update_tracks = Mock() output = update_non_release_correctable_fields( orchard_product, switchboard_product_with_tracks, [formatted_track], create_product_message, orchard_client, Mock() ) orchard_client \ .update_non_release_correctable_product_fields.assert_called_once() orchard_client.update_tracks.assert_not_called() assert output['errors'] def test_update_non_release_correctable_fields_on_track_error( create_product_message, orchard_product, switchboard_product_with_tracks, formatted_track, orchard_client): orchard_client.update_non_release_correctable_product_fields = Mock() orchard_client.update_tracks.return_value = { 'errors': 'something' } output = update_non_release_correctable_fields( orchard_product, switchboard_product_with_tracks, [formatted_track], create_product_message, orchard_client, Mock() ) orchard_client \ .update_non_release_correctable_product_fields.assert_called_once() orchard_client.update_tracks.assert_called_once() assert output['errors']