# Path: marvin_python_toolbox/management/notebook.py
# def notebook(ctx, port, enable_security, spark_conf, allow_root):
#     notebookdir = os.path.join(ctx.obj['base_path'], 'notebooks')
#     command = [
#         "SPARK_CONF_DIR={0} YARN_CONF_DIR={0}".format(spark_conf if spark_conf else os.path.join(os.environ["SPARK_HOME"], "conf")),
#         'jupyter', 'notebook',
#         '--notebook-dir', notebookdir,
#         '--ip', '0.0.0.0',
#         '--port', str(port),
#         '--no-browser',
#         '--config', os.path.join(os.environ["MARVIN_TOOLBOX_PATH"], 'extras', 'notebook_extensions', 'jupyter_notebook_config.py')
#     ]
# 
#     command.append("--NotebookApp.token=") if not enable_security else None
#     command.append("--allow-root") if allow_root else None
# 
#     ret = os.system(' '.join(command))
#     sys.exit(ret)
# 
# def lab(ctx, port, enable_security, spark_conf):
#     notebookdir = os.path.join(ctx.obj['base_path'], 'notebooks')
#     command = [
#         "SPARK_CONF_DIR={0} YARN_CONF_DIR={0}".format(spark_conf if spark_conf else os.path.join(os.environ["SPARK_HOME"], "conf")),
#         'jupyter-lab',
#         '--notebook-dir', notebookdir,
#         '--ip', '0.0.0.0',
#         '--port', str(port),
#         '--no-browser',
#     ]
# 
#     command.append("--NotebookApp.token=") if not enable_security else None
# 
#     ret = os.system(' '.join(command))
#     sys.exit(ret)


    import mock
    import unittest.mock as mock
import os
from marvin_python_toolbox.management.notebook import notebook, lab

    notebook(ctx, port, enable_security, spark_conf, allow_root)

    system_mocked.assert_called_once_with('SPARK_CONF_DIR=/opt/spark/conf YARN_CONF_DIR=/opt/spark/conf jupyter notebook --notebook-dir /tmp/notebooks --ip 0.0.0.0 --port 8888 --no-browser --config ' + os.environ["MARVIN_ENGINE_PATH"] + '/marvin_python_toolbox/extras/notebook_extensions/jupyter_notebook_config.py --NotebookApp.token=')


@mock.patch('marvin_python_toolbox.management.notebook.sys')
@mock.patch('marvin_python_toolbox.management.notebook.os.system')
def test_notebook_with_security(system_mocked, sys_mocked):
    ctx = mocked_ctx()
    port = 8888
    enable_security = True
    allow_root = False
    spark_conf = '/opt/spark/conf'
    system_mocked.return_value = 1

    notebook(ctx, port, enable_security, spark_conf, allow_root)

    system_mocked.assert_called_once_with('SPARK_CONF_DIR=/opt/spark/conf YARN_CONF_DIR=/opt/spark/conf jupyter notebook --notebook-dir /tmp/notebooks --ip 0.0.0.0 --port 8888 --no-browser --config ' + os.environ["MARVIN_ENGINE_PATH"] + '/marvin_python_toolbox/extras/notebook_extensions/jupyter_notebook_config.py')


@mock.patch('marvin_python_toolbox.management.notebook.sys')
@mock.patch('marvin_python_toolbox.management.notebook.os.system')
def test_jupyter_lab(system_mocked, sys_mocked):
    ctx = mocked_ctx()
    port = 8888
    enable_security = False
    spark_conf = '/opt/spark/conf'
    system_mocked.return_value = 1


# Path: marvin_python_toolbox/management/notebook.py
# def notebook(ctx, port, enable_security, spark_conf, allow_root):
#     notebookdir = os.path.join(ctx.obj['base_path'], 'notebooks')
#     command = [
#         "SPARK_CONF_DIR={0} YARN_CONF_DIR={0}".format(spark_conf if spark_conf else os.path.join(os.environ["SPARK_HOME"], "conf")),
#         'jupyter', 'notebook',
#         '--notebook-dir', notebookdir,
#         '--ip', '0.0.0.0',
#         '--port', str(port),
#         '--no-browser',
#         '--config', os.path.join(os.environ["MARVIN_TOOLBOX_PATH"], 'extras', 'notebook_extensions', 'jupyter_notebook_config.py')
#     ]
# 
#     command.append("--NotebookApp.token=") if not enable_security else None
#     command.append("--allow-root") if allow_root else None
# 
#     ret = os.system(' '.join(command))
#     sys.exit(ret)
# 
# def lab(ctx, port, enable_security, spark_conf):
#     notebookdir = os.path.join(ctx.obj['base_path'], 'notebooks')
#     command = [
#         "SPARK_CONF_DIR={0} YARN_CONF_DIR={0}".format(spark_conf if spark_conf else os.path.join(os.environ["SPARK_HOME"], "conf")),
#         'jupyter-lab',
#         '--notebook-dir', notebookdir,
#         '--ip', '0.0.0.0',
#         '--port', str(port),
#         '--no-browser',
#     ]
# 
#     command.append("--NotebookApp.token=") if not enable_security else None
# 
#     ret = os.system(' '.join(command))
#     sys.exit(ret)


# Path: tests/management/test_notebook.py
    import mock
    import unittest.mock as mock
import os
from marvin_python_toolbox.management.notebook import notebook, lab


    notebook(ctx, port, enable_security, spark_conf, allow_root)

    system_mocked.assert_called_once_with('SPARK_CONF_DIR=/opt/spark/conf YARN_CONF_DIR=/opt/spark/conf jupyter notebook --notebook-dir /tmp/notebooks --ip 0.0.0.0 --port 8888 --no-browser --config ' + os.environ["MARVIN_ENGINE_PATH"] + '/marvin_python_toolbox/extras/notebook_extensions/jupyter_notebook_config.py --NotebookApp.token=')


@mock.patch('marvin_python_toolbox.management.notebook.sys')
@mock.patch('marvin_python_toolbox.management.notebook.os.system')
def test_notebook_with_security(system_mocked, sys_mocked):
    ctx = mocked_ctx()
    port = 8888
    enable_security = True
    allow_root = False
    spark_conf = '/opt/spark/conf'
    system_mocked.return_value = 1

    notebook(ctx, port, enable_security, spark_conf, allow_root)

    system_mocked.assert_called_once_with('SPARK_CONF_DIR=/opt/spark/conf YARN_CONF_DIR=/opt/spark/conf jupyter notebook --notebook-dir /tmp/notebooks --ip 0.0.0.0 --port 8888 --no-browser --config ' + os.environ["MARVIN_ENGINE_PATH"] + '/marvin_python_toolbox/extras/notebook_extensions/jupyter_notebook_config.py')


@mock.patch('marvin_python_toolbox.management.notebook.sys')
@mock.patch('marvin_python_toolbox.management.notebook.os.system')
def test_jupyter_lab(system_mocked, sys_mocked):
    ctx = mocked_ctx()
    port = 8888
    enable_security = False
    spark_conf = '/opt/spark/conf'
    system_mocked.return_value = 1


    lab(ctx, port, enable_security, spark_conf)