Skip to content

Commit

Permalink
Reactivate unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc committed Apr 15, 2024
1 parent 01ce6c1 commit d600d99
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 40 deletions.
40 changes: 22 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions tljh_repo2docker/base.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"""

Expand Down
11 changes: 8 additions & 3 deletions tljh_repo2docker/tests/binderhub_build/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
import sys
from pathlib import Path

import pytest
from traitlets.config import Config
Expand All @@ -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"
Expand Down Expand Up @@ -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,
},
Expand Down
17 changes: 13 additions & 4 deletions tljh_repo2docker/tests/binderhub_build/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions tljh_repo2docker/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tljh_repo2docker/tests/local_build/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -50,4 +51,3 @@ async def app(hub_app):

app = await hub_app(config=config)
return app

24 changes: 13 additions & 11 deletions tljh_repo2docker/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -106,4 +109,3 @@ async def remove_docker_image(image_name):
await docker.images.delete(image_name, force=True)
except DockerError:
pass

3 changes: 2 additions & 1 deletion ui-tests/binderhub_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d600d99

Please sign in to comment.