"""Conftest.""" import os from types import SimpleNamespace from bulk_metadata_ingester_common.models.base_csv import TableRowModel from ddex_ingester_common.constants.xmltodict import DDEX_LIST_FIELDS import pytest import xmltodict def parse_xml_to_dict(xml): """Parse given XML file using xmltodict.parse().""" with open(os.open(xml, os.O_RDONLY)) as fd: return xmltodict.parse(fd.read(), force_list=DDEX_LIST_FIELDS) @pytest.fixture def ddex_fluve_single(): """DDEX document deserialized into a dict.""" return parse_xml_to_dict('tests/unit/data/7892920178708.xml') @pytest.fixture def ddex_fluve_multiple_tracks(): """DDEX document deserialized into a dict.""" return parse_xml_to_dict('tests/unit/data/7892920191103.xml') @pytest.fixture def ddex_sony_album(): """DDEX document deserialized into a dict.""" return parse_xml_to_dict('tests/unit/data/ddex-album.xml') @pytest.fixture def test_event(): """Test event fixture for handler.""" return { 'key': 'key/location.xml', 'bucket': 'bucket-name' } @pytest.fixture def test_context(): """Test context for DDEX Schema loader.""" asset = SimpleNamespace( filename='test_asset_filename' ) track = SimpleNamespace( track_name='test_track_name', asset=asset ) product = SimpleNamespace( imprint='test_product' ) return SimpleNamespace( product=product, track=track ) @pytest.fixture def test_rows(): """Test context for DDEX Schema loader.""" return [TableRowModel() for i in range(4)] @pytest.fixture def csv_expected_headers(): """List of expected CSV headers, in order.""" return [ 'Release Name', 'Release Meta Language', 'Orchard Artist', 'Artist Country', 'Subaccount Name', 'Artist URL', 'Release Artist(s)-Primary Artist(s)', 'Release Artist(s)-Featuring(s)', 'Release Artist(s)-Remixer(s)', 'Release Artist(s)-Producer(s)', 'Release Artist(s)-Composer(s)', 'Release Artist(s)-Orchestra(s)', 'Release Artist(s)-Ensemble(s)', 'Release Artist(s)-Conductor(s)', 'Release Date', 'Sale Start Date', 'iTunes Pre-Order', 'iTunes Pre-Order Date', 'Preorder Preview', 'Album Pricing', 'Format: Full Length / EP / Single', 'Imprint', 'Genre', 'Sub-genre', '[C] Information', 'P-Line', 'Digital UPC', "Manufacturer's UPC", 'Folder Name / Project Code', 'Product Code', 'Release Version', 'File Name', 'Volume', 'Track No.', 'Track Name', 'Track Audio Language', 'Version', 'Track Artist', 'Track Artist(s) - Featuring(s)', 'Track Artist(s) - Remixer(s)', 'Track Artist(s) - Producer(s)', 'Track Artist(s) - Composer(s)', 'Track Artist(s) - Orchestra(s)', 'Track Artist(s) - Ensemble(s)', 'Track Artist(s) - Conductor(s)', 'Track Pricing', 'Explicit (No/Yes/Clean)', 'ISRC', '3rd Party Publisher? (Yes/No)', '[P] Information', 'Ownership For This Sound Recording', 'Country of Recording', 'Nationality of Original Copyright Owner', 'Track Lyrics', 'Songwriter(s)', 'Publisher(s)', 'Performer 1 Type', 'Performer 1 Legal Name', 'Performer 1 Main Role', 'Performer 2 Type', 'Performer 2 Legal Name', 'Performer 2 Main Role', 'Performer 3 Type', 'Performer 3 Legal Name', 'Performer 3 Main Role', 'Performer 4 Type', 'Performer 4 Legal Name', 'Performer 4 Main Role', 'Performer 5 Type', 'Performer 5 Legal Name', 'Performer 5 Main Role', 'Only Include/Only Exclude?', 'Territories (ISO Codes)', 'ORCHLABELID', 'Num Agreements' ] @pytest.fixture def csv_expected_rows(): """Desired output CSV row.""" return [ 'Moving On', # Release Name 'en', # Release Metadata Language 'Pri Lacerda', # Orchard Artist '', # Artist Country '', # Subaccount name '', # Artist URL 'Pri Lacerda', # Release Artist(s)-Primary Artist(s) '', # Release Artist(s)-Featuring(s) '', # Release Artist(s)-Remixer(s) 'Maycon Ananias', # Release Artist(s)-Producer(s) '', # Release Artist(s)-Composer(s) '', # Release Artist(s)-Orchestra(s) '', # Release Artist(s)-Ensemble(s) '', # Release Artist(s)-Conductor(s) '2018-07-17', # Release Date '2023-01-13', # Sale Start Date 'No Pre-order', # iTunes Pre-Order '', # iTunes Pre-Order Date 'False', # Preorder Preview 'Mini EP: Max 7', # Album Pricing 'Album', # Format: Full Length / EP / Single 'Pomar Cultural', # Imprint 'WORLD MUSIC', # Genre '', # Sub-genre '2018 Pomar', # [C] Information '2018 Pri Lacerda', # P-Line '7892920191103', # Digital UPC 'GGL_UR_ID:1353730', # Manufacturer's UPC '7892920191103', # Folder Name / Project Code '1353730', # Product Code '', # Release Version '7892920191103_1_1.wav', # File Name '1', # Volume '1', # Track No. 'Once I Was a Girl in Love', # Track Name '', # Track Audio Language '', # Version 'Pri Lacerda', # Track Artist '', # Track Artist(s) - Featuring(s) '', # Track Artist(s) - Remixer(s) 'Maycon Ananias', # Track Artist(s) - Producer(s) 'Alexy Gaiane Viegas', # Track Artist(s) - Composer(s) '', # Track Artist(s) - Orchestra(s) '', # Track Artist(s) - Ensemble(s) '', # Track Artist(s) - Conductor(s) 'Back', # Track Pricing 'N', # Explicit (No/Yes/Clean) 'BXPSQ1700001', # ISRC '', # 3rd Party Publisher? (Yes/No) '2018 Pri Lacerda', # [P] Information '', # Ownership For This Sound Recording '', # Country of Recording '', # Nationality of Original Copyright Owner '', # Track Lyrics 'Alexy Gaiane Viegas', # Songwriter(s) '', # Publisher(s) 'Primary Performer', # Performer 1 Type 'Pri Lacerda', # Performer 1 Legal Name 'LeadVocals', # Performer 1 Main Role '', # Performer 2 Type '', # Performer 2 Legal Name '', # Performer 2 Main Role '', # Performer 3 Type '', # Performer 3 Legal Name '', # Performer 3 Main Role '', # Performer 4 Type '', # Performer 4 Legal Name '', # Performer 4 Main Role '', # Performer 5 Type '', # Performer 5 Legal Name '', # Performer 5 Main Role 'Exclude Only', # Only Include/Only Exclude? '', # Territories (ISO Codes) '', # ORCHLABELID '' # Num Agreements ] @pytest.fixture def csv_expected_row(): """Desired output CSV row.""" return [ 'Pacote Completo', # Release Name 'pt', # Release Metadata Language 'Suel, Di Propósito', # Orchard Artist '', # Artist Country '', # Subaccount name '', # Artist URL 'Suel|Di Propósito', # Release Artist(s)-Primary Artist(s) '', # Release Artist(s)-Featuring(s) '', # Release Artist(s)-Remixer(s) 'Allan Lima|Suel', # Release Artist(s)-Producer(s) 'Suel|Allefy', # Release Artist(s)-Composer(s) '', # Release Artist(s)-Orchestra(s) '', # Release Artist(s)-Ensemble(s) '', # Release Artist(s)-Conductor(s) '2022-03-10', # Release Date '2022-03-10', # Sale Start Date 'No Pre-order', # iTunes Pre-Order '', # iTunes Pre-Order Date 'False', # Preorder Preview 'Mid - Single', # Album Pricing 'Album', # Format: Full Length / EP / Single 'Lalaiá Music', # Imprint 'PAGODE', # Genre '', # Sub-genre '2022 Lalaiá Music', # [C] Information '2022 Lalaiá Music', # P-Line '7892920178708', # Digital UPC 'GGL_UR_ID:926169', # Manufacturer's UPC '7892920178708', # Folder Name / Project Code '926169', # Product Code 'Ao Vivo', # Release Version '7892920178708_1_1.wav', # File Name '1', # Volume '1', # Track No. 'Pacote Completo', # Track Name '', # Track Audio Language 'Ao Vivo', # Version 'Suel|Di Propósito', # Track Artist '', # Track Artist(s) - Featuring(s) '', # Track Artist(s) - Remixer(s) 'Allan Lima|Suel', # Track Artist(s) - Producer(s) 'Suel|Allefy', # Track Artist(s) - Composer(s) '', # Track Artist(s) - Orchestra(s) '', # Track Artist(s) - Ensemble(s) '', # Track Artist(s) - Conductor(s) 'Mid', # Track Pricing 'N', # Explicit (No/Yes/Clean) 'BXLPA2100010', # ISRC '', # 3rd Party Publisher? (Yes/No) '2022 Lalaiá Music', # [P] Information '', # Ownership For This Sound Recording '', # Country of Recording '', # Nationality of Original Copyright Owner '', # Track Lyrics 'Suel|Allefy', # Songwriter(s) 'Lalaiá Music', # Publisher(s) 'Primary Performer', # Performer 1 Type 'Suel', # Performer 1 Legal Name 'MainArtist', # Performer 1 Main Role 'Primary Performer', # Performer 2 Type 'Di Propósito', # Performer 2 Legal Name 'MainArtist', # Performer 2 Main Role '', # Performer 3 Type '', # Performer 3 Legal Name '', # Performer 3 Main Role '', # Performer 4 Type '', # Performer 4 Legal Name '', # Performer 4 Main Role '', # Performer 5 Type '', # Performer 5 Legal Name '', # Performer 5 Main Role 'Exclude Only', # Only Include/Only Exclude? '', # Territories (ISO Codes) '', # ORCHLABELID '' # Num Agreements ] @pytest.fixture def s3_folder_mimetype(): """S3 Folder MimeType.""" return 'application/x-directory' @pytest.fixture def s3_xml_mimetype(): """S3 XML MimeType.""" return 'text/xml' @pytest.fixture def s3_eligible_keys(): """Keys to be processed from S3 tree.""" return [ 'test/123/123.xml', # 'test/123/resources/123_01.wav', # 'test/123/resources/123.jpg', 'test/345/345.xml', 'test/345/resources/ABC_lyrics.txt' ]