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