notebook/IPython/html/tests/test_files.py

52 lines
1.5 KiB
Python
Raw Normal View History

2013-10-23 06:23:46 +08:00
# coding: utf-8
"""Test the /files/ handler."""
import io
import os
from unicodedata import normalize
pjoin = os.path.join
import requests
from IPython.html.utils import url_path_join
from .launchnotebook import NotebookTestBase
from IPython.utils import py3compat
class FilesTest(NotebookTestBase):
def test_hidden_files(self):
not_hidden = [
u'å b',
pjoin(u'å b/ç. d')
]
hidden = [
u'.å b',
pjoin(u'å b/.ç d')
]
dirs = not_hidden + hidden
nbdir = self.notebook_dir.name
for d in dirs:
path = pjoin(nbdir, d.replace('/', os.path.sep))
if not os.path.exists(path):
os.mkdir(path)
2013-10-23 08:02:57 +08:00
with open(pjoin(path, 'foo'), 'w') as f:
f.write('foo')
with open(pjoin(path, '.foo'), 'w') as f:
f.write('.foo')
2013-10-23 06:23:46 +08:00
url = self.base_url()
for d in not_hidden:
path = pjoin(nbdir, d.replace('/', os.path.sep))
r = requests.get(url_path_join(url, 'files', d, 'foo'))
r.raise_for_status()
2013-10-23 08:32:24 +08:00
self.assertEqual(r.content, b'foo')
2013-10-23 06:23:46 +08:00
r = requests.get(url_path_join(url, 'files', d, '.foo'))
self.assertEqual(r.status_code, 403)
for d in hidden:
path = pjoin(nbdir, d.replace('/', os.path.sep))
for foo in ('foo', '.foo'):
r = requests.get(url_path_join(url, 'files', d, foo))
self.assertEqual(r.status_code, 403)