"""Conftest.""" import json import os from bulk_metadata_ingester_common.models.bulk_release import BulkRelease import pytest KEY = os.environ.get('KEY', 'parsed_csv/ALL_DDEX_TO_CSV_2023-02-10_2023-03-01.json') # noqa BUCKET = os.environ.get('BUCKET', 'prod-orcd-fluve-drop') ITEM_INDEX = '7892920191004_____1362655' DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data',) def get_json(json_file='single_release.json'): """Get JSON helper method.""" with open(os.path.join(DATA_DIR, json_file)) as fd: return fd.read() @pytest.fixture def test_release_json(json_file='single_release.json'): """Parse given XML file using xmltodict.parse().""" return get_json(json_file) @pytest.fixture def test_event(): """JSON representing a single release event.""" return { 'key': KEY, 'bucket': BUCKET, 'item_index': ITEM_INDEX, 'execution_name': 'exec-1234', 'state_machine_name': 'sfn-bulk-metadata-ingester', 'correlation_id': 'unittest-1234' } @pytest.fixture def test_model(json_file='single_release.json'): """Named Tuple model representing a release.""" test_json = json.loads(get_json())[ITEM_INDEX] return BulkRelease(json_release_rows=test_json) @pytest.fixture def test_check_for_product_exists_result(): """Test check for product result when exists.""" return { 'productId': '12345', 'status': 'label_processing' } @pytest.fixture def test_get_genre_mapping_result(): """Test get_genre_mapping() result.""" return { 'genre_id': 1, 'subgenre_id': 100 } @pytest.fixture def test_check_for_product_missing_result(): """Test check for product result when does not exist.""" return {} @pytest.fixture def test_create_product_result(): """Test create product result.""" return { 'productId': '123', 'upc': '7892920191004' } @pytest.fixture def test_get_participations_result(): """Test get_participations result.""" return { 'artists': [ { 'labelParticipantUuid': '1234', 'role': 'PRIMARY_ARTIST' }, { 'labelParticipantUuid': '5678', 'role': 'SECONDARY_ARTIST' } ] } @pytest.fixture def test_update_product_result(): """Test update product result.""" return { 'productId': '12345' } @pytest.fixture def test_all_roles_result(): """Test get_all_roles() result.""" return { 'artists': [ { 'role': 'PRIMARY_ARTIST', 'name': 'Pedro Libe' }, { 'role': 'PRIMARY_ARTIST', 'name': 'Jorge & Mateus' }, { 'role': 'PRODUCER', 'name': 'Seu Jonas' }, { 'role': 'COMPOSER', 'name': 'Alex Alves' }, { 'role': 'COMPOSER', 'name': 'Robson Lima' }, { 'role': 'COMPOSER', 'name': 'Lucas Papada' } ] } @pytest.fixture def test_label_participant_uuid(): """Fixture for label participant UUID.""" return '123' @pytest.fixture def test_performer(): """Fixture for performer data.""" return { 'role': 'PRIMARY_ARTIST', 'name': 'Pedro Libe' } @pytest.fixture def test_release_participants(): """Fixture for release participants.""" return [ { 'name': 'Pedro Libe', 'artist_id': '3004908', 'label_participant_id': '5678', 'label_participant_uuid': '123' } ] @pytest.fixture def test_release_performers_result(): """Fixture for track performers data.""" return [ { 'labelParticipantUuid': '123', 'role': 'PRIMARY_ARTIST', }, { 'labelParticipantUuid': '5678', 'role': 'SECONDARY_ARTIST' } ] @pytest.fixture def test_get_all_roles_result(): """Fixture for get_all_roles() response.""" return { 'artists': [ { 'name': 'Pedro Libe', 'role': 'PRIMARY_ARTIST', }, { 'name': 'John Doe', 'role': 'SECONDARY_ARTIST', } ] } @pytest.fixture def test_handler_output_exists(): """Test handler output.""" return { 'key': 'parsed_csv/ALL_DDEX_TO_CSV_2023-02-10_2023-03-01.json', 'bucket': 'prod-orcd-fluve-drop', 'item_index': '7892920191004_____1362655', 'execution_name': 'exec-1234', 'state_machine_name': 'sfn-bulk-metadata-ingester', 'correlation_id': 'unittest-1234', 'release': { 'product_id': '12345', 'genre_id': 1, 'subgenre_id': 100, }, 'tracks': {} } @pytest.fixture def test_handler_output_missing(): """Test handler output.""" return { 'key': 'parsed_csv/ALL_DDEX_TO_CSV_2023-02-10_2023-03-01.json', 'bucket': 'prod-orcd-fluve-drop', 'item_index': '7892920191004_____1362655', 'execution_name': 'exec-1234', 'state_machine_name': 'sfn-bulk-metadata-ingester', 'correlation_id': 'unittest-1234', 'release': { 'product_id': '123', 'genre_id': 1, 'subgenre_id': 100, }, 'tracks': {} }