Show More
@@ -20,6 +20,16 b' from ..filemanager import FileContentsManager' | |||||
20 |
|
20 | |||
21 | class TestFileContentsManager(TestCase): |
|
21 | class TestFileContentsManager(TestCase): | |
22 |
|
22 | |||
|
23 | def symlink(self, src, dst): | |||
|
24 | """Make a symlink to src from dst | |||
|
25 | ||||
|
26 | src and dst are api_paths | |||
|
27 | """ | |||
|
28 | src_os_path = self.contents_manager._get_os_path(src) | |||
|
29 | dst_os_path = self.contents_manager._get_os_path(dst) | |||
|
30 | print(src_os_path, dst_os_path, os.path.isfile(src_os_path)) | |||
|
31 | os.symlink(src_os_path, dst_os_path) | |||
|
32 | ||||
23 | def test_root_dir(self): |
|
33 | def test_root_dir(self): | |
24 | with TemporaryDirectory() as td: |
|
34 | with TemporaryDirectory() as td: | |
25 | fm = FileContentsManager(root_dir=td) |
|
35 | fm = FileContentsManager(root_dir=td) | |
@@ -68,6 +78,38 b' class TestFileContentsManager(TestCase):' | |||||
68 | self.assertEqual(cp_dir, os.path.join(root, fm.checkpoint_dir, cp_name)) |
|
78 | self.assertEqual(cp_dir, os.path.join(root, fm.checkpoint_dir, cp_name)) | |
69 | self.assertEqual(cp_subdir, os.path.join(root, subd, fm.checkpoint_dir, cp_name)) |
|
79 | self.assertEqual(cp_subdir, os.path.join(root, subd, fm.checkpoint_dir, cp_name)) | |
70 |
|
80 | |||
|
81 | @dec.skip_win32 | |||
|
82 | def test_bad_symlink(self): | |||
|
83 | cm = self.contents_manager | |||
|
84 | path = 'test bad symlink' | |||
|
85 | self.make_dir(path) | |||
|
86 | ||||
|
87 | file_model = cm.new_untitled(path=path, ext='.txt') | |||
|
88 | ||||
|
89 | # create a broken symlink | |||
|
90 | self.symlink("target", '%s/%s' % (path, 'bad symlink')) | |||
|
91 | model = cm.get(path) | |||
|
92 | self.assertEqual(model['content'], [file_model]) | |||
|
93 | ||||
|
94 | @dec.skip_win32 | |||
|
95 | def test_good_symlink(self): | |||
|
96 | cm = self.contents_manager | |||
|
97 | parent = 'test good symlink' | |||
|
98 | name = 'good symlink' | |||
|
99 | path = '{0}/{1}'.format(parent, name) | |||
|
100 | self.make_dir(parent) | |||
|
101 | ||||
|
102 | file_model = cm.new(path=parent + '/zfoo.txt') | |||
|
103 | ||||
|
104 | # create a good symlink | |||
|
105 | self.symlink(file_model['path'], path) | |||
|
106 | symlink_model = cm.get(path, content=False) | |||
|
107 | dir_model = cm.get(parent) | |||
|
108 | self.assertEqual( | |||
|
109 | sorted(dir_model['content'], key=lambda x: x['name']), | |||
|
110 | [symlink_model, file_model], | |||
|
111 | ) | |||
|
112 | ||||
71 |
|
113 | |||
72 | class TestContentsManager(TestCase): |
|
114 | class TestContentsManager(TestCase): | |
73 |
|
115 | |||
@@ -90,17 +132,6 b' class TestContentsManager(TestCase):' | |||||
90 | except OSError: |
|
132 | except OSError: | |
91 | print("Directory already exists: %r" % os_path) |
|
133 | print("Directory already exists: %r" % os_path) | |
92 |
|
134 | |||
93 | def symlink(self, src, dst): |
|
|||
94 | """Make a symlink to src from dst |
|
|||
95 |
|
||||
96 | src and dst are api_paths |
|
|||
97 | """ |
|
|||
98 | src_os_path = self.contents_manager._get_os_path(src) |
|
|||
99 | dst_os_path = self.contents_manager._get_os_path(dst) |
|
|||
100 | print(src_os_path, dst_os_path, os.path.isfile(src_os_path)) |
|
|||
101 | os.symlink(src_os_path, dst_os_path) |
|
|||
102 |
|
||||
103 |
|
||||
104 | def add_code_cell(self, nb): |
|
135 | def add_code_cell(self, nb): | |
105 | output = nbformat.new_output("display_data", {'application/javascript': "alert('hi');"}) |
|
136 | output = nbformat.new_output("display_data", {'application/javascript': "alert('hi');"}) | |
106 | cell = nbformat.new_code_cell("print('hi')", outputs=[output]) |
|
137 | cell = nbformat.new_code_cell("print('hi')", outputs=[output]) | |
@@ -220,39 +251,6 b' class TestContentsManager(TestCase):' | |||||
220 | with self.assertRaises(HTTPError): |
|
251 | with self.assertRaises(HTTPError): | |
221 | cm.get('foo', type='file') |
|
252 | cm.get('foo', type='file') | |
222 |
|
253 | |||
223 |
|
||||
224 | @dec.skip_win32 |
|
|||
225 | def test_bad_symlink(self): |
|
|||
226 | cm = self.contents_manager |
|
|||
227 | path = 'test bad symlink' |
|
|||
228 | self.make_dir(path) |
|
|||
229 |
|
||||
230 | file_model = cm.new_untitled(path=path, ext='.txt') |
|
|||
231 |
|
||||
232 | # create a broken symlink |
|
|||
233 | self.symlink("target", '%s/%s' % (path, 'bad symlink')) |
|
|||
234 | model = cm.get(path) |
|
|||
235 | self.assertEqual(model['content'], [file_model]) |
|
|||
236 |
|
||||
237 | @dec.skip_win32 |
|
|||
238 | def test_good_symlink(self): |
|
|||
239 | cm = self.contents_manager |
|
|||
240 | parent = 'test good symlink' |
|
|||
241 | name = 'good symlink' |
|
|||
242 | path = '{0}/{1}'.format(parent, name) |
|
|||
243 | self.make_dir(parent) |
|
|||
244 |
|
||||
245 | file_model = cm.new(path=parent + '/zfoo.txt') |
|
|||
246 |
|
||||
247 | # create a good symlink |
|
|||
248 | self.symlink(file_model['path'], path) |
|
|||
249 | symlink_model = cm.get(path, content=False) |
|
|||
250 | dir_model = cm.get(parent) |
|
|||
251 | self.assertEqual( |
|
|||
252 | sorted(dir_model['content'], key=lambda x: x['name']), |
|
|||
253 | [symlink_model, file_model], |
|
|||
254 | ) |
|
|||
255 |
|
||||
256 | def test_update(self): |
|
254 | def test_update(self): | |
257 | cm = self.contents_manager |
|
255 | cm = self.contents_manager | |
258 | # Create a notebook |
|
256 | # Create a notebook | |
@@ -402,3 +400,4 b' class TestContentsManager(TestCase):' | |||||
402 | cm.mark_trusted_cells(nb, path) |
|
400 | cm.mark_trusted_cells(nb, path) | |
403 | cm.check_and_sign(nb, path) |
|
401 | cm.check_and_sign(nb, path) | |
404 | assert cm.notary.check_signature(nb) |
|
402 | assert cm.notary.check_signature(nb) | |
|
403 |
General Comments 0
You need to be logged in to leave comments.
Login now