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