import pathlib import os import boto3 import moto import pytest BUCKET_NAME = 'test_bucket' FIXTURES = pathlib.Path(__file__).parent / 'fixtures' @pytest.fixture def s3_client(): with moto.mock_s3(): s3_client = boto3.client('s3', use_ssl=False, verify=False) s3_client.create_bucket(Bucket=BUCKET_NAME) yield s3_client @pytest.fixture def s3_upload(s3_client): def wrapper(path, subfolder: str): subfolder_key = os.path.join(subfolder, path) file_path = os.path.join(FIXTURES, subfolder_key) s3_client.upload_file(file_path, BUCKET_NAME, subfolder_key) return 's3://{}'.format(os.path.join(BUCKET_NAME, subfolder_key)) return wrapper @pytest.fixture def s3_upload_schema(s3_upload): def wrapper(path): return s3_upload(path, 'schemas') return wrapper @pytest.fixture def s3_upload_report(s3_upload): def wrapper(path): return s3_upload(path, 'reports') return wrapper