"""Test validation formatting.""" import pytest from product_digital.logic import validation as validation_logic @pytest.fixture def mock_valid_product_response(): """Mocked valid product response.""" return { 'validations': { 'product_basics': { 'valid': True, 'errors': {} }, 'product_artists': { 'valid': True, 'errors': {} }, 'scheduling_and_pricing': { 'valid': True, 'errors': {} }, 'artwork': { 'valid': True, 'errors': [] }, 'tracks': { 'valid': True, 'errors': [], 'total_tracks': 1, 'valid_tracks': 1 }, 'publishing_obligation': { 'valid': True, 'errors': [], 'total_tracks': 1, 'valid_tracks': 1 }, 'product_blocklist': { 'valid': True, 'errors': [] }, 'account': { 'valid': True, 'errors': [] } } } @pytest.fixture def mock_invalid_product_response(): """Mocked invalid product response.""" return { 'validations': { 'product_basics': { 'valid': False, 'errors': { 'c_line': { 'validator': 'required', 'validator_value': True, 'message': "'c_line' is a required property", 'error_code': 'c_line_required' }, 'genre_id': { 'validator': 'required', 'validator_value': True, 'message': "'genre_id' is a required property", 'error_code': 'genre_id_required' }, 'imprint': { 'validator': 'required', 'validator_value': True, 'message': "'imprint' is a required property", 'error_code': 'imprint_required' }, 'subgenre_id': { 'validator': 'required', 'validator_value': True, 'message': "'subgenre_id' is a required property", 'error_code': 'subgenre_id_required' }, 'primary_artist': { 'validator': 'required', 'validator_value': True, 'message': "'primary_artist' is a required property", 'error_code': 'primary_artist_required' } } }, 'scheduling_and_pricing': { 'valid': False, 'errors': { 'release_date': { 'validator': 'required', 'validator_value': True, 'message': "'release_date' is a required property", 'error_code': 'release_date_required' }, 'sale_start_date': { 'validator': 'required', 'validator_value': True, 'message': "'sale_start_date' is a required property", 'error_code': 'sale_start_date_required' } } }, 'artwork': { 'valid': False, 'errors': [ 'Artwork has not been uploaded successfully.' ] }, 'tracks': { 'valid': False, 'errors': [ { 'meta_language_code': { 'validator': 'required', 'validator_value': True, 'message': 'Field `meta_language_code` is required', 'error_code': 'missing_meta_language_code' }, 'p_info': { 'validator': 'required', 'validator_value': True, 'message': 'Field `p_info` is required', 'error_code': 'missing_p_info' }, 'explicit': { 'validator': 'required', 'validator_value': True, 'message': 'Field `explicit` is required', 'error_code': 'missing_explicit' }, 'ownership_rights': { 'validator': 'required', 'validator_value': True, 'message': 'Field `ownership_rights` is required', 'error_code': 'missing_ownership_rights' }, 'writers': { 'validator': 'required', 'validator_value': True, 'message': 'Field `writers` is required', 'error_code': 'missing_writers' }, 'audio_file': { 'validator': 'required', 'validator_value': True, 'message': 'Field `audio_file` is required', 'error_code': 'missing_audio_file' }, 'localizations': [ { 'validator': 'required', 'validator_value': True, 'message': ( 'Please select Chinese Simplified as a localization, as Chinese Traditional ' 'is already selected as the product metadata language. Both variations of the ' 'Chinese written language are required for delivery.' ), 'error_code': 'missing_chinese_localization' } ], 'tuid': 41108066 } ], 'warnings': [ { 'cross_track_isrc_mismatch': { 'validator': 'cross_track_isrc_mismatch', 'validator_value': True, 'message': ( '{"matches": [{"tuid": 29222639, "isrc": "SE4NI1600601", "product_id": 2505973, ' '"upc": "7320470214091", "release_status": "in_content", "subaccount_id": 0, ' '"vendor_id": 29930}]}' ), 'code': 'cross_track_isrc_mismatch' }, 'tuid': 41108066 } ], 'total_tracks': 1, 'valid_tracks': 0 }, 'publishing_obligation': { 'valid': False, 'errors': [ { 'us_publishing_obligation': { 'validator': 'required', 'validator_value': True, 'message': 'Field `us_publishing_obligation` is required', 'error_code': 'missing_us_publishing_obligation' }, 'tuid': 41108066 } ], 'total_tracks': 1, 'valid_tracks': 0 }, 'product_artists': { 'valid': True, 'errors': {}, 'warnings': [] }, 'product_blocklist': { 'valid': False, 'errors': [ { 'word': 'Orchard', 'reason': 'Sony/Orchard Trademark', 'alert': ( 'Metadata contains the words \"Sony\" and/or \"Orchard.\" The Sony and Orchard brands ' 'should only be used in Release Imprint, C-Line, or P-Line metadata for products owned or ' 'published by Sony or The Orchard. If the Release Imprint, C-Line, or P-Line contains ' "\"Sony\" and/or \"Orchard,\" and you're not sure whether this release is from a " 'Sony-owned or Orchard-owned label, consult our legal team.' ), 'contact': 'legal@theorchard.com', 'matched_field': 'artist_name' } ] }, 'account': { 'valid': False, 'errors': [ { 'code': 'ACCOUNT_BLOCKLIST', 'reason': ( 'This content is from a blocked account and cannot be approved. ' 'Please reach out to QC, Operations or Contract Admin for more information.' ) } ] } } } def test_format_valid_product_validations_as_list(mock_valid_product_response): """Test formatting a valid product's validation response as a list.""" actual = validation_logic.format_validations_as_list(mock_valid_product_response['validations']) assert actual == {'errors': [], 'is_valid': True, 'tracks': {}, 'warnings': []} def test_format_invalid_product_validations_as_list(mock_invalid_product_response): """Test formatting an invalid product's validation response as a list.""" actual = validation_logic.format_validations_as_list(mock_invalid_product_response['validations']) assert actual == { 'errors': [ { 'code': 'C_LINE_REQUIRED', 'reason': "'c_line' is a required property" }, { 'code': 'GENRE_ID_REQUIRED', 'reason': "'genre_id' is a required property" }, { 'code': 'IMPRINT_REQUIRED', 'reason': "'imprint' is a required property" }, { 'code': 'SUBGENRE_ID_REQUIRED', 'reason': "'subgenre_id' is a required property" }, { 'code': 'PRIMARY_ARTIST_REQUIRED', 'reason': "'primary_artist' is a required property" }, { 'code': 'RELEASE_DATE_REQUIRED', 'reason': "'release_date' is a required property" }, { 'code': 'SALE_START_DATE_REQUIRED', 'reason': "'sale_start_date' is a required property" }, { 'code': 'ARTWORK', 'reason': 'Artwork has not been uploaded successfully.' }, { 'code': 'ACCOUNT_BLOCKLIST', 'reason': ( 'This content is from a blocked account and cannot be ' 'approved. Please reach out to QC, Operations or ' 'Contract Admin for more information.' ) } ], 'is_valid': False, 'tracks': { '41108066': { 'errors': [ { 'code': 'MISSING_META_LANGUAGE_CODE', 'reason': 'Field `meta_language_code` is required' }, { 'code': 'MISSING_P_INFO', 'reason': 'Field `p_info` is required' }, { 'code': 'MISSING_EXPLICIT', 'reason': 'Field `explicit` is required' }, { 'code': 'MISSING_OWNERSHIP_RIGHTS', 'reason': 'Field `ownership_rights` is required' }, { 'code': 'MISSING_WRITERS', 'reason': 'Field `writers` is required' }, { 'code': 'MISSING_AUDIO_FILE', 'reason': 'Field `audio_file` is required' }, { 'code': 'MISSING_CHINESE_LOCALIZATION', 'reason': ( 'Please select Chinese Simplified as a localization, ' 'as Chinese Traditional is already selected as the ' 'product metadata language. Both variations of the Chinese ' 'written language are required for delivery.' ) }, { 'code': 'MISSING_US_PUBLISHING_OBLIGATION', 'reason': 'Field `us_publishing_obligation` is required' } ], 'is_valid': False, 'tuid': 41108066, 'warnings': [ { 'code': 'CROSS_TRACK_ISRC_MISMATCH', 'reason': ( '{"matches": [{"tuid": 29222639, "isrc": "SE4NI1600601", ' '"product_id": 2505973, "upc": "7320470214091", ' '"release_status": "in_content", ' '"subaccount_id": 0, "vendor_id": 29930}]}' ) } ] } }, 'warnings': [ { 'code': 'BLOCKLIST', 'reason': ( '{"word": "Orchard", "reason": "Sony/Orchard ' 'Trademark", "alert": "Metadata contains the words ' '\\"Sony\\" and/or \\"Orchard.\\" The Sony and ' 'Orchard brands should only be used in Release ' 'Imprint, C-Line, or P-Line metadata for products ' 'owned or published by Sony or The Orchard. If the ' 'Release Imprint, C-Line, or P-Line contains ' '\\"Sony\\" and/or \\"Orchard,\\" and you\'re not ' 'sure whether this release is from a Sony-owned or ' 'Orchard-owned label, consult our legal team.", ' '"contact": "legal@theorchard.com", "matched_field": ' '"artist_name"}' ) } ] }