Ejemplo n.º 1
0
    def test_terminal_handler(self):
        # GET terminal with given name
        term = self.term_api.start().json()['name']
        r = self.term_api.get(term)
        term1 = r.json()
        self.assertEqual(r.status_code, 200)
        assert isinstance(term1, dict)
        self.assertIn('name', term1)
        self.assertEqual(term1['name'], term)

        # Request a bad terminal id and check that a JSON
        # message is returned!
        bad_term = 'nonExistentTerm'
        with assert_http_error(404, 'Terminal not found: ' + bad_term):
            self.term_api.get(bad_term)

        # DELETE terminal with name
        r = self.term_api.shutdown(term)
        self.assertEqual(r.status_code, 204)
        terminals = self.term_api.list().json()
        self.assertEqual(terminals, [])

        # Request to delete a non-existent terminal name
        bad_term = 'nonExistentTerm'
        with assert_http_error(404, 'Terminal not found: ' + bad_term):
            self.term_api.shutdown(bad_term)
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_bad_put(self):
        orig = 'foo'
        copy = 'bar'
        data = self.workspaces_api.get(orig).json()

        with assert_http_error(400):
            self.workspaces_api.put(copy, data)
    def test_create_terminal_with_name(self):
        # Test creation of terminal via GET against terminals/new/<name>
        r = self.term_api._req('GET', 'terminals/new/foo')
        self.assertEqual(r.status_code, 200)

        r = self.term_api.get('foo')
        foo_term = r.json()
        self.assertEqual(r.status_code, 200)
        self.assertIsInstance(foo_term, dict)
        self.assertEqual(foo_term['name'], 'foo')

        # hit the same endpoint a second time and ensure 302 with Location is returned
        r = self.term_api._req('GET', 'terminals/new/foo')
        # Access the "interesting" response from the history
        self.assertEqual(len(r.history), 1)
        r = r.history[0]
        foo_term = r.json()
        self.assertEqual(r.status_code, 302)
        self.assertEqual(r.headers['Location'],
                         self.url_prefix + "terminals/foo")
        self.assertIsInstance(foo_term, dict)
        self.assertEqual(foo_term['name'], 'foo')

        r = self.term_api.shutdown('foo')
        self.assertEqual(r.status_code, 204)

        # Make sure there are no terminals are running
        terminals = self.term_api.list().json()
        self.assertEqual(len(terminals), 0)

        # hit terminals/new/new and ensure that 400 is raised
        with assert_http_error(400):
            self.term_api._req('GET', 'terminals/new/new')
Ejemplo n.º 5
0
 def test_delete_non_empty_dir(self):
     if sys.platform == 'win32':
         self.skipTest("Disabled deleting non-empty dirs on Windows")
     # Test that non empty directory can be deleted
     self.api.delete(u'å b')
     # Check if directory has actually been deleted
     with assert_http_error(404):
         self.api.list(u'å b')
Ejemplo n.º 6
0
 def test_delete_non_empty_dir(self):
     if sys.platform == 'win32':
         self.skipTest("Disabled deleting non-empty dirs on Windows")
     # Test that non empty directory can be deleted
     self.api.delete(u'å b')
     # Check if directory has actually been deleted
     with assert_http_error(404):
         self.api.list(u'å b')
Ejemplo n.º 7
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.º 8
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.º 9
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.º 10
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.º 11
0
 def test_delete_non_empty_dir(self):
     if sys.platform == 'win32':
         self.skipTest("Disabled deleting non-empty dirs on Windows")
     # Test that non empty directory can be deleted
     try:
         self.api.delete(u'å b')
     except requests.HTTPError as e:
         if e.response.status_code == 400:
             if not self.can_send2trash(u'å b'):
                 self.skipTest("Dir can't be sent to trash")
         raise
     # Check if directory has actually been deleted
     with assert_http_error(404):
         self.api.list(u'å b')
