##// END OF EJS Templates
TEST: Refactor symlink tests.
Scott Sanderson -
Show More
@@ -18,15 +18,26 b' from IPython.testing import decorators as dec'
18 from ..filemanager import FileContentsManager
18 from ..filemanager import FileContentsManager
19
19
20
20
21 def _make_dir(contents_manager, api_path):
22 """
23 Make a directory.
24 """
25 os_path = contents_manager._get_os_path(api_path)
26 try:
27 os.makedirs(os_path)
28 except OSError:
29 print("Directory already exists: %r" % os_path)
30
31
21 class TestFileContentsManager(TestCase):
32 class TestFileContentsManager(TestCase):
22
33
23 def symlink(self, src, dst):
34 def symlink(self, contents_manager, src, dst):
24 """Make a symlink to src from dst
35 """Make a symlink to src from dst
25
36
26 src and dst are api_paths
37 src and dst are api_paths
27 """
38 """
28 src_os_path = self.contents_manager._get_os_path(src)
39 src_os_path = contents_manager._get_os_path(src)
29 dst_os_path = self.contents_manager._get_os_path(dst)
40 dst_os_path = contents_manager._get_os_path(dst)
30 print(src_os_path, dst_os_path, os.path.isfile(src_os_path))
41 print(src_os_path, dst_os_path, os.path.isfile(src_os_path))
31 os.symlink(src_os_path, dst_os_path)
42 os.symlink(src_os_path, dst_os_path)
32
43
@@ -80,29 +91,31 b' class TestFileContentsManager(TestCase):'
80
91
81 @dec.skip_win32
92 @dec.skip_win32
82 def test_bad_symlink(self):
93 def test_bad_symlink(self):
83 cm = self.contents_manager
94 with TemporaryDirectory() as td:
95 cm = FileContentsManager(root_dir=td)
84 path = 'test bad symlink'
96 path = 'test bad symlink'
85 self.make_dir(path)
97 _make_dir(cm, path)
86
98
87 file_model = cm.new_untitled(path=path, ext='.txt')
99 file_model = cm.new_untitled(path=path, ext='.txt')
88
100
89 # create a broken symlink
101 # create a broken symlink
90 self.symlink("target", '%s/%s' % (path, 'bad symlink'))
102 self.symlink(cm, "target", '%s/%s' % (path, 'bad symlink'))
91 model = cm.get(path)
103 model = cm.get(path)
92 self.assertEqual(model['content'], [file_model])
104 self.assertEqual(model['content'], [file_model])
93
105
94 @dec.skip_win32
106 @dec.skip_win32
95 def test_good_symlink(self):
107 def test_good_symlink(self):
96 cm = self.contents_manager
108 with TemporaryDirectory() as td:
109 cm = FileContentsManager(root_dir=td)
97 parent = 'test good symlink'
110 parent = 'test good symlink'
98 name = 'good symlink'
111 name = 'good symlink'
99 path = '{0}/{1}'.format(parent, name)
112 path = '{0}/{1}'.format(parent, name)
100 self.make_dir(parent)
113 _make_dir(cm, parent)
101
114
102 file_model = cm.new(path=parent + '/zfoo.txt')
115 file_model = cm.new(path=parent + '/zfoo.txt')
103
116
104 # create a good symlink
117 # create a good symlink
105 self.symlink(file_model['path'], path)
118 self.symlink(cm, file_model['path'], path)
106 symlink_model = cm.get(path, content=False)
119 symlink_model = cm.get(path, content=False)
107 dir_model = cm.get(parent)
120 dir_model = cm.get(parent)
108 self.assertEqual(
121 self.assertEqual(
@@ -126,11 +139,7 b' class TestContentsManager(TestCase):'
126 def make_dir(self, api_path):
139 def make_dir(self, api_path):
127 """make subdirectory, rel_path is the relative path
140 """make subdirectory, rel_path is the relative path
128 to that directory from the location where the server started"""
141 to that directory from the location where the server started"""
129 os_path = self.contents_manager._get_os_path(api_path)
142 _make_dir(self.contents_manager, api_path)
130 try:
131 os.makedirs(os_path)
132 except OSError:
133 print("Directory already exists: %r" % os_path)
134
143
135 def add_code_cell(self, nb):
144 def add_code_cell(self, nb):
136 output = nbformat.new_output("display_data", {'application/javascript': "alert('hi');"})
145 output = nbformat.new_output("display_data", {'application/javascript': "alert('hi');"})
General Comments 0
You need to be logged in to leave comments. Login now