def test_fs_volume_copy_files(basedir, emptydir, data_a, data_e): """Test copying separate files from a storage volume.""" source = FileSystemStorage(basedir=basedir) target = FileSystemStorage(basedir=emptydir) source.copy(src='A.json', dst='static/A.json', store=target) source.copy(src='examples/data', dst='static/examples/data', store=target) files = {key: file for key, file in target.walk(src='static')} assert set(files.keys()) == {'static/A.json', 'static/examples/data/data.json'} with files['static/examples/data/data.json'].open() as f: assert json.load(f) == data_e source.copy(src=['examples'], dst='static2', store=target, verbose=True) files = {key: file for key, file in target.walk(src='static2')} assert set(files.keys()) == {'static2/B.json', 'static2/C.json', 'static2/data/data.json'} source.copy(src=['examples/'], dst='static3', store=target, verbose=True) files = {key: file for key, file in target.walk(src='static3')} assert set(files.keys()) == {'static3/B.json', 'static3/C.json', 'static3/data/data.json'}
def test_fs_volume_copy_all(basedir, emptydir, filenames_all, data_a): """Test copying the full directory of a storage volume.""" source = FileSystemStorage(basedir=basedir) target = FileSystemStorage(basedir=emptydir) source.copy(src=None, dst=None, store=target) files = {key: file for key, file in target.walk(src='')} assert set(files.keys()) == filenames_all with files['A.json'].open() as f: assert json.load(f) == data_a
def test_fs_volume_walk(basedir, filenames_all): """Test listing files in a directory.""" store = FileSystemStorage(basedir=basedir) # -- Full directory. files = store.walk(src='') assert set([key for key, _ in files]) == filenames_all # -- Sub-directory. files = store.walk(src='examples') keys = set([key for key, _ in files]) assert keys == {'examples/B.json', 'examples/C.json', 'examples/data/data.json'} files = store.walk(src=util.join('examples', 'data')) assert set([key for key, _ in files]) == {'examples/data/data.json'} # -- Single file. files = store.walk(src=util.join('docs', 'D.json')) assert set([key for key, _ in files]) == {'docs/D.json'} # -- Unknown file or directory. files = store.walk(src=util.join('docs', 'E.json')) assert files == []
def test_remote_volume_upload_all(mock_ssh, basedir, emptydir, filenames_all, data_a): """Test uploading a full directory to a storage volume.""" with ssh.ssh_client('test', sep=os.sep) as client: source = RemoteStorage(remotedir=basedir, client=client) target = FileSystemStorage(basedir=emptydir) source.copy(src=None, dst=None, store=target) files = {key: file for key, file in target.walk(src='')} assert set(files.keys()) == filenames_all with files['A.json'].open() as f: assert json.load(f) == data_a
def test_remote_volume_upload_file(mock_ssh, basedir, emptydir, data_e): """Test uploading a file to a storage volume.""" with ssh.ssh_client('test', sep=os.sep) as client: source = RemoteStorage(remotedir=basedir, client=client) target = FileSystemStorage(basedir=emptydir) source.copy(src='examples/data/data.json', dst='static/examples/data/data.json', store=target) files = {key: file for key, file in target.walk(src='static')} assert set(files.keys()) == {'static/examples/data/data.json'} with files['static/examples/data/data.json'].open() as f: assert json.load(f) == data_e
def test_fs_volume_upload_file(basedir, emptydir, data_e): """Test uploading a file to a storage volume.""" source = FileSystemStorage(basedir=basedir) target = FileSystemStorage(basedir=emptydir) source.copy( src='examples/data/data.json', dst='static/examples/data/data.json', store=target, verbose=True ) files = {key: file for key, file in target.walk(src='static')} assert set(files.keys()) == {'static/examples/data/data.json'} with files['static/examples/data/data.json'].open() as f: assert json.load(f) == data_e