diff --git a/ansible/tljh.yml b/ansible/tljh.yml index 5c46e01..7f2dd2d 100644 --- a/ansible/tljh.yml +++ b/ansible/tljh.yml @@ -26,11 +26,9 @@ - name: Run the TLJH installer shell: | - {{ ansible_python_interpreter }} {{ tljh_installer_dest }} --no-user-env \ + {{ ansible_python_interpreter }} {{ tljh_installer_dest }} \ --plugin {{ tljh_plasma }} {{ tljh_repo2docker }} - # TODO: remove when --no-user-env (or equivalent) is available - environment: - TLJH_BOOTSTRAP_PIP_SPEC: "{{ tljh_bootstrap_pip_spec }}" + --version {{ tljh_version }} - name: Set the idle culler timeout to 1 hour shell: "tljh-config set services.cull.timeout 3600" diff --git a/ansible/vars/default.yml b/ansible/vars/default.yml index 2d992cd..53f48c3 100644 --- a/ansible/vars/default.yml +++ b/ansible/vars/default.yml @@ -4,9 +4,7 @@ tljh_plasma: git+https://github.com/plasmabio/plasma@master#"egg=tljh-plasma&sub tljh_repo2docker: git+https://github.com/plasmabio/tljh-repo2docker@master tljh_installer_dest: /srv/tljh-installer.py tljh_prefix: /opt/tljh -# TODO: update to upstream TLJH links when the --no-user-env (or similar) is available -# See https://github.com/jupyterhub/the-littlest-jupyterhub/pull/528 -tljh_bootstrap_pip_spec: git+https://github.com/jtpio/the-littlest-jupyterhub.git@skip-install#"egg=the_littlest_jupyterhub" -tljh_installer_url: https://raw.githubusercontent.com/jtpio/the-littlest-jupyterhub/skip-install/bootstrap/bootstrap.py +tljh_installer_url: https://tljh.jupyter.org/bootstrap.py +tljh_version: 1.0.0 ... diff --git a/dev-requirements.txt b/dev-requirements.txt index 2e71f20..d595d4a 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,9 +1,10 @@ -git+https://github.com/jupyterhub/the-littlest-jupyterhub -git+https://github.com/plasmabio/tljh-repo2docker -jupyterhub~=1.5 -notebook<7 +git+https://github.com/jupyterhub/the-littlest-jupyterhub@1.0.0 +git+https://github.com/jtpio/tljh-repo2docker@jupyterhub-4 +jupyterhub>=4,<5 +notebook pytest pytest-aiohttp pytest-asyncio pytest-cov +pytest-jupyterhub requests-mock diff --git a/pytest.ini b/pytest.ini index 0ee949b..cc244a3 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,3 @@ [pytest] python_files = test_*.py +asyncio_mode = auto diff --git a/tljh-plasma/tljh_plasma/permissions.py b/tljh-plasma/tljh_plasma/permissions.py index aa79496..5dde581 100644 --- a/tljh-plasma/tljh_plasma/permissions.py +++ b/tljh-plasma/tljh_plasma/permissions.py @@ -7,7 +7,7 @@ from jupyterhub.apihandlers import APIHandler from jupyterhub.handlers.base import BaseHandler from jupyterhub.orm import Base, Column, Integer, Unicode -from jupyterhub.utils import admin_only +from jupyterhub.scopes import needs_scope from tljh_repo2docker.docker import list_images from tornado.web import authenticated @@ -32,7 +32,7 @@ class PermissionsHandler(BaseHandler): """ @authenticated - @admin_only + @needs_scope("admin-ui") async def get(self): include_groups = self.settings.get("include_groups") all_groups = list_groups(include_groups) @@ -60,8 +60,8 @@ class PermissionsAPIHandler(APIHandler): Handle edits to the mapping of environments and groups. """ - @admin_only @authenticated + @needs_scope("admin-ui") async def post(self): raw_args = self.request.body.decode("utf-8") args = json.loads(raw_args) diff --git a/tljh-plasma/tljh_plasma/tests/conftest.py b/tljh-plasma/tljh_plasma/tests/conftest.py index 2f21b20..8b40aa3 100644 --- a/tljh-plasma/tljh_plasma/tests/conftest.py +++ b/tljh-plasma/tljh_plasma/tests/conftest.py @@ -1,59 +1,25 @@ -import asyncio -import sys - import pytest -from jupyterhub.tests.conftest import ( - io_loop, - event_loop, - db, - pytest_collection_modifyitems, -) -from jupyterhub.tests.mocking import MockHub, MockPAMAuthenticator +from jupyterhub.tests.mocking import MockPAMAuthenticator from tljh_repo2docker.tests.conftest import ( - DummyConfig, minimal_repo, image_name, generated_image_name, remove_all_test_images ) -from tljh_repo2docker.tests.utils import add_environment from tljh_repo2docker import tljh_custom_jupyterhub_config as tljh_repo2docker_config from tljh_plasma import tljh_custom_jupyterhub_config as tljh_plasma_config +from traitlets.config import Config -@pytest.fixture(scope="module") -def app(request, io_loop): - """ - Adapted from: - https://github.com/jupyterhub/jupyterhub/blob/8a3790b01ff944c453ffcc0486149e2a58ffabea/jupyterhub/tests/conftest.py#L74 - """ - - # create a JupyterHub mock instance - mocked_app = MockHub.instance() - c = DummyConfig() - c.JupyterHub = mocked_app - - # apply the config from the plugins - tljh_repo2docker_config(c) - tljh_plasma_config(c) - - # switch back to the MockPAMAuthenticator for the tests - c.JupyterHub.authenticator_class = MockPAMAuthenticator +@pytest.fixture +async def app(hub_app): + config = Config() - async def make_app(): - await mocked_app.initialize([]) - await mocked_app.start() + tljh_repo2docker_config(config) + tljh_plasma_config(config) - def fin(): - # disconnect logging during cleanup because pytest closes captured FDs prematurely - mocked_app.log.handlers = [] - MockHub.clear_instance() - try: - mocked_app.stop() - except Exception as e: - print("Error stopping Hub: %s" % e, file=sys.stderr) + config.JupyterHub.authenticator_class = MockPAMAuthenticator - request.addfinalizer(fin) - io_loop.run_sync(make_app) - return mocked_app + app = await hub_app(config=config) + return app \ No newline at end of file