"""Lambda conftest module.""" import pytest import pandas as pd from src.constants.track_fields import TRACK_FIELDS from src.constants.request_file import FIELDS @pytest.fixture def mock_graphql_track_data(): """Mock graphql response.""" return [{ 'tuid': '1', 'isrc': 'ABC12345', 'durationMinutes': 2, 'durationSeconds': 19, 'publishing': { 'publishers': [ { 'id': '1', 'name': 'Test \tPublisher 1' } ] }, 'trackName': 'Test Track 1', 'participations': [ { 'participant': { 'name': 'Test Writer 1' } }, { 'participant': { 'name': 'Test Writer 3' } } ], 'product': { 'label': { 'name': 'Test Label 1' }, 'displayUpc': '11789', 'productName': 'Test Product 1', 'ingestionCompleted': '2022-05-13', 'distributionDate': '2022-05-27', 'vendorCatalogNumber': 'VCN1234', 'priority': 3, 'project': { 'labelParticipant': { 'name': 'Test Artist 1' } } } }, { 'tuid': '2', 'isrc': 'XYZ1234', 'durationMinutes': 1, 'durationSeconds': 47, 'publishing': { 'publishers': [ { 'id': '3', 'name': 'Test Publisher 3' }, { 'id': '2', 'name': 'Test Publisher 2' } ] }, 'trackName': 'Test Track 2', 'participations': [ { 'participant': { 'name': 'Test Writer 2' } } ], 'product': { 'label': { 'name': 'Test Label 2' }, 'displayUpc': '1234567', 'productName': 'Test Product 2', 'ingestionCompleted': '2022-05-13', 'distributionDate': '2022-05-27', 'vendorCatalogNumber': 'VCN234567', 'priority': 3, 'project': { 'labelParticipant': { 'name': 'Test Artist 2' } } } }, { 'tuid': '3', 'isrc': 'DEF123', 'durationMinutes': 2, 'durationSeconds': 19, 'publishing': { 'publishers': [] }, 'trackName': 'Test Track 3', 'participations': [ { 'participant': { 'name': 'Test Writer 3' } } ], 'product': { 'label': { 'name': 'Test Label 3' }, 'displayUpc': '123', 'productName': 'Test Product 3', 'ingestionCompleted': '2022-05-13', 'distributionDate': '2022-05-27', 'vendorCatalogNumber': 'VCN3', 'priority': 3, 'project': { 'labelParticipant': { 'name': 'Test Artist 3' } } } }] @pytest.fixture def mock_empty_graphql_track_data(): """Mock graphql track response as empty list.""" return [] @pytest.fixture def mock_track_info_json(): """Mock Track info as list of dictionaries.""" return [ { 'track_id': '1', 'label_name': 'Test Label 1', 'isrc': 'ABC12345', 'length_minute': 2, 'length_seconds': 19, 'artist_name': 'Test Artist 1', 'track_name': 'Test Track 1', 'publisher_name': 'Test \tPublisher 1', 'vendor_catalog_number': 'VCN1234', 'release_name': 'Test Product 1', 'display_upc': '11789', 'ingestion_date': '2022-05-13', 'distribution_date': '2022-05-27', 'track_publisher_id': '1', 'priority': 3, 'writers': 'Test Writer 1,Test Writer 3' }, { 'track_id': '2', 'label_name': 'Test Label 2', 'isrc': 'XYZ1234', 'length_minute': 1, 'length_seconds': 47, 'artist_name': 'Test Artist 2', 'track_name': 'Test Track 2', 'publisher_name': 'Test Publisher 2', 'vendor_catalog_number': 'VCN234567', 'release_name': 'Test Product 2', 'display_upc': '1234567', 'ingestion_date': '2022-05-13', 'distribution_date': '2022-05-27', 'track_publisher_id': '2', 'priority': 3, 'writers': 'Test Writer 2' }, { 'track_id': '2', 'label_name': 'Test Label 2', 'isrc': 'XYZ1234', 'length_minute': 1, 'length_seconds': 47, 'artist_name': 'Test Artist 2', 'track_name': 'Test Track 2', 'publisher_name': 'Test Publisher 3', 'vendor_catalog_number': 'VCN234567', 'release_name': 'Test Product 2', 'display_upc': '1234567', 'ingestion_date': '2022-05-13', 'distribution_date': '2022-05-27', 'track_publisher_id': '3', 'priority': 3, 'writers': 'Test Writer 2' }, { 'track_id': '3', 'label_name': 'Test Label 3', 'isrc': 'DEF123', 'length_minute': 2, 'length_seconds': 19, 'artist_name': 'Test Artist 3', 'track_name': 'Test Track 3', 'publisher_name': None, 'vendor_catalog_number': 'VCN3', 'release_name': 'Test Product 3', 'display_upc': '123', 'ingestion_date': '2022-05-13', 'distribution_date': '2022-05-27', 'track_publisher_id': None, 'priority': 3, 'writers': 'Test Writer 3' } ] @pytest.fixture def mock_bad_graphql_track_data(mock_track_info_json): """Mock Track info as list of dictionaries with invalid track_id.""" mock_track_info_json[0]['track_id'] = 'invalid_int' return mock_track_info_json @pytest.fixture def mock_track_info_df(mock_track_info_json): """Convert track_info_json to DataFrame.""" return pd.DataFrame(mock_track_info_json, columns=TRACK_FIELDS) @pytest.fixture def mock_empty_track_info_df(): """Mock empty track_info dataframe.""" return pd.DataFrame(columns=TRACK_FIELDS) @pytest.fixture def mock_bad_track_info_df(mock_track_info_json): """Convert track_info_json to DataFrame.""" mock_track_info_json[0]['track_id'] = 'invalid_int' bad_track_info_df = pd.DataFrame(mock_track_info_json, columns=TRACK_FIELDS) return bad_track_info_df @pytest.fixture def mock_current_date(): """Mock current date.""" return 20220501 @pytest.fixture def mock_publishing_table_data(): """Mock publishing table json response.""" return [{ 'id': 1, 'orchard_track_id': 1, 'state': 'pending', 'hfa_configuration_code': 'SP' }, { 'id': 2, 'orchard_track_id': 2, 'state': 'pending', 'hfa_configuration_code': 'SP' }, { 'id': 3, 'orchard_track_id': 3, 'state': 'pending', 'hfa_configuration_code': 'RT' }] @pytest.fixture def mock_hfa_orchard_track_licenses_df(mock_publishing_table_data): """Mock hfa_orchard_track_licenses table dataframe.""" return pd.DataFrame.from_records(mock_publishing_table_data) @pytest.fixture def mock_resubmit_orchard_track_licenses_df(mock_hfa_orchard_track_licenses_df): """Mock hfa_orchard_track_licenses table's resubmit state dataframe.""" return mock_hfa_orchard_track_licenses_df.query("state == 'resubmit'") @pytest.fixture def mock_transformed_json(mock_current_date): """Mock transformed data's list of dictionary.""" return [{ 'hfa_agreement_code': 'SSA', 'manufacturer_number': 'M16106', 'transaction_date': mock_current_date, 'manufacturer_request_number': 1, 'label_name': 'Test Label 1', 'isrc_code': 'ABC12345', 'playing_time_minutes': 2, 'playing_time_seconds': 19, 'artist': 'Test Artist 1', 'song_title': 'Test Track 1', 'aka_song_title': 'Test Track 1', 'iswc_code': '', 'hfa_song_code': '', 'composers': 'Test Writer 1,Test Writer 3', 'publisher_name': 'Test Publisher 1', 'hfa_publisher_number': '', 'exact_per_publisher_share': '', 'catalog_number': 'VCN1234', 'album_title': 'Test Product 1', 'upc_code': '11789', 'configuration_codes': 'SP', 'license_type': 'G', 'server_fixation_date': 20220513, 'rate_code': 'S', 'hfa_output_1': '', 'hfa_output_2': '', 'hfa_output_3': '', 'hfa_license_number_direct_deal_reference_id': '', 'hfa_request_process_code_1': '', 'hfa_request_process_code_2': '', 'hfa_request_process_code_3': '', 'hfa_request_process_code_4': '', 'licensed_status_code': '', 'hfa_output_field': '', 'publisher_status': '', 'total_hfa_licensed_share': '', 'user_defined_1': 'N2', 'user_defined_2_track_id': '1', 'user_defined_3_copyright_office_request': 'FALSE', 'user_defined_4_distribution_date': '20220527', 'user_defined_5_track_publisher_id': '1', 'user_defined_6': '', 'user_defined_7_tr_code': '', 'user_defined_8_priority_code': '3', 'user_defined_9_pid': '' }, { 'hfa_agreement_code': 'SSA', 'manufacturer_number': 'M16106', 'transaction_date': mock_current_date, 'manufacturer_request_number': 2, 'label_name': 'Test Label 2', 'isrc_code': 'XYZ1234', 'playing_time_minutes': 1, 'playing_time_seconds': 47, 'artist': 'Test Artist 2', 'song_title': 'Test Track 2', 'aka_song_title': 'Test Track 2', 'iswc_code': '', 'hfa_song_code': '', 'composers': 'Test Writer 2', 'publisher_name': 'Test Publisher 2', 'hfa_publisher_number': '', 'exact_per_publisher_share': '', 'catalog_number': 'VCN234567', 'album_title': 'Test Product 2', 'upc_code': '1234567', 'configuration_codes': 'SP', 'license_type': 'G', 'server_fixation_date': 20220513, 'rate_code': 'S', 'hfa_output_1': '', 'hfa_output_2': '', 'hfa_output_3': '', 'hfa_license_number_direct_deal_reference_id': '', 'hfa_request_process_code_1': '', 'hfa_request_process_code_2': '', 'hfa_request_process_code_3': '', 'hfa_request_process_code_4': '', 'licensed_status_code': '', 'hfa_output_field': '', 'publisher_status': '', 'total_hfa_licensed_share': '', 'user_defined_1': 'N2', 'user_defined_2_track_id': '2', 'user_defined_3_copyright_office_request': 'FALSE', 'user_defined_4_distribution_date': '20220527', 'user_defined_5_track_publisher_id': '2', 'user_defined_6': '', 'user_defined_7_tr_code': '', 'user_defined_8_priority_code': '3', 'user_defined_9_pid': '' }, { 'hfa_agreement_code': 'SSA', 'manufacturer_number': 'M16106', 'transaction_date': mock_current_date, 'manufacturer_request_number': 2, 'label_name': 'Test Label 2', 'isrc_code': 'XYZ1234', 'playing_time_minutes': 1, 'playing_time_seconds': 47, 'artist': 'Test Artist 2', 'song_title': 'Test Track 2', 'aka_song_title': 'Test Track 2', 'iswc_code': '', 'hfa_song_code': '', 'composers': 'Test Writer 2', 'publisher_name': 'Test Publisher 3', 'hfa_publisher_number': '', 'exact_per_publisher_share': '', 'catalog_number': 'VCN234567', 'album_title': 'Test Product 2', 'upc_code': '1234567', 'configuration_codes': 'SP', 'license_type': 'G', 'server_fixation_date': 20220513, 'rate_code': 'S', 'hfa_output_1': '', 'hfa_output_2': '', 'hfa_output_3': '', 'hfa_license_number_direct_deal_reference_id': '', 'hfa_request_process_code_1': '', 'hfa_request_process_code_2': '', 'hfa_request_process_code_3': '', 'hfa_request_process_code_4': '', 'licensed_status_code': '', 'hfa_output_field': '', 'publisher_status': '', 'total_hfa_licensed_share': '', 'user_defined_1': 'N2', 'user_defined_2_track_id': '2', 'user_defined_3_copyright_office_request': 'FALSE', 'user_defined_4_distribution_date': '20220527', 'user_defined_5_track_publisher_id': '3', 'user_defined_6': '', 'user_defined_7_tr_code': '', 'user_defined_8_priority_code': '3', 'user_defined_9_pid': '' }, { 'hfa_agreement_code': 'RGT', 'manufacturer_number': 'M16106', 'transaction_date': mock_current_date, 'manufacturer_request_number': 3, 'label_name': 'Test Label 3', 'isrc_code': 'DEF123', 'playing_time_minutes': 2, 'playing_time_seconds': 19, 'artist': 'Test Artist 3', 'song_title': 'Test Track 3', 'aka_song_title': 'Test Track 3', 'iswc_code': '', 'hfa_song_code': '', 'composers': 'Test Writer 3', 'publisher_name': '', 'hfa_publisher_number': '', 'exact_per_publisher_share': '', 'catalog_number': 'VCN3', 'album_title': 'Test Product 3', 'upc_code': '123', 'configuration_codes': 'RT', 'license_type': 'G', 'server_fixation_date': 20220513, 'rate_code': 'Y', 'hfa_output_1': '', 'hfa_output_2': '', 'hfa_output_3': '', 'hfa_license_number_direct_deal_reference_id': '', 'hfa_request_process_code_1': '', 'hfa_request_process_code_2': '', 'hfa_request_process_code_3': '', 'hfa_request_process_code_4': '', 'licensed_status_code': '', 'hfa_output_field': '', 'publisher_status': '', 'total_hfa_licensed_share': '', 'user_defined_1': 'N2', 'user_defined_2_track_id': '3', 'user_defined_3_copyright_office_request': 'FALSE', 'user_defined_4_distribution_date': '20220527', 'user_defined_5_track_publisher_id': '', 'user_defined_6': '', 'user_defined_7_tr_code': '', 'user_defined_8_priority_code': '3', 'user_defined_9_pid': '' }] @pytest.fixture def mock_transform_df(mock_transformed_json): """Mock transformed dataframe.""" return pd.DataFrame.from_records(mock_transformed_json) @pytest.fixture def mock_empty_transform_df(): """Mock empty transformed dataframe.""" return pd.DataFrame(columns=FIELDS) @pytest.fixture def mock_ssa_df(mock_transform_df): """Mock hfa_orchard_track_licenses table's resubmit state dataframe.""" return mock_transform_df.query('hfa_agreement_code == "SSA"') @pytest.fixture def mock_rgt_df(mock_transform_df): """Mock hfa_orchard_track_licenses table's resubmit state dataframe.""" return mock_transform_df.query('hfa_agreement_code == "RGT"') @pytest.fixture def mock_dependencies(mocker): """Mock the dependencies for testing purposes in the 'src.app' module.""" return { 'datetime': mocker.patch('src.app.datetime'), 'capture_exception': mocker.patch('src.app.capture_exception'), 'load_generate_hfa_tmp_files': mocker.patch('src.app.load_generate_hfa_tmp_files'), 'transform': mocker.patch('src.app.transform'), 'generate_and_upload_file': mocker.patch('src.app.generate_and_upload_file'), 'upload_file_to_s3': mocker.patch('src.app.s3.upload_file_to_s3'), 'os_path_join': mocker.patch('src.app.os.path.join'), 'temp_directory': mocker.patch('src.app.tempfile.TemporaryDirectory'), 's3_bucket_name': mocker.patch('src.app.config.S3_BUCKET_NAME', 'mock-bucket'), 's3_request_dir': mocker.patch('src.app.config.S3_REQUEST_FILE_DIR', 'requests/'), 'generate_random_string': mocker.patch('src.app.generate_random_string'), 'generate_file_name': mocker.patch('src.app.generate_file_name'), 'logger': mocker.patch('src.app.logger'), }