import pytest import config from aws_testing_utils.logger import log import constants env = config.ENV S3_BUCKET = f'{env}-orcd-mezzanine-assets' UPC = 44003199682 PRODUCT_ID = 3840746 STEP_FUNCTION_NAME = constants.WORKFLOW_TRANSFER_ASSETS SFN_TIMEOUT = 900 @pytest.mark.parametrize('alchemy_db', ['dd'], indirect=True) @pytest.mark.parametrize('step_function_handler', [STEP_FUNCTION_NAME], indirect=True) @pytest.mark.parametrize('physical_location', [ {"description": "s3_to_s3", "id": 9} ]) def test_workflow_transfer_assets_artwork( alchemy_db, s3_handler, current_datetime, step_function_handler, physical_location): """Test workflow-transfer-assets state machine for artwork \n https://www.notion.so/VECTOR-fe346add2b484d6fa9da91969dee0bde""" alchemy_db.assets.remove_assets_if_exists(UPC, 2) asset = 'vector_component_testing_artwork.tif' file_path = f'images/tif/{asset}' with open(f'src/assets/{asset}', 'rb') as image: f = image.read() b = bytearray(f) s3_handler.put_if_object_not_present(S3_BUCKET, file_path, b) input_data = build_input_data('TIF', file_path, current_datetime, physical_location["id"]) delete_existing_assets_from_destination(physical_location, input_data, s3_handler) step_function_handler.execute(input_data, timeout=SFN_TIMEOUT) assert_file_in_location(physical_location, input_data, s3_handler) @pytest.mark.parametrize('alchemy_db', ['dd'], indirect=True) @pytest.mark.parametrize('step_function_handler', [STEP_FUNCTION_NAME], indirect=True) @pytest.mark.parametrize('physical_location', [ {"description": "s3_to_s3", "id": 9} ]) def test_workflow_transfer_assets_audio( alchemy_db, s3_handler, current_datetime, step_function_handler, physical_location): """Test workflow-transfer-assets state machine for audio \n https://www.notion.so/VECTOR-fe346add2b484d6fa9da91969dee0bde""" alchemy_db.assets.remove_assets_if_exists(UPC, 1) asset = 'vector_component_testing_audio.wav' file_path = asset with open(f'src/assets/{asset}', 'rb') as wav: f = wav.read() b = bytearray(f) s3_handler.put_if_object_not_present(S3_BUCKET, file_path, b) input_data = build_input_data('WAV', file_path, current_datetime, physical_location["id"]) delete_existing_assets_from_destination(physical_location, input_data, s3_handler) step_function_handler.execute(input_data, timeout=SFN_TIMEOUT) assert_file_in_location(physical_location, input_data, s3_handler) def delete_existing_assets_from_destination(location, input_data, s3_handler): if location["description"] == "s3_to_s3": bucket = input_data['assets'][0]["s3_destination_bucket"] path = input_data['assets'][0]["s3_destination_key"] s3_handler.delete_if_object_present(bucket, path) elif location["description"] == "s3_to_nyc": log.info("Deleting from NYC storage not supported") return def assert_file_in_location(location, input_data, s3_handler): if location["description"] == "s3_to_s3": bucket = input_data['assets'][0]["s3_destination_bucket"] path = input_data['assets'][0]["s3_destination_key"] s3_handler.assert_object_exists(bucket, path) elif location["description"] == "s3_to_nyc": log.info("Asserting NYC storage not supported") return def build_input_data(asset_type, file_path, datetime, physical_location_id): if physical_location_id in [9, 10]: # s3/CEPH drives return build_input_data_for_s3_storage( asset_type, file_path, datetime, physical_location_id) return build_input_data_for_old_storage( asset_type, file_path, datetime, physical_location_id) def build_input_data_for_old_storage( asset_type, file_path, datetime, physical_location_id ): asset = {"tuid": 0, "upc": UPC, "product_id": PRODUCT_ID, "asset_type": "", "s3_bucket": S3_BUCKET, "s3_key": "", "physical_location_id": "", "asset_type_id": 1, "asset_id": 0, "asset_location_id": 0, "asset_location_detail_id": 0, "updated_timestamp": "", "destination_filepath": "", "destination_filename": "", "host": "10.40.1.115", "sharename": "dev-thumbnails", "path": "", "drive_id": 233, "file_type": "", "drive_location": "D" } if asset_type == 'TIF': asset.update({ "tuid": 0, "asset_type": asset_type, "s3_key": file_path, "physical_location_id": physical_location_id, "asset_type_id": 2, "updated_timestamp": datetime, "destination_filepath": f"daemon-asset-copy/440031/996/{UPC}.tif", "destination_filename": f"{UPC}.tif", "path": "daemon-asset-copy/{upc(0,6)}/{upc(6,3)}/{upc}.tif", "file_type": "file" }) if asset_type == 'WAV': asset.update({ "tuid": 35880553, "asset_type": asset_type, "s3_key": file_path, "physical_location_id": physical_location_id, "asset_type_id": 1, "updated_timestamp": datetime, "destination_filepath": f"daemon-asset-copy/440031/996/{UPC}_1_1.wav", "destination_filename": f"{UPC}_1_1.wav", "path": "daemon-asset-copy/{upc(0,6)}/{upc(6,3)}/{upc}", "file_type": "directory" }) return {"assets": [asset]} def build_input_data_for_s3_storage( asset_type, file_path, datetime, physical_location_id ): asset = {"tuid": 0, "upc": UPC, "product_id": PRODUCT_ID, "asset_type": "", "s3_source_bucket": S3_BUCKET, "s3_source_key": "", "physical_location_id": "", "s3_destination_bucket": "", "asset_type_id": 1, "asset_id": 0, "asset_location_id": 0, "asset_location_detail_id": 0, "updated_timestamp": "", "s3_destination_key": "", "destination_filename": "", "host": "10.40.1.115", "sharename": "dev-thumbnails", "path": "", "drive_id": 233, "file_type": "", "drive_location": "D" } if asset_type == 'TIF': asset.update({ "tuid": 0, "asset_type": asset_type, "s3_source_key": file_path, "physical_location_id": physical_location_id, "asset_type_id": 2, "updated_timestamp": datetime, "s3_destination_key": f"integration-tests/440031/996/{UPC}.tif", "s3_destination_bucket": f"qa-encoding-wav-physical-location-" f"{physical_location_id}", "destination_filename": f"{UPC}.tif", "path": "integration-tests/{upc(0,6)}/{upc(6,3)}/{upc}.tif", "file_type": "file" }) if asset_type == 'WAV': asset.update({ "tuid": 35880553, "asset_type": asset_type, "s3_source_key": file_path, "physical_location_id": physical_location_id, "asset_type_id": 1, "updated_timestamp": datetime, "s3_destination_key": f"integration-tests/440031/996/{UPC}_1_1.wav", "s3_destination_bucket": f"qa-encoding-wav-physical-location-" f"{physical_location_id}", "destination_filename": f"{UPC}_1_1.wav", "path": "integration-tests/{upc(0,6)}/{upc(6,3)}/{upc}", "file_type": "directory" }) return {"assets": [asset]}