exercise password app

This commit is contained in:
Min RK 2017-01-03 15:15:44 +01:00
parent 53f809d407
commit f871d64e6e

View File

@ -1,11 +1,18 @@
"""Test NotebookApp"""
import getpass
import logging
import os
import re
from subprocess import Popen, PIPE, STDOUT
import sys
from tempfile import NamedTemporaryFile
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
@ -14,7 +21,7 @@ from jupyter_core.application import NoStart
from ipython_genutils.tempdir import TemporaryDirectory
from traitlets import TraitError
from notebook import notebookapp, __version__
from notebook import notebookapp
from notebook.auth.security import passwd_check
NotebookApp = notebookapp.NotebookApp
@ -117,3 +124,17 @@ def raise_on_bad_version(version):
def test_current_version():
raise_on_bad_version(__version__)
def test_notebook_password():
password = 'secret'
with TemporaryDirectory() as td:
with patch.dict('os.environ', {
'JUPYTER_CONFIG_DIR': td,
}), patch.object(getpass, 'getpass', return_value=password):
app = notebookapp.NotebookPasswordApp(log_level=logging.ERROR)
app.initialize([])
app.start()
nb = NotebookApp()
nb.load_config_file()
nt.assert_not_equal(nb.password, '')
passwd_check(nb.password, password)