Beispiel #1
0
def test_src_dst_all_files(path, labels, mocker):
    """Ensure file paths are tranformed correctly into dir paths"""
    src_str = os.path.join(resolve_path(path.path), "")
    dst_str = src_str
    expected = generate_volmount_args(src_str=src_str,
                                      dst_str=dst_str,
                                      labels=labels)

    result = []
    src_file = os.path.join(path.path, "", "file.txt")
    dest_file = src_file

    base_config = BaseConfig()
    mocker.patch("os.path.exists", return_value=True)
    mocker.patch("os.path.isdir", return_value=False)
    base_config._update_volume_mount_paths(args_list=result,
                                           src_mount_path=src_file,
                                           dst_mount_path=dest_file,
                                           labels=labels)

    explanation = (
        f"provided: {src_file}:{dest_file}",
        f"got: {result}",
        f"expected {expected}",
    )
    assert result == expected, explanation
    assert all(part.endswith('/')
               for part in result[1].split(':')[0:1]), explanation
Beispiel #2
0
def test_check_not_safe_to_mount_dir(not_safe, mocker):
    """Ensure unsafe directories are not mounted"""
    with pytest.raises(ConfigurationError):
        bc = BaseConfig()
        mocker.patch("os.path.exists", return_value=True)
        bc._update_volume_mount_paths(args_list=[],
                                      src_mount_path=not_safe,
                                      dst_mount_path=None)
Beispiel #3
0
def test_check_not_safe_to_mount_file(not_safe, mocker):
    """Ensure unsafe directories for a given file are not mounted"""
    file_path = os.path.join(not_safe, "file.txt")
    with pytest.raises(ConfigurationError):
        bc = BaseConfig()
        mocker.patch("os.path.exists", return_value=True)
        bc._update_volume_mount_paths(args_list=[],
                                      src_mount_path=file_path,
                                      dst_mount_path=None)