##// END OF EJS Templates
url encode/decode tests added to nbmanager
Zachary Sailer -
Show More
@@ -86,11 +86,11 b' class FileNotebookManager(NotebookManager):'
86 def list_notebooks(self, path):
86 def list_notebooks(self, path):
87 """List all notebooks in the notebook dir."""
87 """List all notebooks in the notebook dir."""
88 notebook_names = self.get_notebook_names(path)
88 notebook_names = self.get_notebook_names(path)
89 notebook_mapping = []
89 notebooks = []
90 for name in notebook_names:
90 for name in notebook_names:
91 model = self.notebook_model(name, path, content=False)
91 model = self.notebook_model(name, path, content=False)
92 notebook_mapping.append(model)
92 notebooks.append(model)
93 return notebook_mapping
93 return notebooks
94
94
95 def change_notebook(self, data, notebook_name, notebook_path=None):
95 def change_notebook(self, data, notebook_name, notebook_path=None):
96 """Changes notebook"""
96 """Changes notebook"""
@@ -73,11 +73,13 b' class NotebookManager(LoggingConfigurable):'
73 return name, path
73 return name, path
74
74
75 def url_encode(self, path):
75 def url_encode(self, path):
76 parts = path.split('/')
76 parts = os.path.split(path)
77 #parts = path.split('/')
77 return os.path.join(*[quote(p) for p in parts])
78 return os.path.join(*[quote(p) for p in parts])
78
79
79 def url_decode(self, path):
80 def url_decode(self, path):
80 parts = path.split('/')
81 parts = os.path.split(path)
82 #parts = path.split('/')
81 return os.path.join(*[unquote(p) for p in parts])
83 return os.path.join(*[unquote(p) for p in parts])
82
84
83 def _notebook_dir_changed(self, new):
85 def _notebook_dir_changed(self, new):
@@ -127,11 +129,6 b' class NotebookManager(LoggingConfigurable):'
127 """
129 """
128 raise NotImplementedError('must be implemented in a subclass')
130 raise NotImplementedError('must be implemented in a subclass')
129
131
130
131 def notebook_exists(self, notebook_path):
132 """Does a notebook exist?"""
133
134
135 def notebook_model(self, notebook_name, notebook_path=None, content=True):
132 def notebook_model(self, notebook_name, notebook_path=None, content=True):
136 """ Creates the standard notebook model """
133 """ Creates the standard notebook model """
137 last_modified, contents = self.read_notebook_object(notebook_name, notebook_path)
134 last_modified, contents = self.read_notebook_object(notebook_name, notebook_path)
@@ -35,12 +35,12 b' class TestFileNotebookManager(TestCase):'
35 class TestNotebookManager(TestCase):
35 class TestNotebookManager(TestCase):
36 def test_named_notebook_path(self):
36 def test_named_notebook_path(self):
37 nm = NotebookManager()
37 nm = NotebookManager()
38
38
39 # doesn't end with ipynb, should just be path
39 # doesn't end with ipynb, should just be path
40 name, path = nm.named_notebook_path('hello')
40 name, path = nm.named_notebook_path('hello')
41 self.assertEqual(name, None)
41 self.assertEqual(name, None)
42 self.assertEqual(path, '/hello/')
42 self.assertEqual(path, '/hello/')
43
43
44 name, path = nm.named_notebook_path('/')
44 name, path = nm.named_notebook_path('/')
45 self.assertEqual(name, None)
45 self.assertEqual(name, None)
46 self.assertEqual(path, '/')
46 self.assertEqual(path, '/')
@@ -48,17 +48,43 b' class TestNotebookManager(TestCase):'
48 name, path = nm.named_notebook_path('hello.ipynb')
48 name, path = nm.named_notebook_path('hello.ipynb')
49 self.assertEqual(name, 'hello.ipynb')
49 self.assertEqual(name, 'hello.ipynb')
50 self.assertEqual(path, '/')
50 self.assertEqual(path, '/')
51
51
52 name, path = nm.named_notebook_path('/hello.ipynb')
52 name, path = nm.named_notebook_path('/hello.ipynb')
53 self.assertEqual(name, 'hello.ipynb')
53 self.assertEqual(name, 'hello.ipynb')
54 self.assertEqual(path, '/')
54 self.assertEqual(path, '/')
55
55
56 name, path = nm.named_notebook_path('/this/is/a/path/hello.ipynb')
56 name, path = nm.named_notebook_path('/this/is/a/path/hello.ipynb')
57 self.assertEqual(name, 'hello.ipynb')
57 self.assertEqual(name, 'hello.ipynb')
58 self.assertEqual(path, '/this/is/a/path/')
58 self.assertEqual(path, '/this/is/a/path/')
59
59
60 name, path = nm.named_notebook_path('path/without/leading/slash/hello.ipynb')
60 name, path = nm.named_notebook_path('path/without/leading/slash/hello.ipynb')
61 self.assertEqual(name, 'hello.ipynb')
61 self.assertEqual(name, 'hello.ipynb')
62 self.assertEqual(path, '/path/without/leading/slash/')
62 self.assertEqual(path, '/path/without/leading/slash/')
63
63
64 def test_url_encode(self):
65 nm = NotebookManager()
66
67 # changes path or notebook name with special characters to url encoding
68 # these tests specifically encode paths with spaces
69 path = nm.url_encode('/this is a test/for spaces/')
70 self.assertEqual(path, '/this%20is%20a%20test/for%20spaces/')
71
72 path = nm.url_encode('notebook with space.ipynb')
73 self.assertEqual(path, 'notebook%20with%20space.ipynb')
74
75 path = nm.url_encode('/path with a/notebook and space.ipynb')
76 self.assertEqual(path, '/path%20with%20a/notebook%20and%20space.ipynb')
64
77
78 def test_url_decode(self):
79 nm = NotebookManager()
80
81 # decodes a url string to a plain string
82 # these tests decode paths with spaces
83 path = nm.url_decode('/this%20is%20a%20test/for%20spaces/')
84 self.assertEqual(path, '/this is a test/for spaces/')
85
86 path = nm.url_decode('notebook%20with%20space.ipynb')
87 self.assertEqual(path, 'notebook with space.ipynb')
88
89 path = nm.url_decode('/path%20with%20a/notebook%20and%20space.ipynb')
90 self.assertEqual(path, '/path with a/notebook and space.ipynb')
General Comments 0
You need to be logged in to leave comments. Login now