Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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')
Ejemplo n.º 4
0
    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')
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    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')
Ejemplo n.º 7
0
    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')
Ejemplo n.º 8
0
 def test_from_file_404(self):
     with assert_http_error(404):
         self.nbconvert_api.from_file('html', 'foo',
                                      'thisdoesntexist.ipynb')
Ejemplo n.º 9
0
 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')
Ejemplo n.º 10
0
 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')
Ejemplo n.º 11
0
 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')
Ejemplo n.º 12
0
 def test_list_nonexistant_dir(self):
     with assert_http_error(404):
         self.api.list('nonexistant')
Ejemplo n.º 13
0
    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')
Ejemplo n.º 14
0
 def test_get_nonexistant_kernelspec(self):
     with assert_http_error(404):
         self.ks_api.kernel_spec_info('nonexistant')
Ejemplo n.º 15
0
 def test_list_nonexistant_dir(self):
     with assert_http_error(404):
         self.api.list('nonexistant')
Ejemplo n.º 16
0
 def test_mkdir_hidden_400(self):
     with assert_http_error(400):
         resp = self.api.mkdir(u'å b/.hidden')
Ejemplo n.º 17
0
 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')
Ejemplo n.º 18
0
 def test_delete_non_empty_dir(self):
     """delete non-empty dir raises 400"""
     with assert_http_error(400):
         self.api.delete(u'å b')
Ejemplo n.º 19
0
    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')
Ejemplo n.º 20
0
 def test_rename_existing(self):
     with assert_http_error(409):
         self.api.rename('foo/a.ipynb', 'foo/b.ipynb')
Ejemplo n.º 21
0
 def test_delete_non_empty_dir(self):
     """delete non-empty dir raises 400"""
     with assert_http_error(400):
         self.api.delete(u'å b')
Ejemplo n.º 22
0
 def test_copy_dir_400(self):
     # can't copy directories
     with assert_http_error(400):
         resp = self.api.copy(u'å b', u'foo')
Ejemplo n.º 23
0
 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')
Ejemplo n.º 24
0
 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')
Ejemplo n.º 26
0
 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')
Ejemplo n.º 28
0
 def test_rename_existing(self):
     with assert_http_error(409):
         self.api.rename('foo/a.ipynb', 'foo/b.ipynb')
Ejemplo n.º 29
0
 def test_from_file_404(self):
     with assert_http_error(404):
         self.nbconvert_api.from_file('html', 'foo', 'thisdoesntexist.ipynb')