"""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_participant_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_project_exists_result(): """Test check for project result when exists.""" return { 'projectId': '123', } @pytest.fixture def test_check_for_project_missing_result(): """Test check for project result when does not exist.""" return {} @pytest.fixture def test_create_project_result(): """Test create project result.""" return { 'projectId': '456', } @pytest.fixture def test_check_code_mismatch_result(): """Test check project code mismatch result.""" return {} @pytest.fixture def test_process_participants_result(): """Test process participants result.""" return [ { 'name': 'Pedro Libe, Jorge & Mateus', 'artist_id': '2991910', 'label_participant_id': '1680562139953', 'label_participant_uuid': 'b3c44c3c-e3e7-47d7-a379-516dd22a1550' }, { 'name': 'Pedro Libe', 'artist_id': '2991911', 'label_participant_id': '1680562140543', 'label_participant_uuid': '46ea4ddd-6dee-40d8-af20-8354cb59c632' } ] @pytest.fixture def test_find_subaccount_id_result(): """Test find subaccount_id result.""" return 5 @pytest.fixture def test_update_project_result(): """Test update project result.""" return { 'projectId': '123' } @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': { 'subaccount_id': 5, 'project_id': '123', 'participants': [ { 'name': 'Pedro Libe, Jorge & Mateus', 'artist_id': '2991910', 'label_participant_id': '1680562139953', 'label_participant_uuid': 'b3c44c3c-e3e7-47d7-a379-516dd22a1550' # noqa }, { 'name': 'Pedro Libe', 'artist_id': '2991911', 'label_participant_id': '1680562140543', 'label_participant_uuid': '46ea4ddd-6dee-40d8-af20-8354cb59c632' # noqa } ] }, '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': { 'subaccount_id': 5, 'project_id': '456', 'participants': [ { 'name': 'Pedro Libe, Jorge & Mateus', 'artist_id': '2991910', 'label_participant_id': '1680562139953', 'label_participant_uuid': 'b3c44c3c-e3e7-47d7-a379-516dd22a1550' # noqa }, { 'name': 'Pedro Libe', 'artist_id': '2991911', 'label_participant_id': '1680562140543', 'label_participant_uuid': '46ea4ddd-6dee-40d8-af20-8354cb59c632' # noqa } ] }, 'tracks': {} }