scitacean.testing.transfer.FakeFileTransfer#
- class scitacean.testing.transfer.FakeFileTransfer(*, fs=None, files=None, reverted=None, source_folder=None)[source]#
Mimic a file down-/upload handler.
Files are not transferred to a server but loaded into an internal storage.
It is possible to use a fake file system as implemented by pyfakefs.
Examples
Using the
fsfixture from pyfakefs in pytest:def test_upload(fs): client = FakeClient.from_token( url="...", token="...", file_transfer=FakeFileTransfer(fs=fs) ) dset = ... client.upload_new_dataset_now(dset) assert client.file_transfer.files[expected_remote_path] == file_content
See also
scitacean.testing.client.FakeClientClient to mimic a SciCat server.
Constructors
__init__(*[, fs, files, reverted, source_folder])Initialize a file transfer.
Methods
connect_for_download(dataset, ...)Open a connection for downloads.
connect_for_upload(dataset, ...)Open a connection for uploads.
source_folder_for(dataset)Return the source folder for a given dataset.
- __init__(*, fs=None, files=None, reverted=None, source_folder=None)[source]#
Initialize a file transfer.
- Parameters:
fs (
Optional[FakeFilesystem], default:None) – Fake filesystem. If given, files are down-/uploaded to/from this filesystem instead of the real one. If set toNone, the real filesystem is used.files (
Optional[Mapping[TypeVar(RemotePathOrStr,RemotePath,str,RemotePath|str),bytes]], default:None) – Initial files stored “on the server”. Maps file names to contents.reverted (
Optional[Mapping[TypeVar(RemotePathOrStr,RemotePath,str,RemotePath|str),bytes]], default:None) – Files that have been uploaded and subsequently been removed.source_folder (
Union[str,RemotePath,None], default:None) – Upload files to this folder if set. Otherwise, upload to the dataset’s source_folder. Ignored when downloading files.
- connect_for_download(dataset, representative_file_path)[source]#
Open a connection for downloads.
- Return type:
- connect_for_upload(dataset, representative_file_path)[source]#
Open a connection for uploads.
- Return type: