##// END OF EJS Templates
use request.text for Python 3 (content is always bytes)
MinRK -
Show More
@@ -1,85 +1,85 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 u'Γ₯ b/Γ§. d',
21 21 ]
22 22 hidden = [
23 23 u'.Γ₯ b',
24 24 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.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.sep))
41 41 r = requests.get(url_path_join(url, 'files', d, 'foo'))
42 42 r.raise_for_status()
43 self.assertEqual(r.content, b'foo')
43 self.assertEqual(r.text, '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.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)
52 52
53 53 def test_old_files_redirect(self):
54 54 """pre-2.0 'files/' prefixed links are properly redirected"""
55 55 nbdir = self.notebook_dir.name
56 56 base = self.base_url()
57 57
58 58 os.mkdir(pjoin(nbdir, 'files'))
59 59 os.makedirs(pjoin(nbdir, 'sub', 'files'))
60 60
61 61 for prefix in ('', 'sub'):
62 62 with open(pjoin(nbdir, prefix, 'files', 'f1.txt'), 'w') as f:
63 63 f.write(prefix + '/files/f1')
64 64 with open(pjoin(nbdir, prefix, 'files', 'f2.txt'), 'w') as f:
65 65 f.write(prefix + '/files/f2')
66 66 with open(pjoin(nbdir, prefix, 'f2.txt'), 'w') as f:
67 67 f.write(prefix + '/f2')
68 68 with open(pjoin(nbdir, prefix, 'f3.txt'), 'w') as f:
69 69 f.write(prefix + '/f3')
70 70
71 71 url = url_path_join(base, 'notebooks', prefix, 'files', 'f1.txt')
72 72 r = requests.get(url)
73 73 self.assertEqual(r.status_code, 200)
74 self.assertEqual(r.content, prefix + '/files/f1')
74 self.assertEqual(r.text, prefix + '/files/f1')
75 75
76 76 url = url_path_join(base, 'notebooks', prefix, 'files', 'f2.txt')
77 77 r = requests.get(url)
78 78 self.assertEqual(r.status_code, 200)
79 self.assertEqual(r.content, prefix + '/files/f2')
79 self.assertEqual(r.text, prefix + '/files/f2')
80 80
81 81 url = url_path_join(base, 'notebooks', prefix, 'files', 'f3.txt')
82 82 r = requests.get(url)
83 83 self.assertEqual(r.status_code, 200)
84 self.assertEqual(r.content, prefix + '/f3')
84 self.assertEqual(r.text, prefix + '/f3')
85 85
General Comments 0
You need to be logged in to leave comments. Login now