Ejemplo n.º 1
0
def s3_client():
    mock_s3 = moto.mock_s3()
    mock_s3.start()

    client = boto3.client('s3')
    client.create_bucket(Bucket=test_bucket_name)
    client.put_object(Bucket=test_bucket_name, Key=test_file_path, Body=test_nb_content)
    yield S3()
    try:
        client.delete_object(Bucket=test_bucket_name, Key=test_file_path)
        client.delete_object(Bucket=test_bucket_name, Key=test_file_path + '.txt')
    except Exception:
        pass
    mock_s3.stop()
Ejemplo n.º 2
0
def s3_client():
    mock_s3 = moto.mock_s3()
    mock_s3.start()

    client = boto3.client('s3')
    client.create_bucket(
        Bucket=test_bucket_name,
        CreateBucketConfiguration={'LocationConstraint': 'us-west-2'})
    client.put_object(Bucket=test_bucket_name,
                      Key=test_file_path,
                      Body=test_nb_content)
    client.put_object(Bucket=test_bucket_name,
                      Key=test_empty_file_path,
                      Body='')
    yield S3()
    try:
        client.delete_object(Bucket=test_bucket_name, Key=test_file_path)
        client.delete_object(Bucket=test_bucket_name,
                             Key=test_file_path + '.txt')
        client.delete_object(Bucket=test_bucket_name, Key=test_empty_file_path)
    except Exception:
        pass
    mock_s3.stop()