Beispiel #1
0
def test_get_os_path(tmp_path):
    fm = FileContentsManager(root_dir=str(tmp_path))
    path = fm._get_os_path('/path/to/notebook/test.ipynb')
    rel_path_list = '/path/to/notebook/test.ipynb'.split('/')
    fs_path = os.path.join(fm.root_dir, *rel_path_list)
    assert path == fs_path

    fm = FileContentsManager(root_dir=str(tmp_path))
    path = fm._get_os_path('test.ipynb')
    fs_path = os.path.join(fm.root_dir, 'test.ipynb')
    assert path == fs_path

    fm = FileContentsManager(root_dir=str(tmp_path))
    path = fm._get_os_path('////test.ipynb')
    fs_path = os.path.join(fm.root_dir, 'test.ipynb')
    assert path == fs_path
Beispiel #2
0
def test_get_os_path(tmp_path):
    fm = FileContentsManager(root_dir=str(tmp_path))
    path = fm._get_os_path("/path/to/notebook/test.ipynb")
    rel_path_list = "/path/to/notebook/test.ipynb".split("/")
    fs_path = os.path.join(fm.root_dir, *rel_path_list)
    assert path == fs_path

    fm = FileContentsManager(root_dir=str(tmp_path))
    path = fm._get_os_path("test.ipynb")
    fs_path = os.path.join(fm.root_dir, "test.ipynb")
    assert path == fs_path

    fm = FileContentsManager(root_dir=str(tmp_path))
    path = fm._get_os_path("////test.ipynb")
    fs_path = os.path.join(fm.root_dir, "test.ipynb")
    assert path == fs_path
Beispiel #3
0
def test_403(tmp_path):
    if hasattr(os, 'getuid'):
        if os.getuid() == 0:
            raise pytest.skip("Can't test permissions as root")
    if sys.platform.startswith('win'):
        raise pytest.skip("Can't test permissions on Windows")

    td = str(tmp_path)
    cm = FileContentsManager(root_dir=td)
    model = cm.new_untitled(type='file')
    os_path = cm._get_os_path(model['path'])

    os.chmod(os_path, 0o400)
    try:
        with cm.open(os_path, 'w') as f:
            f.write(u"don't care")
    except HTTPError as e:
        assert e.status_code == 403