##// END OF EJS Templates
add tests for file download via ContentsManager
Manuel Riel -
Show More
@@ -8,11 +8,17 b' from unicodedata import normalize'
8 pjoin = os.path.join
8 pjoin = os.path.join
9
9
10 import requests
10 import requests
11 import json
12
13 from IPython.nbformat.current import (new_notebook, write, new_worksheet,
14 new_heading_cell, new_code_cell,
15 new_output)
11
16
12 from IPython.html.utils import url_path_join
17 from IPython.html.utils import url_path_join
13 from .launchnotebook import NotebookTestBase
18 from .launchnotebook import NotebookTestBase
14 from IPython.utils import py3compat
19 from IPython.utils import py3compat
15
20
21
16 class FilesTest(NotebookTestBase):
22 class FilesTest(NotebookTestBase):
17 def test_hidden_files(self):
23 def test_hidden_files(self):
18 not_hidden = [
24 not_hidden = [
@@ -50,6 +56,49 b' class FilesTest(NotebookTestBase):'
50 r = requests.get(url_path_join(url, 'files', d, foo))
56 r = requests.get(url_path_join(url, 'files', d, foo))
51 self.assertEqual(r.status_code, 404)
57 self.assertEqual(r.status_code, 404)
52
58
59 def test_contents_manager(self):
60 "make sure ContentsManager returns right files (ipynb, bin, txt)."
61
62 nbdir = self.notebook_dir.name
63 base = self.base_url()
64
65 nb = new_notebook(name='testnb')
66
67 ws = new_worksheet()
68 nb.worksheets = [ws]
69 ws.cells.append(new_heading_cell(u'Created by test Β³'))
70 cc1 = new_code_cell(input=u'print(2*6)')
71 cc1.outputs.append(new_output(output_text=u'12', output_type='stream'))
72 ws.cells.append(cc1)
73
74 with io.open(pjoin(nbdir, 'testnb.ipynb'), 'w',
75 encoding='utf-8') as f:
76 write(nb, f, format='ipynb')
77
78 with io.open(pjoin(nbdir, 'test.bin'), 'wb') as f:
79 f.write("\x5F\x9D\x3E")
80 f.close()
81
82 with io.open(pjoin(nbdir, 'test.txt'), 'w') as f:
83 f.write(u'foo\nbar')
84 f.close()
85
86 r = requests.get(url_path_join(base, 'files', 'testnb.ipynb'))
87 self.assertEqual(r.status_code, 200)
88 self.assertIn(u'print(2*6)', r.text)
89 json.loads(r.text)
90
91 r = requests.get(url_path_join(base, 'files', 'test.bin'))
92 self.assertEqual(r.status_code, 200)
93 self.assertEqual(r.headers['content-type'], 'application/octet-stream')
94 self.assertEqual(r.content, 'X50+\n')
95
96 r = requests.get(url_path_join(base, 'files', 'test.txt'))
97 self.assertEqual(r.status_code, 200)
98 self.assertEqual(r.headers['content-type'], 'text/plain')
99 self.assertEqual(r.content, u'foo\nbar')
100
101
53 def test_old_files_redirect(self):
102 def test_old_files_redirect(self):
54 """pre-2.0 'files/' prefixed links are properly redirected"""
103 """pre-2.0 'files/' prefixed links are properly redirected"""
55 nbdir = self.notebook_dir.name
104 nbdir = self.notebook_dir.name
General Comments 0
You need to be logged in to leave comments. Login now