Exemple #1
0
def test_e2e_copy_recursive_to_platform(helper: Helper,
                                        nested_data: Tuple[str, str, str],
                                        tmp_path: Path) -> None:
    helper.mkdir("")
    srcfile, checksum, dir_path = nested_data
    target_file_name = Path(srcfile).name

    # Upload local file
    captured = helper.run_cli(
        ["storage", "cp", "-r", dir_path, helper.tmpstorage])
    # stderr has logs like "Using path ..."
    # assert not captured.err
    assert not captured.out

    helper.check_file_exists_on_storage(target_file_name,
                                        f"nested/directory/for/test",
                                        FILE_SIZE_B // 3)

    # Download into local directory and confirm checksum
    targetdir = tmp_path / "bar"
    targetdir.mkdir()
    helper.run_cli(
        ["storage", "cp", "-r", f"{helper.tmpstorage}",
         str(targetdir)])
    targetfile = targetdir / "nested" / "directory" / "for" / "test" / target_file_name
    print("source file", srcfile)
    print("target file", targetfile)
    assert helper.hash_hex(targetfile) == checksum
Exemple #2
0
def test_copy_local_file_to_platform_directory(helper: Helper,
                                               data2: _Data) -> None:
    srcfile, checksum = data2
    file_name = str(PurePath(srcfile).name)

    helper.mkdir("folder", parents=True)
    # Upload local file to existing directory
    helper.run_cli(["storage", "cp", srcfile, helper.tmpstorage + "/folder"])

    # Ensure file is there
    helper.check_file_exists_on_storage(file_name, "folder", FILE_SIZE_B // 3)
Exemple #3
0
def test_e2e_storage(data: Tuple[Path, str], tmp_path: Path,
                     helper: Helper) -> None:
    srcfile, checksum = data

    # Create directory for the test
    helper.mkdir("folder", parents=True)

    # Upload local file
    helper.check_upload_file_to_storage("foo", "folder", str(srcfile))

    # Confirm file has been uploaded
    helper.check_file_exists_on_storage("foo", "folder", FILE_SIZE_B)

    # Download into local file and confirm checksum
    helper.check_file_on_storage_checksum("foo", "folder", checksum,
                                          str(tmp_path), "bar")

    # Rename file on the storage
    helper.check_rename_file_on_storage("foo", "folder", "bar", "folder")
    helper.check_file_exists_on_storage("bar", "folder", FILE_SIZE_B)

    # Rename directory on the storage
    helper.check_rename_directory_on_storage("folder", "folder2")
    helper.check_file_exists_on_storage("bar", "folder2", FILE_SIZE_B)

    # Non-recursive removing should not have any effect
    with pytest.raises(IsADirectoryError,
                       match=".+Target is a directory") as cm:
        helper.rm("folder2", recursive=False)
    assert cm.value.errno == errno.EISDIR
    helper.check_file_exists_on_storage("bar", "folder2", FILE_SIZE_B)
Exemple #4
0
def test_copy_local_single_file_to_platform_file(helper: Helper,
                                                 data: _Data) -> None:
    # case when copy happens with rename to 'different_name.txt'
    srcfile, checksum = data
    file_name = str(PurePath(srcfile).name)

    helper.mkdir("folder", parents=True)
    # Upload local file to platform
    helper.run_cli([
        "storage", "cp", srcfile,
        helper.tmpstorage + "/folder/different_name.txt"
    ])

    # Ensure file is there
    helper.check_file_exists_on_storage("different_name.txt", "folder",
                                        FILE_SIZE_B)
    helper.check_file_absent_on_storage(file_name, "folder")
Exemple #5
0
def test_copy_and_remove_multiple_files(helper: Helper, data2: _Data,
                                        data3: _Data, tmp_path: Path) -> None:
    helper.mkdir("")
    # case when copy happens with rename to 'different_name.txt'
    srcfile, checksum = data2
    srcfile2, checksum2 = data3
    srcname = os.path.basename(srcfile)
    srcname2 = os.path.basename(srcfile2)

    # Upload local files
    captured = helper.run_cli(
        ["storage", "cp", srcfile, srcfile2, helper.tmpstorage])
    assert captured.out == ""

    # Confirm files has been uploaded
    helper.check_file_exists_on_storage(srcname, "", FILE_SIZE_B // 3)
    helper.check_file_exists_on_storage(srcname2, "", FILE_SIZE_B // 5)

    # Download into local directory and confirm checksum
    targetdir = tmp_path / "bar"
    targetdir.mkdir()
    helper.run_cli([
        "storage",
        "cp",
        f"{helper.tmpstorage}/{srcname}",
        f"{helper.tmpstorage}/{srcname2}",
        str(targetdir),
    ])
    assert helper.hash_hex(targetdir / srcname) == checksum
    assert helper.hash_hex(targetdir / srcname2) == checksum2

    # Remove the files from platform
    captured = helper.run_cli([
        "storage",
        "rm",
        f"{helper.tmpstorage}/{srcname}",
        f"{helper.tmpstorage}/{srcname2}",
    ])
    assert captured.out == ""

    # Ensure files are not there
    helper.check_file_absent_on_storage(srcname, "")
    helper.check_file_absent_on_storage(srcname2, "")