##// END OF EJS Templates
use from_dict for dict->notebook...
MinRK -
Show More
@@ -13,7 +13,7 b' from ..base.handlers import ('
13 IPythonHandler, FilesRedirectHandler,
13 IPythonHandler, FilesRedirectHandler,
14 notebook_path_regex, path_regex,
14 notebook_path_regex, path_regex,
15 )
15 )
16 from IPython.nbformat.current import to_notebook_json
16 from IPython.nbformat.current import from_dict
17
17
18 from IPython.utils.py3compat import cast_bytes
18 from IPython.utils.py3compat import cast_bytes
19
19
@@ -115,7 +115,7 b' class NbconvertPostHandler(IPythonHandler):'
115
115
116 model = self.get_json_body()
116 model = self.get_json_body()
117 name = model.get('name', 'notebook.ipynb')
117 name = model.get('name', 'notebook.ipynb')
118 nbnode = to_notebook_json(model['content'])
118 nbnode = from_dict(model['content'])
119
119
120 try:
120 try:
121 output, resources = exporter.from_notebook_node(nbnode)
121 output, resources = exporter.from_notebook_node(nbnode)
@@ -295,7 +295,7 b' class FileContentsManager(ContentsManager):'
295 def _save_notebook(self, os_path, model, name='', path=''):
295 def _save_notebook(self, os_path, model, name='', path=''):
296 """save a notebook file"""
296 """save a notebook file"""
297 # Save the notebook file
297 # Save the notebook file
298 nb = current.to_notebook_json(model['content'])
298 nb = current.from_dict(model['content'])
299
299
300 self.check_and_sign(nb, name, path)
300 self.check_and_sign(nb, name, path)
301
301
@@ -16,7 +16,7 b' from IPython.html.utils import url_path_join, url_escape'
16 from IPython.html.tests.launchnotebook import NotebookTestBase, assert_http_error
16 from IPython.html.tests.launchnotebook import NotebookTestBase, assert_http_error
17 from IPython.nbformat import current
17 from IPython.nbformat import current
18 from IPython.nbformat.current import (new_notebook, write, read,
18 from IPython.nbformat.current import (new_notebook, write, read,
19 new_markdown_cell, to_notebook_json)
19 new_markdown_cell, from_dict)
20 from IPython.nbformat import v2
20 from IPython.nbformat import v2
21 from IPython.utils import py3compat
21 from IPython.utils import py3compat
22 from IPython.utils.data import uniq_stable
22 from IPython.utils.data import uniq_stable
@@ -414,7 +414,7 b' class APITest(NotebookTestBase):'
414 def test_save(self):
414 def test_save(self):
415 resp = self.api.read('a.ipynb', 'foo')
415 resp = self.api.read('a.ipynb', 'foo')
416 nbcontent = json.loads(resp.text)['content']
416 nbcontent = json.loads(resp.text)['content']
417 nb = to_notebook_json(nbcontent)
417 nb = from_dict(nbcontent)
418 nb.cells.append(new_markdown_cell(u'Created by test ³'))
418 nb.cells.append(new_markdown_cell(u'Created by test ³'))
419
419
420 nbmodel= {'name': 'a.ipynb', 'path':'foo', 'content': nb, 'type': 'notebook'}
420 nbmodel= {'name': 'a.ipynb', 'path':'foo', 'content': nb, 'type': 'notebook'}
@@ -426,7 +426,7 b' class APITest(NotebookTestBase):'
426 self.assertEqual(newnb.cells[0].source,
426 self.assertEqual(newnb.cells[0].source,
427 u'Created by test ³')
427 u'Created by test ³')
428 nbcontent = self.api.read('a.ipynb', 'foo').json()['content']
428 nbcontent = self.api.read('a.ipynb', 'foo').json()['content']
429 newnb = to_notebook_json(nbcontent)
429 newnb = from_dict(nbcontent)
430 self.assertEqual(newnb.cells[0].source,
430 self.assertEqual(newnb.cells[0].source,
431 u'Created by test ³')
431 u'Created by test ³')
432
432
@@ -451,7 +451,7 b' class APITest(NotebookTestBase):'
451
451
452 # Modify it
452 # Modify it
453 nbcontent = json.loads(resp.text)['content']
453 nbcontent = json.loads(resp.text)['content']
454 nb = to_notebook_json(nbcontent)
454 nb = from_dict(nbcontent)
455 hcell = new_markdown_cell('Created by test')
455 hcell = new_markdown_cell('Created by test')
456 nb.cells.append(hcell)
456 nb.cells.append(hcell)
457 # Save
457 # Save
@@ -463,14 +463,14 b' class APITest(NotebookTestBase):'
463 self.assertEqual(cps, [cp1])
463 self.assertEqual(cps, [cp1])
464
464
465 nbcontent = self.api.read('a.ipynb', 'foo').json()['content']
465 nbcontent = self.api.read('a.ipynb', 'foo').json()['content']
466 nb = to_notebook_json(nbcontent)
466 nb = from_dict(nbcontent)
467 self.assertEqual(nb.cells[0].source, 'Created by test')
467 self.assertEqual(nb.cells[0].source, 'Created by test')
468
468
469 # Restore cp1
469 # Restore cp1
470 r = self.api.restore_checkpoint('a.ipynb', 'foo', cp1['id'])
470 r = self.api.restore_checkpoint('a.ipynb', 'foo', cp1['id'])
471 self.assertEqual(r.status_code, 204)
471 self.assertEqual(r.status_code, 204)
472 nbcontent = self.api.read('a.ipynb', 'foo').json()['content']
472 nbcontent = self.api.read('a.ipynb', 'foo').json()['content']
473 nb = to_notebook_json(nbcontent)
473 nb = from_dict(nbcontent)
474 self.assertEqual(nb.cells, [])
474 self.assertEqual(nb.cells, [])
475
475
476 # Delete cp1
476 # Delete cp1
General Comments 0
You need to be logged in to leave comments. Login now