# pylint: disable=unused-argument,redefined-outer-name,invalid-name import json import os from io import BytesIO import boto3 import pytest from moto import mock_s3 from slz_apple_music_charts_pipeline_configurator.const import EnvironmentEnum from slz_apple_music_charts_pipeline_configurator.entities import Config, Payload @pytest.fixture(scope='function') def config_stub(): return Config( environment=EnvironmentEnum.DEV, apple_music_scrapper_batch_config_path= 's3://dev-delphi-configs/apple-music-charts/scrapper-batch-config-standard.json', vendor_api_secret_key='vendor/api/secret', slz_corrupted_bucket='slz/corrupted/bucket', slz_decompressed_bucket='slz/decompressed/bucket', slz_decompressed_quarantine_bucket='slz/decompressed-quarantine/bucket', slz_rds_secret_key='slz/rds/secret', sentry_secret_key='sentry/secret/key', ) @pytest.fixture(scope='function') def payload_stub(): return Payload( uow_id='am-1', execution_name='am-sf-name', report_date='2021-10-01', dsp='apple', report_type='charts_daily', version='v1', licensor='sme', contexts=['us', 'mx', 'gb'], config_bucket='dev-delphi-configs', ) @pytest.fixture(scope='function') def aws_credentials(): """Mocked AWS Credentials for moto.""" os.environ['AWS_ACCESS_KEY_ID'] = 'testing' os.environ['AWS_SECRET_ACCESS_KEY'] = 'testing' os.environ['AWS_SECURITY_TOKEN'] = 'testing' os.environ['AWS_SESSION_TOKEN'] = 'testing' @pytest.fixture(scope='function') def s3(aws_credentials): with mock_s3(): yield boto3.client('s3', region_name='us-east-1') @pytest.fixture(scope='function') def scraper_batch_config(s3): bucket = 'test-delphi-configs' key = 'apple-music-charts/scrapper-batch-config-standard.json' s3.create_bucket(Bucket=bucket) f = BytesIO( json.dumps({ 'JobQueue': 'arn:aws:batch:us-east-1:475275892927:job-queue/test-delphi-main', 'JobDefinition': ( 'arn:aws:batch:us-east-1:475275892927:job-definition/' 'test-delphi-slz-apple-music-charts-scrapper:1' ), }).encode('utf-8') ) s3.upload_fileobj(f, bucket, key) yield f's3://{bucket}/{key}' s3.delete_object(Bucket=bucket, Key=key) s3.delete_bucket(Bucket=bucket)