Ejemplo n.º 12
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(
                decodebytes(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.º 13
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(
                decodebytes(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.º 14
0
    def test_clear(self):
        with assert_http_error(500):
            self.build_api.clear()

        def build_thread():
            with assert_http_error(500):
                self.build_api.build()

        t1 = threading.Thread(target=build_thread)
        t1.start()

        while 1:
            resp = self.build_api.getStatus().json()
            if resp['status'] == 'building':
                break

        resp = self.build_api.clear()
        assert resp.status_code == 204
Ejemplo n.º 15
0
    def test_clear(self):
        with assert_http_error(500):
            self.build_api.clear()

        def build_thread():
            with assert_http_error(500):
                self.build_api.build()

        t1 = threading.Thread(target=build_thread)
        t1.start()

        while 1:
            resp = self.build_api.getStatus().json()
            if resp['status'] == 'building':
                break

        resp = self.build_api.clear()
        assert resp.status_code == 204
Ejemplo n.º 16
0
 def test_patch_bad_data(self):
     id = 'jupyter.services.codemirror-commands'
     data = dict(keyMap=10)
     with assert_http_error(400):
         self.settings_api.patch(id, data)
Ejemplo n.º 17
0
 def test_list_nonexistant_dir(self):
     with assert_http_error(404):
         self.api.list('nonexistant')
Ejemplo n.º 18
0
 def test_get_bad(self):
     with assert_http_error(404):
         self.settings_api.get('foo')
Ejemplo n.º 19
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.º 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_copy_dir_400(self):
     # can't copy directories
     with assert_http_error(400):
         resp = self.api.copy(u'å b', u'foo')
Ejemplo n.º 22
0
 def test_mkdir_hidden_400(self):
     with assert_http_error(400):
         resp = self.api.mkdir(u'å b/.hidden')
Ejemplo n.º 23
0
 def build_thread():
     with assert_http_error(500):
         self.build_api.build()
Ejemplo n.º 24
0
def _test_delete_non_empty_dir_pass(self, path):
    # Test that non empty directory can be deleted
    self.api.delete(path)
    # Check if directory has actually been deleted
    with assert_http_error(404):
        self.api.list(path)
Ejemplo n.º 25
0
def _test_delete_non_empty_dir_fail(self, path):
    with assert_http_error(400):
        self.api.delete(path)
 def test_patch_bad_data(self):
     id = 'jupyter.services.codemirror-commands'
     data = dict(keyMap=10)
     with assert_http_error(400):
         self.settings_api.patch(id, data)
 def test_patch_wrong_id(self):
     with assert_http_error(404):
         self.settings_api.patch('foo', dict())
 def test_get_bad(self):
     with assert_http_error(404):
         self.settings_api.get('foo')
Ejemplo n.º 29
0
 def build_thread():
     with assert_http_error(500):
         self.build_api.build()
Ejemplo n.º 30
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')
 def test_from_file_404(self):
     with assert_http_error(404):
         self.nbconvert_api.from_file('html', 'foo', 'thisdoesntexist.ipynb')
Ejemplo n.º 32
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.º 33
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.º 34
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.º 35
0
 def test_delete_non_empty_dir(self):
     # Test that non empty directory can be deleted
     self.api.delete(u'å b')
     # Check if directory has actually been deleted
     with assert_http_error(404):
         self.api.list(u'å b')
Ejemplo n.º 36
0
 def test_get_nonexistant_kernelspec(self):
     with assert_http_error(404):
         self.ks_api.kernel_spec_info('nonexistant')
Ejemplo n.º 37
0
 def test_delete_non_empty_dir(self):
     # Test that non empty directory can be deleted
     self.api.delete(u'å b')
     # Check if directory has actually been deleted
     with assert_http_error(404):
         self.api.list(u'å b')
Ejemplo n.º 38
0
 def test_put_wrong_id(self):
     with assert_http_error(404):
         self.settings_api.put('foo', dict())
Ejemplo n.º 39
0
 def test_list_nonexistant_dir(self):
     with assert_http_error(404):
         self.api.list('nonexistant')
Ejemplo n.º 40
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.º 41
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.º 42
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.º 43
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.º 44
0
 def test_put_bad_data(self):
     id = '@jupyterlab/codemirror-extension:commands'
     data = dict(keyMap=10)
     with assert_http_error(400):
         self.settings_api.put(id, data)
Ejemplo n.º 45
0
 def test_get_nonexistant_kernelspec(self):
     with assert_http_error(404):
         self.ks_api.kernel_spec_info('nonexistant')
Ejemplo n.º 46
0
 def test_mkdir_hidden_400(self):
     with assert_http_error(400):
         resp = self.api.mkdir(u'å b/.hidden')
Ejemplo n.º 47
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.º 48
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.º 49
0
 def test_from_file_404(self):
     with assert_http_error(404):
         self.nbconvert_api.from_file('html', 'foo',
                                      'thisdoesntexist.ipynb')
Ejemplo n.º 50
0
 def test_rename_existing(self):
     with assert_http_error(409):
         self.api.rename('foo/a.ipynb', 'foo/b.ipynb')
Ejemplo n.º 51
0
 def test_blank_put(self):
     orig = 'foo'
     data = self.workspaces_api.get(orig).json()
     with assert_http_error(400):
         self.workspaces_api.put('', data)