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 fs fixture 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.FakeClient

Client to mimic a SciCat server.

Constructors

__init__(*[, fs, files, reverted, source_folder])

Initialize a file transfer.

Methods

connect_for_download()

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 (FakeFilesystem | None, default: None) – Fake filesystem. If given, files are down-/uploaded to/from this filesystem instead of the real one. If set to None, the real filesystem is used.

  • files (dict[str | RemotePath, bytes] | None, default: None) – Initial files stored “on the server”. Maps file names to contents.

  • reverted (dict[str | RemotePath, bytes] | None, default: None) – Files that have been uploaded and subsequently been removed.

  • source_folder (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()[source]#

Open a connection for downloads.

Return type:

Iterator[FakeDownloadConnection]

connect_for_upload(dataset)[source]#

Open a connection for uploads.

Return type:

Iterator[FakeUploadConnection]

source_folder_for(dataset)[source]#

Return the source folder for a given dataset.

Return type:

RemotePath