##// END OF EJS Templates
py3k bytes, for crying out loud
MinRK -
Show More
@@ -1,51 +1,51
1 # coding: utf-8
1 # coding: utf-8
2 """Test the /files/ handler."""
2 """Test the /files/ handler."""
3
3
4 import io
4 import io
5 import os
5 import os
6 from unicodedata import normalize
6 from unicodedata import normalize
7
7
8 pjoin = os.path.join
8 pjoin = os.path.join
9
9
10 import requests
10 import requests
11
11
12 from IPython.html.utils import url_path_join
12 from IPython.html.utils import url_path_join
13 from .launchnotebook import NotebookTestBase
13 from .launchnotebook import NotebookTestBase
14 from IPython.utils import py3compat
14 from IPython.utils import py3compat
15
15
16 class FilesTest(NotebookTestBase):
16 class FilesTest(NotebookTestBase):
17 def test_hidden_files(self):
17 def test_hidden_files(self):
18 not_hidden = [
18 not_hidden = [
19 u'Γ₯ b',
19 u'Γ₯ b',
20 pjoin(u'Γ₯ b/Γ§. d')
20 pjoin(u'Γ₯ b/Γ§. d')
21 ]
21 ]
22 hidden = [
22 hidden = [
23 u'.Γ₯ b',
23 u'.Γ₯ b',
24 pjoin(u'Γ₯ b/.Γ§ d')
24 pjoin(u'Γ₯ b/.Γ§ d')
25 ]
25 ]
26 dirs = not_hidden + hidden
26 dirs = not_hidden + hidden
27
27
28 nbdir = self.notebook_dir.name
28 nbdir = self.notebook_dir.name
29 for d in dirs:
29 for d in dirs:
30 path = pjoin(nbdir, d.replace('/', os.path.sep))
30 path = pjoin(nbdir, d.replace('/', os.path.sep))
31 if not os.path.exists(path):
31 if not os.path.exists(path):
32 os.mkdir(path)
32 os.mkdir(path)
33 with open(pjoin(path, 'foo'), 'w') as f:
33 with open(pjoin(path, 'foo'), 'w') as f:
34 f.write('foo')
34 f.write('foo')
35 with open(pjoin(path, '.foo'), 'w') as f:
35 with open(pjoin(path, '.foo'), 'w') as f:
36 f.write('.foo')
36 f.write('.foo')
37 url = self.base_url()
37 url = self.base_url()
38
38
39 for d in not_hidden:
39 for d in not_hidden:
40 path = pjoin(nbdir, d.replace('/', os.path.sep))
40 path = pjoin(nbdir, d.replace('/', os.path.sep))
41 r = requests.get(url_path_join(url, 'files', d, 'foo'))
41 r = requests.get(url_path_join(url, 'files', d, 'foo'))
42 r.raise_for_status()
42 r.raise_for_status()
43 self.assertEqual(r.content, u'foo')
43 self.assertEqual(r.content, b'foo')
44 r = requests.get(url_path_join(url, 'files', d, '.foo'))
44 r = requests.get(url_path_join(url, 'files', d, '.foo'))
45 self.assertEqual(r.status_code, 403)
45 self.assertEqual(r.status_code, 403)
46
46
47 for d in hidden:
47 for d in hidden:
48 path = pjoin(nbdir, d.replace('/', os.path.sep))
48 path = pjoin(nbdir, d.replace('/', os.path.sep))
49 for foo in ('foo', '.foo'):
49 for foo in ('foo', '.foo'):
50 r = requests.get(url_path_join(url, 'files', d, foo))
50 r = requests.get(url_path_join(url, 'files', d, foo))
51 self.assertEqual(r.status_code, 403)
51 self.assertEqual(r.status_code, 403)
General Comments 0
You need to be logged in to leave comments. Login now