def test_kernel_handler(self): # GET kernel with given id kid = self.kern_api.start().json()['id'] r = self.kern_api.get(kid) kern1 = r.json() self.assertEqual(r.status_code, 200) assert isinstance(kern1, dict) self.assertIn('id', kern1) self.assertEqual(kern1['id'], kid) # Request a bad kernel id and check that a JSON # message is returned! bad_id = '111-111-111-111-111' with assert_http_error(404, 'Kernel does not exist: ' + bad_id): self.kern_api.get(bad_id) # DELETE kernel with id r = self.kern_api.shutdown(kid) self.assertEqual(r.status_code, 204) kernels = self.kern_api.list().json() self.assertEqual(kernels, []) # Request to delete a non-existent kernel id bad_id = '111-111-111-111-111' with assert_http_error(404, 'Kernel does not exist: ' + bad_id): self.kern_api.shutdown(bad_id)
def test_kernel_handler(self): # GET kernel with given id kid = self.kern_api.start().json()['id'] r = self.kern_api.get(kid) kern1 = r.json() self.assertEqual(r.status_code, 200) assert isinstance(kern1, dict) self.assertIn('id', kern1) self.assertEqual(kern1['id'], kid) # Request a bad kernel id and check that a JSON # message is returned! bad_id = '111-111-111-111-111' with assert_http_error(404, 'Kernel does not exist: ' + bad_id): self.kern_api.get(bad_id) # DELETE kernel with id r = self.kern_api.shutdown(kid) self.assertEqual(r.status_code, 204) kernels = self.kern_api.list().json() self.assertEqual(kernels, []) # Request to delete a non-existent kernel id bad_id = '111-111-111-111-111' with assert_http_error(404, 'Kernel does not exist: ' + bad_id): self.kern_api.shutdown(bad_id)
def test_get_text_file_contents(self): for d, name in self.dirs_nbs: path = url_path_join(d, name + '.txt') model = self.api.read(path).json() self.assertEqual(model['name'], u'%s.txt' % name) self.assertEqual(model['path'], path) self.assertIn('content', model) self.assertEqual(model['format'], 'text') self.assertEqual(model['type'], 'file') self.assertEqual(model['content'], self._txt_for_name(name)) # Name that doesn't exist - should be a 404 with assert_http_error(404): self.api.read('foo/q.txt') # Specifying format=text should fail on a non-UTF-8 file with assert_http_error(400): self.api.read('foo/bar/baz.blob', type='file', format='text')
def test_get_text_file_contents(self): for d, name in self.dirs_nbs: path = url_path_join(d, name + '.txt') model = self.api.read(path).json() self.assertEqual(model['name'], u'%s.txt' % name) self.assertEqual(model['path'], path) self.assertIn('content', model) self.assertEqual(model['format'], 'text') self.assertEqual(model['type'], 'file') self.assertEqual(model['content'], self._txt_for_name(name)) # Name that doesn't exist - should be a 404 with assert_http_error(404): self.api.read('foo/q.txt') # Specifying format=text should fail on a non-UTF-8 file with assert_http_error(400): self.api.read('foo/bar/baz.blob', type='file', format='text')
def test_delete(self): newsession = self.sess_api.create('foo/nb1.ipynb').json() sid = newsession['id'] resp = self.sess_api.delete(sid) self.assertEqual(resp.status_code, 204) sessions = self.sess_api.list().json() self.assertEqual(sessions, []) with assert_http_error(404): self.sess_api.get(sid)
def test_get_binary_file_contents(self): for d, name in self.dirs_nbs: path = url_path_join(d, name + '.blob') model = self.api.read(path).json() self.assertEqual(model['name'], u'%s.blob' % name) self.assertEqual(model['path'], path) self.assertIn('content', model) self.assertEqual(model['format'], 'base64') self.assertEqual(model['type'], 'file') self.assertEqual( base64.decodestring(model['content'].encode('ascii')), self._blob_for_name(name), ) # Name that doesn't exist - should be a 404 with assert_http_error(404): self.api.read('foo/q.txt')
def test_get_binary_file_contents(self): for d, name in self.dirs_nbs: path = url_path_join(d, name + '.blob') model = self.api.read(path).json() self.assertEqual(model['name'], u'%s.blob' % name) self.assertEqual(model['path'], path) self.assertIn('content', model) self.assertEqual(model['format'], 'base64') self.assertEqual(model['type'], 'file') self.assertEqual( base64.decodestring(model['content'].encode('ascii')), self._blob_for_name(name), ) # Name that doesn't exist - should be a 404 with assert_http_error(404): self.api.read('foo/q.txt')
def test_from_file_404(self): with assert_http_error(404): self.nbconvert_api.from_file('html', 'foo', 'thisdoesntexist.ipynb')
def test_get_contents_no_such_file(self): # Name that doesn't exist - should be a 404 with assert_http_error(404): self.api.read('foo/q.ipynb')
def test_get_contents_no_such_file(self): # Name that doesn't exist - should be a 404 with assert_http_error(404): self.api.read('foo/q.ipynb')
def test_get_nonexistant_resource(self): with assert_http_error(404): self.ks_api.kernel_resource('nonexistant', 'resource.txt') with assert_http_error(404): self.ks_api.kernel_resource('sample', 'nonexistant.txt')
def test_list_nonexistant_dir(self): with assert_http_error(404): self.api.list('nonexistant')
def test_get_bad_type(self): with assert_http_error(400): self.api.read(u'unicodé', type='file') # this is a directory with assert_http_error(400): self.api.read(u'unicodé/innonascii.ipynb', type='directory')
def test_get_nonexistant_kernelspec(self): with assert_http_error(404): self.ks_api.kernel_spec_info('nonexistant')
def test_list_nonexistant_dir(self): with assert_http_error(404): self.api.list('nonexistant')
def test_mkdir_hidden_400(self): with assert_http_error(400): resp = self.api.mkdir(u'å b/.hidden')
def test_copy_put_400(self): with assert_http_error(400): resp = self.api.copy_put(u'å b/ç d.ipynb', u'å b/cøpy.ipynb')
def test_delete_non_empty_dir(self): """delete non-empty dir raises 400""" with assert_http_error(400): self.api.delete(u'å b')
def test_get_bad_type(self): with assert_http_error(400): self.api.read(u'unicodé', type='file') # this is a directory with assert_http_error(400): self.api.read(u'unicodé/innonascii.ipynb', type='directory')
def test_rename_existing(self): with assert_http_error(409): self.api.rename('foo/a.ipynb', 'foo/b.ipynb')
def test_delete_non_empty_dir(self): """delete non-empty dir raises 400""" with assert_http_error(400): self.api.delete(u'å b')
def test_copy_dir_400(self): # can't copy directories with assert_http_error(400): resp = self.api.copy(u'å b', u'foo')
def test_copy_put_400(self): with assert_http_error(400): resp = self.api.copy_put(u'å b/ç d.ipynb', u'å b/cøpy.ipynb')
def test_mkdir_hidden_400(self): with assert_http_error(400): resp = self.api.mkdir(u'å b/.hidden')
def test_get_nonexistant_kernelspec(self): with assert_http_error(404): self.ks_api.kernel_spec_info('nonexistant')
def test_copy_dir_400(self): # can't copy directories with assert_http_error(400): resp = self.api.copy(u'å b', u'foo')
def test_get_nonexistant_resource(self): with assert_http_error(404): self.ks_api.kernel_resource('nonexistant', 'resource.txt') with assert_http_error(404): self.ks_api.kernel_resource('sample', 'nonexistant.txt')
def test_rename_existing(self): with assert_http_error(409): self.api.rename('foo/a.ipynb', 'foo/b.ipynb')
def test_from_file_404(self): with assert_http_error(404): self.nbconvert_api.from_file('html', 'foo', 'thisdoesntexist.ipynb')