Ejemplo n.º 1
0
def test_get_file(binary_image, s3_bucket: S3Bucket, base_path, expected_key):
    s3_bucket.S3_UPLOAD_LOCATION = base_path
    in_fp = BytesIO(binary_image)

    s3_bucket.bucket.upload_fileobj(Key=expected_key, Fileobj=in_fp)
    out_fp = s3_bucket.get_file('binary-image')

    assert isinstance(out_fp, SpooledTemporaryFile)
    assert not out_fp.closed
    assert out_fp.tell() == 0
    assert out_fp.read() == binary_image
Ejemplo n.º 2
0
def test__delete_objects(s3_bucket: S3Bucket, basepath, files, expected_paths):
    s3_bucket.S3_UPLOAD_LOCATION = basepath

    for path in expected_paths:
        s3_bucket.bucket.upload_fileobj(Fileobj=BytesIO(), Key=path)

    response = s3_bucket._delete_objects(files)
    assert 'Deleted' in response

    deleted_keys = list(map(lambda o: o['Key'], response['Deleted']))
    assert deleted_keys == expected_paths
Ejemplo n.º 3
0
def test_upload(binary_image, s3_bucket: S3Bucket, base_path, expected_key):
    s3_bucket.S3_UPLOAD_LOCATION = base_path
    mocked_upload_fileobj = s3_bucket.bucket.upload_fileobj = mock.Mock(
        wraps=s3_bucket.bucket.upload_fileobj)

    in_fp = BytesIO(binary_image)
    out_fp = BytesIO()

    s3_bucket.upload(in_fp, 'binary-image')
    mocked_upload_fileobj.assert_called_once_with(
        Fileobj=in_fp,
        Key=expected_key,
        ExtraArgs={'ContentType': 'image/gif'})

    s3_bucket.bucket.download_fileobj(Key=expected_key, Fileobj=out_fp)

    out_fp.seek(0)
    assert out_fp.read() == binary_image