Show More
@@ -247,12 +247,16 b' class APITest(NotebookTestBase):' | |||||
247 | with assert_http_error(404): |
|
247 | with assert_http_error(404): | |
248 | self.api.read('q.txt', 'foo') |
|
248 | self.api.read('q.txt', 'foo') | |
249 |
|
249 | |||
250 |
def _check_ |
|
250 | def _check_created(self, resp, name, path, type='notebook'): | |
251 | self.assertEqual(resp.status_code, 201) |
|
251 | self.assertEqual(resp.status_code, 201) | |
252 | location_header = py3compat.str_to_unicode(resp.headers['Location']) |
|
252 | location_header = py3compat.str_to_unicode(resp.headers['Location']) | |
253 | self.assertEqual(location_header, url_escape(url_path_join(u'/api/contents', path, name))) |
|
253 | self.assertEqual(location_header, url_escape(url_path_join(u'/api/contents', path, name))) | |
254 | self.assertEqual(resp.json()['name'], name) |
|
254 | rjson = resp.json() | |
255 | assert os.path.isfile(pjoin( |
|
255 | self.assertEqual(rjson['name'], name) | |
|
256 | self.assertEqual(rjson['path'], path) | |||
|
257 | self.assertEqual(rjson['type'], type) | |||
|
258 | isright = os.path.isdir if type == 'directory' else os.path.isfile | |||
|
259 | assert isright(pjoin( | |||
256 | self.notebook_dir.name, |
|
260 | self.notebook_dir.name, | |
257 | path.replace('/', os.sep), |
|
261 | path.replace('/', os.sep), | |
258 | name, |
|
262 | name, | |
@@ -260,19 +264,19 b' class APITest(NotebookTestBase):' | |||||
260 |
|
264 | |||
261 | def test_create_untitled(self): |
|
265 | def test_create_untitled(self): | |
262 | resp = self.api.create_untitled(path=u'å b') |
|
266 | resp = self.api.create_untitled(path=u'å b') | |
263 |
self._check_ |
|
267 | self._check_created(resp, 'Untitled0.ipynb', u'å b') | |
264 |
|
268 | |||
265 | # Second time |
|
269 | # Second time | |
266 | resp = self.api.create_untitled(path=u'å b') |
|
270 | resp = self.api.create_untitled(path=u'å b') | |
267 |
self._check_ |
|
271 | self._check_created(resp, 'Untitled1.ipynb', u'å b') | |
268 |
|
272 | |||
269 | # And two directories down |
|
273 | # And two directories down | |
270 | resp = self.api.create_untitled(path='foo/bar') |
|
274 | resp = self.api.create_untitled(path='foo/bar') | |
271 |
self._check_ |
|
275 | self._check_created(resp, 'Untitled0.ipynb', 'foo/bar') | |
272 |
|
276 | |||
273 | def test_create_untitled_txt(self): |
|
277 | def test_create_untitled_txt(self): | |
274 | resp = self.api.create_untitled(path='foo/bar', ext='.txt') |
|
278 | resp = self.api.create_untitled(path='foo/bar', ext='.txt') | |
275 |
self._check_ |
|
279 | self._check_created(resp, 'Untitled0.txt', 'foo/bar', type='file') | |
276 |
|
280 | |||
277 | resp = self.api.read(path='foo/bar', name='Untitled0.txt') |
|
281 | resp = self.api.read(path='foo/bar', name='Untitled0.txt') | |
278 | model = resp.json() |
|
282 | model = resp.json() | |
@@ -285,14 +289,20 b' class APITest(NotebookTestBase):' | |||||
285 | nbmodel = {'content': nb, 'type': 'notebook'} |
|
289 | nbmodel = {'content': nb, 'type': 'notebook'} | |
286 | resp = self.api.upload_untitled(path=u'å b', |
|
290 | resp = self.api.upload_untitled(path=u'å b', | |
287 | body=json.dumps(nbmodel)) |
|
291 | body=json.dumps(nbmodel)) | |
288 |
self._check_ |
|
292 | self._check_created(resp, 'Untitled0.ipynb', u'å b') | |
289 |
|
293 | |||
290 | def test_upload(self): |
|
294 | def test_upload(self): | |
291 | nb = new_notebook(name=u'ignored') |
|
295 | nb = new_notebook(name=u'ignored') | |
292 | nbmodel = {'content': nb, 'type': 'notebook'} |
|
296 | nbmodel = {'content': nb, 'type': 'notebook'} | |
293 | resp = self.api.upload(u'Upload tést.ipynb', path=u'å b', |
|
297 | resp = self.api.upload(u'Upload tést.ipynb', path=u'å b', | |
294 | body=json.dumps(nbmodel)) |
|
298 | body=json.dumps(nbmodel)) | |
295 |
self._check_ |
|
299 | self._check_created(resp, u'Upload tést.ipynb', u'å b') | |
|
300 | ||||
|
301 | def test_mkdir(self): | |||
|
302 | model = {'type': 'directory'} | |||
|
303 | resp = self.api.upload(u'New ∂ir', path=u'å b', | |||
|
304 | body=json.dumps(model)) | |||
|
305 | self._check_created(resp, u'New ∂ir', u'å b', type='directory') | |||
296 |
|
306 | |||
297 | def test_upload_txt(self): |
|
307 | def test_upload_txt(self): | |
298 | body = u'ünicode téxt' |
|
308 | body = u'ünicode téxt' | |
@@ -338,7 +348,7 b' class APITest(NotebookTestBase):' | |||||
338 | nbmodel = {'content': nb, 'type': 'notebook'} |
|
348 | nbmodel = {'content': nb, 'type': 'notebook'} | |
339 | resp = self.api.upload(u'Upload tést.ipynb', path=u'å b', |
|
349 | resp = self.api.upload(u'Upload tést.ipynb', path=u'å b', | |
340 | body=json.dumps(nbmodel)) |
|
350 | body=json.dumps(nbmodel)) | |
341 |
self._check_ |
|
351 | self._check_created(resp, u'Upload tést.ipynb', u'å b') | |
342 | resp = self.api.read(u'Upload tést.ipynb', u'å b') |
|
352 | resp = self.api.read(u'Upload tést.ipynb', u'å b') | |
343 | data = resp.json() |
|
353 | data = resp.json() | |
344 | self.assertEqual(data['content']['nbformat'], current.nbformat) |
|
354 | self.assertEqual(data['content']['nbformat'], current.nbformat) | |
@@ -346,11 +356,11 b' class APITest(NotebookTestBase):' | |||||
346 |
|
356 | |||
347 | def test_copy_untitled(self): |
|
357 | def test_copy_untitled(self): | |
348 | resp = self.api.copy_untitled(u'ç d.ipynb', path=u'å b') |
|
358 | resp = self.api.copy_untitled(u'ç d.ipynb', path=u'å b') | |
349 |
self._check_ |
|
359 | self._check_created(resp, u'ç d-Copy0.ipynb', u'å b') | |
350 |
|
360 | |||
351 | def test_copy(self): |
|
361 | def test_copy(self): | |
352 | resp = self.api.copy(u'ç d.ipynb', u'cøpy.ipynb', path=u'å b') |
|
362 | resp = self.api.copy(u'ç d.ipynb', u'cøpy.ipynb', path=u'å b') | |
353 |
self._check_ |
|
363 | self._check_created(resp, u'cøpy.ipynb', u'å b') | |
354 |
|
364 | |||
355 | def test_delete(self): |
|
365 | def test_delete(self): | |
356 | for d, name in self.dirs_nbs: |
|
366 | for d, name in self.dirs_nbs: |
General Comments 0
You need to be logged in to leave comments.
Login now