import os import pytest from unittest.mock import Mock from exp_manager_lambda import get_config_from_file from exp_manager_lambda.entities import Config from exp_manager_lambda.service import Service FIXTURES_PATH = os.path.join(os.path.dirname(__file__), "fixtures") @pytest.mark.parametrize( 'uow_id, expected_result', [ ('gras-20200810-sme-dim_company-v1', True), ('gras-20200810-sme-dim_company-v1-rp20200722T142514', True), ('tiktokreporting-20200510-sme-Trends_TopSong-v1', True), ('vevo-20200308-sme-sony_standard_sales-v1', False), ('spotify-20200309-sme-partneremails-v1', True), ('spotify-20200815-sme-streams-v2', True), ('spotify-20200815-sme-streams-v4', False), ('apple-20200815-sme-amStreams-v1_2', False), ] ) def test_check_should_skip(uow_id, expected_result): config = Config( environment='dev', rds_secrets_key='/delphi/dev/key', trace_id='123', excluded_dsp=['gras'], exp_dsp_config=get_config_from_file( os.path.join(FIXTURES_PATH, "exploration-dsp-config.json") ), ) service = Service(Mock(), Mock(), Mock(), config) result = service._check_should_skip(uow_id) assert result == expected_result @pytest.mark.parametrize( 'uow_id, expected_result', [ ('apple-20200815-sme-amStreams-v1_2', False), ('apple-20200815-sme-amStreams-v1_2-rp20200722T142514', False), ('youtubereporting-20201108-sme-content_owner_asset-a2', True), ] ) def test_check_report_is_for_copy_only(uow_id, expected_result): config = Config( environment='dev', rds_secrets_key='/delphi/dev/key', trace_id='123', excluded_dsp=['gras'], exp_dsp_config=get_config_from_file( os.path.join(FIXTURES_PATH, "exploration-dsp-config_full.json") ), ) service = Service(Mock(), Mock(), Mock(), config) result = service._check_report_is_for_action_copy(uow_id) assert result == expected_result @pytest.mark.parametrize( 'file_path, expected_result', [ ('s3://dev-archive/spotify/path1.txt', False), ('s3://dev-archive/spotify/path1.csv', False), ('s3://dev-archive/spotify/part-00000-e408e7f5-2f61-4bc4-8c9b-d4dd6a6d600f.c000.snappy.parquet', True), ('s3://dev-archive/spotify/part-00283-e40AA7f5-2f61-4bc4-8c9b-d4dd6a6d600f.c014.snappy.parquet', True), ('s3://dev-archive/spotify/part-00283-e40AA7f5-2f61-4bc4-8c9b-d4dd6a6d600f-ASDF.c014.snappy.parquet', True), ('s3://dev-archive/spotify/part-00283-e40AA7f5-2f61-ASDF.c014.snappy.parquet', False), ] ) def test_check_file_is_parquet(file_path, expected_result): result = Service._check_file_is_parquet(file_path) assert result == expected_result