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