__init__.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (c) Jupyter Development Team.
  2. # Distributed under the terms of the Modified BSD License.
  3. import getpass
  4. import os
  5. from pathlib import Path
  6. from tempfile import NamedTemporaryFile, mkdtemp
  7. def configure_jupyter_server(c):
  8. """Helper to configure the Jupyter Server for integration testing
  9. with Galata.
  10. By default the tests will be executed in the OS temporary folder. You
  11. can override that folder by setting the environment variable ``JUPYTERLAB_GALATA_ROOT_DIR``.
  12. .. warning::
  13. Never use this configuration in production as it will remove all security protections.
  14. """
  15. # Test if we are running in a docker
  16. if getpass.getuser() == "jovyan":
  17. c.ServerApp.ip = "0.0.0.0" # noqa S104
  18. c.ServerApp.port = 8888
  19. c.ServerApp.port_retries = 0
  20. c.ServerApp.open_browser = False
  21. # Add test helpers extension shipped with JupyterLab.
  22. # You can replace the following line by the two following one
  23. # import jupyterlab
  24. # c.LabServerApp.extra_labextensions_path = str(Path(jupyterlab.__file__).parent / "galata")
  25. c.LabServerApp.extra_labextensions_path = str(Path(__file__).parent)
  26. c.LabApp.workspaces_dir = mkdtemp(prefix="galata-workspaces-")
  27. with NamedTemporaryFile(mode="w", delete=False) as tmp:
  28. tmp.write('PS1="$ "\n')
  29. rcfile_path = tmp.name
  30. c.ServerApp.terminado_settings = {"shell_command": ["/bin/bash", "--rcfile", rcfile_path]}
  31. c.ServerApp.root_dir = os.environ.get(
  32. "JUPYTERLAB_GALATA_ROOT_DIR", mkdtemp(prefix="galata-test-")
  33. )
  34. c.IdentityProvider.token = ""
  35. c.ServerApp.password = ""
  36. c.ServerApp.disable_check_xsrf = True
  37. c.LabApp.expose_app_in_browser = True