##// END OF EJS Templates
url encode/decode tests added to nbmanager
Zachary Sailer -
Show More
@@ -86,11 +86,11 b' class FileNotebookManager(NotebookManager):'
86 86 def list_notebooks(self, path):
87 87 """List all notebooks in the notebook dir."""
88 88 notebook_names = self.get_notebook_names(path)
89 notebook_mapping = []
89 notebooks = []
90 90 for name in notebook_names:
91 91 model = self.notebook_model(name, path, content=False)
92 notebook_mapping.append(model)
93 return notebook_mapping
92 notebooks.append(model)
93 return notebooks
94 94
95 95 def change_notebook(self, data, notebook_name, notebook_path=None):
96 96 """Changes notebook"""
@@ -73,11 +73,13 b' class NotebookManager(LoggingConfigurable):'
73 73 return name, path
74 74
75 75 def url_encode(self, path):
76 parts = path.split('/')
76 parts = os.path.split(path)
77 #parts = path.split('/')
77 78 return os.path.join(*[quote(p) for p in parts])
78 79
79 80 def url_decode(self, path):
80 parts = path.split('/')
81 parts = os.path.split(path)
82 #parts = path.split('/')
81 83 return os.path.join(*[unquote(p) for p in parts])
82 84
83 85 def _notebook_dir_changed(self, new):
@@ -127,11 +129,6 b' class NotebookManager(LoggingConfigurable):'
127 129 """
128 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 132 def notebook_model(self, notebook_name, notebook_path=None, content=True):
136 133 """ Creates the standard notebook model """
137 134 last_modified, contents = self.read_notebook_object(notebook_name, notebook_path)
@@ -35,12 +35,12 b' class TestFileNotebookManager(TestCase):'
35 35 class TestNotebookManager(TestCase):
36 36 def test_named_notebook_path(self):
37 37 nm = NotebookManager()
38
38
39 39 # doesn't end with ipynb, should just be path
40 40 name, path = nm.named_notebook_path('hello')
41 41 self.assertEqual(name, None)
42 42 self.assertEqual(path, '/hello/')
43
43
44 44 name, path = nm.named_notebook_path('/')
45 45 self.assertEqual(name, None)
46 46 self.assertEqual(path, '/')
@@ -48,17 +48,43 b' class TestNotebookManager(TestCase):'
48 48 name, path = nm.named_notebook_path('hello.ipynb')
49 49 self.assertEqual(name, 'hello.ipynb')
50 50 self.assertEqual(path, '/')
51
51
52 52 name, path = nm.named_notebook_path('/hello.ipynb')
53 53 self.assertEqual(name, 'hello.ipynb')
54 54 self.assertEqual(path, '/')
55
55
56 56 name, path = nm.named_notebook_path('/this/is/a/path/hello.ipynb')
57 57 self.assertEqual(name, 'hello.ipynb')
58 58 self.assertEqual(path, '/this/is/a/path/')
59
59
60 60 name, path = nm.named_notebook_path('path/without/leading/slash/hello.ipynb')
61 61 self.assertEqual(name, 'hello.ipynb')
62 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