Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_install_symlink(self):
with TemporaryDirectory() as d:
f = u'ƒ.js'
src = pjoin(d, f)
touch(src)
install_nbextension(src, symlink=True)
dest = pjoin(self.system_nbext, f)
assert os.path.islink(dest)
link = os.readlink(dest)
self.assertEqual(link, src)
def test_quiet(self):
stdout = StringIO()
stderr = StringIO()
with patch.object(sys, 'stdout', stdout), \
patch.object(sys, 'stderr', stderr):
install_nbextension(self.src)
self.assertEqual(stdout.getvalue(), '')
self.assertEqual(stderr.getvalue(), '')
def test_create_nbextensions_system(self):
with TemporaryDirectory() as td:
self.system_nbext = pjoin(td, u'nbextensions')
with patch.object(nbextensions, 'SYSTEM_JUPYTER_PATH', [td]):
install_nbextension(self.src, user=False)
self.assert_installed(
pjoin(basename(self.src), u'ƒile'),
user=False
)
def test_overwrite_file(self):
with TemporaryDirectory() as d:
fname = u'ƒ.js'
src = pjoin(d, fname)
with open(src, 'w') as f:
f.write('first')
mtime = touch(src)
dest = pjoin(self.system_nbext, fname)
install_nbextension(src)
with open(src, 'w') as f:
f.write('overwrite')
mtime = touch(src, mtime - 100)
install_nbextension(src, overwrite=True)
with open(dest) as f:
self.assertEqual(f.read(), 'overwrite')
def test_single_dir_trailing_slash(self):
d = u'∂ir/'
install_nbextension(pjoin(self.src, d))
self.assert_installed(self.files[-1])
if os.name == 'nt':
d = u'∂ir\\'
install_nbextension(pjoin(self.src, d))
self.assert_installed(self.files[-1])
],
"type": "query-hive",
"id": null,
"snippets": [{"id": "e069ef32-5c95-4507-b961-e79c090b5abf","type":"hive","status":"ready","database":"default","statement":"select * from web_logs","statement_raw":"select * from web_logs","variables":[],"properties":{"settings":[],"files":[],"functions":[]},"result":{}}],
"uuid": "8a20da5f-b69c-4843-b17d-dea5c74c41d1"
}
"""
# Assert that the notebook is first saved
response = self.client.post(reverse('notebook:save_notebook'), {'notebook': trash_notebook_json})
data = json.loads(response.content)
assert_equal(0, data['status'], data)
# Test that deleting it moves it to the user's Trash folder
notebook_doc = Document2.objects.get(id=data['id'])
trash_notebooks = [Notebook(notebook_doc).get_data()]
response = self.client.post(reverse('notebook:delete'), {'notebooks': json.dumps(trash_notebooks)})
data = json.loads(response.content)
assert_equal(0, data['status'], data)
assert_equal('Trashed 1 notebook(s)', data['message'], data)
response = self.client.get('/desktop/api2/doc', {'path': '/.Trash'})
data = json.loads(response.content)
trash_uuids = [doc['uuid'] for doc in data['children']]
assert_true(notebook_doc.uuid in trash_uuids, data)
# Test that any errors are reported in the response
nonexistant_doc = {
"id": 12345,
"uuid": "ea22da5f-b69c-4843-b17d-dea5c74c41d1",
"selectedSnippet": "hive",
"showHistory": False,
def get_config_manager(cls):
try:
# single-user notebook server tests use cls.notebook for app
return cls.notebook.config_manager
except AttributeError:
# jupyterhub-based tests don't (can't) have cls.notebook defined,
# so we must construct a ConfigManager from scratch
return ConfigManager(
log=cls.log,
config_dir=os.path.join(_get_config_dir(user=True), 'nbconfig')
)
def get_servers():
return list(notebookapp.list_running_servers(nbapp.runtime_dir))
nbapp.initialize(argv=[])
def test_url_escape():
# changes path or notebook name with special characters to url encoding
# these tests specifically encode paths with spaces
path = url_escape('/this is a test/for spaces/')
nt.assert_equal(path, '/this%20is%20a%20test/for%20spaces/')
path = url_escape('notebook with space.ipynb')
nt.assert_equal(path, 'notebook%20with%20space.ipynb')
path = url_escape('/path with a/notebook and space.ipynb')
nt.assert_equal(path, '/path%20with%20a/notebook%20and%20space.ipynb')
path = url_escape('/ !@$#%^&* / test %^ notebook @#$ name.ipynb')
nt.assert_equal(path,
'/%20%21%40%24%23%25%5E%26%2A%20/%20test%20%25%5E%20notebook%20%40%23%24%20name.ipynb')
try:
from unittest.mock import patch
except ImportError:
from mock import patch # py2
import nose.tools as nt
from traitlets.tests.utils import check_help_all_output
from jupyter_core.application import NoStart
from ipython_genutils.tempdir import TemporaryDirectory
from traitlets import TraitError
from notebook import notebookapp, __version__
from notebook.auth.security import passwd_check
NotebookApp = notebookapp.NotebookApp
def test_help_output():
"""ipython notebook --help-all works"""
check_help_all_output('notebook')
def test_server_info_file():
td = TemporaryDirectory()
nbapp = NotebookApp(runtime_dir=td.name, log=logging.getLogger())
def get_servers():
return list(notebookapp.list_running_servers(nbapp.runtime_dir))
nbapp.initialize(argv=[])
nbapp.write_server_info_file()
servers = get_servers()
nt.assert_equal(len(servers), 1)
nt.assert_equal(servers[0]['port'], nbapp.port)