예제 #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)
예제 #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)
예제 #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')
예제 #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')
예제 #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')
예제 #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')
예제 #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')
예제 #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)
예제 #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)
예제 #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')
예제 #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')
예제 #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')
예제 #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
예제 #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
예제 #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)
예제 #17
0
 def test_list_nonexistant_dir(self):
     with assert_http_error(404):
         self.api.list('nonexistant')
예제 #18
0
 def test_get_bad(self):
     with assert_http_error(404):
         self.settings_api.get('foo')
예제 #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')
예제 #20
0
 def test_rename_existing(self):
     with assert_http_error(409):
         self.api.rename('foo/a.ipynb', 'foo/b.ipynb')
예제 #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')
예제 #22
0
 def test_mkdir_hidden_400(self):
     with assert_http_error(400):
         resp = self.api.mkdir(u'å b/.hidden')
예제 #23
0
 def build_thread():
     with assert_http_error(500):
         self.build_api.build()
예제 #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)
예제 #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')
예제 #29
0
 def build_thread():
     with assert_http_error(500):
         self.build_api.build()
예제 #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')
예제 #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')
예제 #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')
예제 #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')
예제 #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')
예제 #36
0
 def test_get_nonexistant_kernelspec(self):
     with assert_http_error(404):
         self.ks_api.kernel_spec_info('nonexistant')
예제 #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')
예제 #38
0
 def test_put_wrong_id(self):
     with assert_http_error(404):
         self.settings_api.put('foo', dict())
예제 #39
0
 def test_list_nonexistant_dir(self):
     with assert_http_error(404):
         self.api.list('nonexistant')
예제 #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')
예제 #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')
예제 #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')
예제 #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')
예제 #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)
예제 #45
0
 def test_get_nonexistant_kernelspec(self):
     with assert_http_error(404):
         self.ks_api.kernel_spec_info('nonexistant')
예제 #46
0
 def test_mkdir_hidden_400(self):
     with assert_http_error(400):
         resp = self.api.mkdir(u'å b/.hidden')
예제 #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')
예제 #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')
예제 #49
0
 def test_from_file_404(self):
     with assert_http_error(404):
         self.nbconvert_api.from_file('html', 'foo',
                                      'thisdoesntexist.ipynb')
예제 #50
0
 def test_rename_existing(self):
     with assert_http_error(409):
         self.api.rename('foo/a.ipynb', 'foo/b.ipynb')
예제 #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)