##// END OF EJS Templates
cleanup test_nbmanager...
MinRK -
Show More
@@ -61,7 +61,10 b' class TestNotebookManager(TestCase):'
61 def setUp(self):
61 def setUp(self):
62 self._temp_dir = TemporaryDirectory()
62 self._temp_dir = TemporaryDirectory()
63 self.td = self._temp_dir.name
63 self.td = self._temp_dir.name
64 self.nbm = FileNotebookManager(notebook_dir=self.td, log=logging.getLogger())
64 self.notebook_manager = FileNotebookManager(
65 notebook_dir=self.td,
66 log=logging.getLogger()
67 )
65
68
66 def tearDown(self):
69 def tearDown(self):
67 self._temp_dir.cleanup()
70 self._temp_dir.cleanup()
@@ -83,7 +86,7 b' class TestNotebookManager(TestCase):'
83 nb.worksheets[0].cells.append(cell)
86 nb.worksheets[0].cells.append(cell)
84
87
85 def new_notebook(self):
88 def new_notebook(self):
86 nbm = self.nbm
89 nbm = self.notebook_manager
87 model = nbm.create_notebook()
90 model = nbm.create_notebook()
88 name = model['name']
91 name = model['name']
89 path = model['path']
92 path = model['path']
@@ -96,10 +99,7 b' class TestNotebookManager(TestCase):'
96 return nb, name, path
99 return nb, name, path
97
100
98 def test_create_notebook(self):
101 def test_create_notebook(self):
99 with TemporaryDirectory() as td:
102 nm = self.notebook_manager
100 # Test in root directory
101 # Create a notebook
102 nm = FileNotebookManager(notebook_dir=td)
103 # Test in root directory
103 # Test in root directory
104 model = nm.create_notebook()
104 model = nm.create_notebook()
105 assert isinstance(model, dict)
105 assert isinstance(model, dict)
@@ -119,10 +119,8 b' class TestNotebookManager(TestCase):'
119 self.assertEqual(model['path'], sub_dir.strip('/'))
119 self.assertEqual(model['path'], sub_dir.strip('/'))
120
120
121 def test_get_notebook(self):
121 def test_get_notebook(self):
122 with TemporaryDirectory() as td:
122 nm = self.notebook_manager
123 # Test in root directory
124 # Create a notebook
123 # Create a notebook
125 nm = FileNotebookManager(notebook_dir=td)
126 model = nm.create_notebook()
124 model = nm.create_notebook()
127 name = model['name']
125 name = model['name']
128 path = model['path']
126 path = model['path']
@@ -148,10 +146,8 b' class TestNotebookManager(TestCase):'
148 self.assertEqual(model2['path'], sub_dir.strip('/'))
146 self.assertEqual(model2['path'], sub_dir.strip('/'))
149
147
150 def test_update_notebook(self):
148 def test_update_notebook(self):
151 with TemporaryDirectory() as td:
149 nm = self.notebook_manager
152 # Test in root directory
153 # Create a notebook
150 # Create a notebook
154 nm = FileNotebookManager(notebook_dir=td)
155 model = nm.create_notebook()
151 model = nm.create_notebook()
156 name = model['name']
152 name = model['name']
157 path = model['path']
153 path = model['path']
@@ -188,10 +184,8 b' class TestNotebookManager(TestCase):'
188 self.assertRaises(HTTPError, nm.get_notebook, name, path)
184 self.assertRaises(HTTPError, nm.get_notebook, name, path)
189
185
190 def test_save_notebook(self):
186 def test_save_notebook(self):
191 with TemporaryDirectory() as td:
187 nm = self.notebook_manager
192 # Test in the root directory
193 # Create a notebook
188 # Create a notebook
194 nm = FileNotebookManager(notebook_dir=td)
195 model = nm.create_notebook()
189 model = nm.create_notebook()
196 name = model['name']
190 name = model['name']
197 path = model['path']
191 path = model['path']
@@ -225,9 +219,9 b' class TestNotebookManager(TestCase):'
225 self.assertEqual(model['path'], sub_dir.strip('/'))
219 self.assertEqual(model['path'], sub_dir.strip('/'))
226
220
227 def test_save_notebook_with_script(self):
221 def test_save_notebook_with_script(self):
228 with TemporaryDirectory() as td:
222 nm = self.notebook_manager
229 # Create a notebook
223 # Create a notebook
230 nm = FileNotebookManager(notebook_dir=td)
224 model = nm.create_notebook()
231 nm.save_script = True
225 nm.save_script = True
232 model = nm.create_notebook()
226 model = nm.create_notebook()
233 name = model['name']
227 name = model['name']
@@ -240,17 +234,13 b' class TestNotebookManager(TestCase):'
240 model = nm.save_notebook(full_model, name, path)
234 model = nm.save_notebook(full_model, name, path)
241
235
242 # Check that the script was created
236 # Check that the script was created
243 py_path = os.path.join(td, os.path.splitext(name)[0]+'.py')
237 py_path = os.path.join(nm.notebook_dir, os.path.splitext(name)[0]+'.py')
244 assert os.path.exists(py_path), py_path
238 assert os.path.exists(py_path), py_path
245
239
246 def test_delete_notebook(self):
240 def test_delete_notebook(self):
247 with TemporaryDirectory() as td:
241 nm = self.notebook_manager
248 # Test in the root directory
249 # Create a notebook
242 # Create a notebook
250 nm = FileNotebookManager(notebook_dir=td)
243 nb, name, path = self.new_notebook()
251 model = nm.create_notebook()
252 name = model['name']
253 path = model['path']
254
244
255 # Delete the notebook
245 # Delete the notebook
256 nm.delete_notebook(name, path)
246 nm.delete_notebook(name, path)
@@ -259,13 +249,10 b' class TestNotebookManager(TestCase):'
259 self.assertRaises(HTTPError, nm.get_notebook, name, path)
249 self.assertRaises(HTTPError, nm.get_notebook, name, path)
260
250
261 def test_copy_notebook(self):
251 def test_copy_notebook(self):
262 with TemporaryDirectory() as td:
252 nm = self.notebook_manager
263 # Test in the root directory
264 # Create a notebook
265 nm = FileNotebookManager(notebook_dir=td)
266 path = u'Γ₯ b'
253 path = u'Γ₯ b'
267 name = u'nb √.ipynb'
254 name = u'nb √.ipynb'
268 os.mkdir(os.path.join(td, path))
255 os.mkdir(os.path.join(nm.notebook_dir, path))
269 orig = nm.create_notebook({'name' : name}, path=path)
256 orig = nm.create_notebook({'name' : name}, path=path)
270
257
271 # copy with unspecified name
258 # copy with unspecified name
@@ -277,18 +264,20 b' class TestNotebookManager(TestCase):'
277 self.assertEqual(copy2['name'], u'copy 2.ipynb')
264 self.assertEqual(copy2['name'], u'copy 2.ipynb')
278
265
279 def test_trust_notebook(self):
266 def test_trust_notebook(self):
280 nbm = self.nbm
267 nbm = self.notebook_manager
281 nb, name, path = self.new_notebook()
268 nb, name, path = self.new_notebook()
282
269
283 untrusted = nbm.get_notebook(name, path)['content']
270 untrusted = nbm.get_notebook(name, path)['content']
284 assert not nbm.notary.check_signature(untrusted)
271 assert not nbm.notary.check_cells(untrusted)
285
272
273 # print(untrusted)
286 nbm.trust_notebook(name, path)
274 nbm.trust_notebook(name, path)
287 trusted = nbm.get_notebook(name, path)['content']
275 trusted = nbm.get_notebook(name, path)['content']
288 assert nbm.notary.check_signature(trusted)
276 # print(trusted)
277 assert nbm.notary.check_cells(trusted)
289
278
290 def test_mark_trusted_cells(self):
279 def test_mark_trusted_cells(self):
291 nbm = self.nbm
280 nbm = self.notebook_manager
292 nb, name, path = self.new_notebook()
281 nb, name, path = self.new_notebook()
293
282
294 nbm.mark_trusted_cells(nb, name, path)
283 nbm.mark_trusted_cells(nb, name, path)
@@ -298,13 +287,12 b' class TestNotebookManager(TestCase):'
298
287
299 nbm.trust_notebook(name, path)
288 nbm.trust_notebook(name, path)
300 nb = nbm.get_notebook(name, path)['content']
289 nb = nbm.get_notebook(name, path)['content']
301 nbm.mark_trusted_cells(nb, name, path)
302 for cell in nb.worksheets[0].cells:
290 for cell in nb.worksheets[0].cells:
303 if cell.cell_type == 'code':
291 if cell.cell_type == 'code':
304 assert cell.trusted
292 assert cell.trusted
305
293
306 def test_check_and_sign(self):
294 def test_check_and_sign(self):
307 nbm = self.nbm
295 nbm = self.notebook_manager
308 nb, name, path = self.new_notebook()
296 nb, name, path = self.new_notebook()
309
297
310 nbm.mark_trusted_cells(nb, name, path)
298 nbm.mark_trusted_cells(nb, name, path)
General Comments 0
You need to be logged in to leave comments. Login now