def test_pyfs_copy(pyfs, dummy_location): """Test send file.""" s = PyFSFileStorage(join(dummy_location.uri, 'anotherpath/data')) s.save(BytesIO(b'otherdata')) pyfs.copy(s) fp = pyfs.open() assert fp.read() == b'otherdata'
def test_pyfs_delete(app, db, dummy_location): """Test init of files.""" testurl = join(dummy_location.uri, 'subpath/data') s = PyFSFileStorage(testurl) s.initialize(size=100) assert exists(testurl) s.delete() assert not exists(testurl) s = PyFSFileStorage(join(dummy_location.uri, 'anotherpath/data')) pytest.raises(ResourceNotFoundError, s.delete)
def test_pyfs_checksum_fail(): """Test fixity problems.""" # Raise an error during checksum calculation def callback(total, size): raise OSError(errno.EPERM, "Permission") s = PyFSFileStorage('LICENSE', size=getsize('LICENSE')) pytest.raises(StorageError, s.checksum, progress_callback=callback)
def test_copy(s3_bucket, s3fs): """Test copy file.""" data = b'test' s3fs.save(BytesIO(data)) s3_copy_path = 's3://{}/path/to/copy/data'.format(s3_bucket.name) s3fs_copy = S3FSFileStorage(s3_copy_path) s3fs_copy.copy(s3fs) assert s3fs_copy.open().read() == data tmppath = tempfile.mkdtemp() s = PyFSFileStorage(os.path.join(tmppath, 'anotherpath/data')) data = b'othertest' s.save(BytesIO(data)) s3fs_copy.copy(s) assert s3fs_copy.open().read() == data shutil.rmtree(tmppath)
def test_pyfs_checksum(get_md5): """Test fixity.""" # Compute checksum of license file/ with open('LICENSE', 'rb') as fp: data = fp.read() checksum = get_md5(data) counter = dict(size=0) def callback(total, size): counter['size'] = size # Now do it with storage interface s = PyFSFileStorage('LICENSE', size=getsize('LICENSE')) assert checksum == s.checksum(chunk_size=2, progress_callback=callback) assert counter['size'] == getsize('LICENSE') # No size provided, means progress callback isn't called counter['size'] = 0 s = PyFSFileStorage('LICENSE') assert checksum == s.checksum(chunk_size=2, progress_callback=callback) assert counter['size'] == 0
def pyfs(dummy_location, pyfs_testpath): """Instance of PyFSFileStorage.""" return PyFSFileStorage(pyfs_testpath)