diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8c700f3..7c9d266 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -76,24 +76,28 @@ jobs: - name: Checkout uses: actions/checkout@v3 - # - name: Base Setup - # uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 - - # - name: Download app package - # uses: actions/download-artifact@v3 - # with: - # name: tljh_repo2docker-artifacts - - # - name: Install package - # run: | - # set -eux - # python -m pip install -r dev-requirements.txt - # python -m pip install tljh_repo2docker*.whl - # npm -g install configurable-http-proxy - - # - name: Run Tests - # run: | - # python -m pytest --cov + - name: Base Setup + uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 + + - name: Download app package + uses: actions/download-artifact@v3 + with: + name: tljh_repo2docker-artifacts + + - name: Install package + run: | + set -eux + python -m pip install -r dev-requirements.txt + python -m pip install tljh_repo2docker*.whl + npm -g install configurable-http-proxy + + - name: Run local build backend tests + run: | + python -m pytest tljh_repo2docker/tests/local_build --cov + + - name: Run binfderhub build backend tests + run: | + python -m pytest tljh_repo2docker/tests/binderhub_build --cov integration-tests: name: Integration tests diff --git a/tljh_repo2docker/base.py b/tljh_repo2docker/base.py index e825cf9..c800531 100644 --- a/tljh_repo2docker/base.py +++ b/tljh_repo2docker/base.py @@ -1,9 +1,9 @@ import functools import json import os +import sys from contextlib import _AsyncGeneratorContextManager from http.client import responses -import sys from typing import Any, Callable, Dict, List, Optional, Tuple from httpx import AsyncClient @@ -19,10 +19,13 @@ from .model import UserModel if sys.version_info >= (3, 9): - AsyncSessionContextFactory = Callable[[], _AsyncGeneratorContextManager[AsyncSession]] + AsyncSessionContextFactory = Callable[ + [], _AsyncGeneratorContextManager[AsyncSession] + ] else: AsyncSessionContextFactory = Any + def require_admin_role(func): """decorator to require admin role to perform an action""" diff --git a/tljh_repo2docker/tests/binderhub_build/conftest.py b/tljh_repo2docker/tests/binderhub_build/conftest.py index 10b0d0d..a04736c 100644 --- a/tljh_repo2docker/tests/binderhub_build/conftest.py +++ b/tljh_repo2docker/tests/binderhub_build/conftest.py @@ -1,5 +1,5 @@ -from pathlib import Path import sys +from pathlib import Path import pytest from traitlets.config import Config @@ -18,6 +18,11 @@ def generated_image_name(): return "plasmabio-tljh-repo2docker-test-binder:HEAD" +@pytest.fixture(scope="module") +def docker_image_name(): + return "https-3a-2f-2fgithub-2ecom-2fplasmabio-2ftljh-2drepo2docker-2dtest-2dbinder-3f035a:06bb545ab3a2888477cbddfed0ea77eae313cfed" + + @pytest.fixture(scope="module") def image_name(): return "tljh-repo2docker-test:HEAD" @@ -54,8 +59,8 @@ async def app(hub_app): "127.0.0.1", "--port", "6789", - "--config", - f"{tljh_repo2docker_config}", + "--binderhub_url", + "http://localhost:8585/@/space%20word/services/binder/", ], "oauth_no_confirm": True, }, diff --git a/tljh_repo2docker/tests/binderhub_build/test_images.py b/tljh_repo2docker/tests/binderhub_build/test_images.py index db7bcd4..7adffda 100644 --- a/tljh_repo2docker/tests/binderhub_build/test_images.py +++ b/tljh_repo2docker/tests/binderhub_build/test_images.py @@ -30,7 +30,7 @@ async def test_images_list_not_admin(app): @pytest.mark.asyncio -async def test_spawn_page(app, minimal_repo, image_name): +async def test_spawn_page(app, minimal_repo, image_name, docker_image_name): cookies = await app.login_user("admin") # go to the spawn page @@ -40,12 +40,21 @@ async def test_spawn_page(app, minimal_repo, image_name): # add a new envionment name, ref = image_name.split(":") - r = await add_environment(app, repo=minimal_repo, name=name, ref=ref) + r = await add_environment( + app, repo=minimal_repo, name=name, ref=ref, provider="git" + ) assert r.status_code == 200 - await wait_for_image(image_name=image_name) + await wait_for_image(image_name=docker_image_name) # the environment should be on the page - r = await get_page("spawn", app, cookies=cookies, allow_redirects=False) + r = await get_page( + "services/tljh_repo2docker/environments", + app, + cookies=cookies, + allow_redirects=True, + hub=False, + ) r.raise_for_status() + assert r.status_code == 200 assert minimal_repo in r.text diff --git a/tljh_repo2docker/tests/conftest.py b/tljh_repo2docker/tests/conftest.py index e272088..a77917d 100644 --- a/tljh_repo2docker/tests/conftest.py +++ b/tljh_repo2docker/tests/conftest.py @@ -2,6 +2,7 @@ from .utils import remove_docker_image + @pytest.fixture(scope="session") def minimal_repo(): return "https://github.com/plasmabio/tljh-repo2docker-test-binder" diff --git a/tljh_repo2docker/tests/local_build/conftest.py b/tljh_repo2docker/tests/local_build/conftest.py index fa1609a..bcc7069 100644 --- a/tljh_repo2docker/tests/local_build/conftest.py +++ b/tljh_repo2docker/tests/local_build/conftest.py @@ -5,6 +5,7 @@ from tljh_repo2docker import tljh_custom_jupyterhub_config + @pytest.fixture(scope="module") def generated_image_name(): return "plasmabio-tljh-repo2docker-test-binder:HEAD" @@ -50,4 +51,3 @@ async def app(hub_app): app = await hub_app(config=config) return app - diff --git a/tljh_repo2docker/tests/utils.py b/tljh_repo2docker/tests/utils.py index 3707a48..2ab70b5 100644 --- a/tljh_repo2docker/tests/utils.py +++ b/tljh_repo2docker/tests/utils.py @@ -49,21 +49,24 @@ def get_service_page(path, app, **kw): return async_requests.get(url, **kw) -async def add_environment(app, *, repo, ref="HEAD", name="", memory="", cpu=""): +async def add_environment( + app, *, repo, ref="HEAD", name="", memory="", cpu="", provider=None +): """Use the POST endpoint to add a new environment""" + data = { + "repo": repo, + "ref": ref, + "name": name, + "memory": memory, + "cpu": cpu, + } + if provider: + data["provider"] = provider r = await api_request( app, "environments", method="post", - data=json.dumps( - { - "repo": repo, - "ref": ref, - "name": name, - "memory": memory, - "cpu": cpu, - } - ), + data=json.dumps(data), ) return r @@ -106,4 +109,3 @@ async def remove_docker_image(image_name): await docker.images.delete(image_name, force=True) except DockerError: pass - diff --git a/ui-tests/binderhub_config.py b/ui-tests/binderhub_config.py index 95d1226..febcd0d 100644 --- a/ui-tests/binderhub_config.py +++ b/ui-tests/binderhub_config.py @@ -20,8 +20,9 @@ c.BinderHub.enable_api_only_mode = True use_registry = bool(os.getenv("BINDERHUB_USE_REGISTRY", False)) +c.BinderHub.use_registry = use_registry + if use_registry: - c.BinderHub.use_registry = use_registry c.BinderHub.image_prefix = os.getenv( "BINDERHUB_IMAGE_PREFIX", "" ) # https://binderhub.readthedocs.io/en/latest/zero-to-binderhub/setup-binderhub.html#id2