Show More
@@ -20,6 +20,16 b' from ..filemanager import FileContentsManager' | |||
|
20 | 20 | |
|
21 | 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 | 33 | def test_root_dir(self): |
|
24 | 34 | with TemporaryDirectory() as td: |
|
25 | 35 | fm = FileContentsManager(root_dir=td) |
@@ -67,6 +77,38 b' class TestFileContentsManager(TestCase):' | |||
|
67 | 77 | self.assertNotEqual(cp_dir, cp_subdir) |
|
68 | 78 | self.assertEqual(cp_dir, os.path.join(root, fm.checkpoint_dir, cp_name)) |
|
69 | 79 | self.assertEqual(cp_subdir, os.path.join(root, subd, fm.checkpoint_dir, cp_name)) |
|
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 | ) | |
|
70 | 112 | |
|
71 | 113 | |
|
72 | 114 | class TestContentsManager(TestCase): |
@@ -89,17 +131,6 b' class TestContentsManager(TestCase):' | |||
|
89 | 131 | os.makedirs(os_path) |
|
90 | 132 | except OSError: |
|
91 | 133 | print("Directory already exists: %r" % os_path) |
|
92 | ||
|
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 | 134 | |
|
104 | 135 | def add_code_cell(self, nb): |
|
105 | 136 | output = nbformat.new_output("display_data", {'application/javascript': "alert('hi');"}) |
@@ -220,39 +251,6 b' class TestContentsManager(TestCase):' | |||
|
220 | 251 | with self.assertRaises(HTTPError): |
|
221 | 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 | 254 | def test_update(self): |
|
257 | 255 | cm = self.contents_manager |
|
258 | 256 | # Create a notebook |
@@ -402,3 +400,4 b' class TestContentsManager(TestCase):' | |||
|
402 | 400 | cm.mark_trusted_cells(nb, path) |
|
403 | 401 | cm.check_and_sign(nb, path) |
|
404 | 402 | assert cm.notary.check_signature(nb) |
|
403 |
General Comments 0
You need to be logged in to leave comments.
Login now