Skip to content

Commit d600d99

Browse files
committed
Reactivate unit tests
1 parent 01ce6c1 commit d600d99

File tree

8 files changed

+65
-40
lines changed

8 files changed

+65
-40
lines changed

.github/workflows/build.yml

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,28 @@ jobs:
7676
- name: Checkout
7777
uses: actions/checkout@v3
7878

79-
# - name: Base Setup
80-
# uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
81-
82-
# - name: Download app package
83-
# uses: actions/download-artifact@v3
84-
# with:
85-
# name: tljh_repo2docker-artifacts
86-
87-
# - name: Install package
88-
# run: |
89-
# set -eux
90-
# python -m pip install -r dev-requirements.txt
91-
# python -m pip install tljh_repo2docker*.whl
92-
# npm -g install configurable-http-proxy
93-
94-
# - name: Run Tests
95-
# run: |
96-
# python -m pytest --cov
79+
- name: Base Setup
80+
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
81+
82+
- name: Download app package
83+
uses: actions/download-artifact@v3
84+
with:
85+
name: tljh_repo2docker-artifacts
86+
87+
- name: Install package
88+
run: |
89+
set -eux
90+
python -m pip install -r dev-requirements.txt
91+
python -m pip install tljh_repo2docker*.whl
92+
npm -g install configurable-http-proxy
93+
94+
- name: Run local build backend tests
95+
run: |
96+
python -m pytest tljh_repo2docker/tests/local_build --cov
97+
98+
- name: Run binfderhub build backend tests
99+
run: |
100+
python -m pytest tljh_repo2docker/tests/binderhub_build --cov
97101
98102
integration-tests:
99103
name: Integration tests

tljh_repo2docker/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import functools
22
import json
33
import os
4+
import sys
45
from contextlib import _AsyncGeneratorContextManager
56
from http.client import responses
6-
import sys
77
from typing import Any, Callable, Dict, List, Optional, Tuple
88

99
from httpx import AsyncClient
@@ -19,10 +19,13 @@
1919
from .model import UserModel
2020

2121
if sys.version_info >= (3, 9):
22-
AsyncSessionContextFactory = Callable[[], _AsyncGeneratorContextManager[AsyncSession]]
22+
AsyncSessionContextFactory = Callable[
23+
[], _AsyncGeneratorContextManager[AsyncSession]
24+
]
2325
else:
2426
AsyncSessionContextFactory = Any
2527

28+
2629
def require_admin_role(func):
2730
"""decorator to require admin role to perform an action"""
2831

tljh_repo2docker/tests/binderhub_build/conftest.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from pathlib import Path
21
import sys
2+
from pathlib import Path
33

44
import pytest
55
from traitlets.config import Config
@@ -18,6 +18,11 @@ def generated_image_name():
1818
return "plasmabio-tljh-repo2docker-test-binder:HEAD"
1919

2020

21+
@pytest.fixture(scope="module")
22+
def docker_image_name():
23+
return "https-3a-2f-2fgithub-2ecom-2fplasmabio-2ftljh-2drepo2docker-2dtest-2dbinder-3f035a:06bb545ab3a2888477cbddfed0ea77eae313cfed"
24+
25+
2126
@pytest.fixture(scope="module")
2227
def image_name():
2328
return "tljh-repo2docker-test:HEAD"
@@ -54,8 +59,8 @@ async def app(hub_app):
5459
"127.0.0.1",
5560
"--port",
5661
"6789",
57-
"--config",
58-
f"{tljh_repo2docker_config}",
62+
"--binderhub_url",
63+
"http://localhost:8585/@/space%20word/services/binder/",
5964
],
6065
"oauth_no_confirm": True,
6166
},

tljh_repo2docker/tests/binderhub_build/test_images.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async def test_images_list_not_admin(app):
3030

3131

3232
@pytest.mark.asyncio
33-
async def test_spawn_page(app, minimal_repo, image_name):
33+
async def test_spawn_page(app, minimal_repo, image_name, docker_image_name):
3434
cookies = await app.login_user("admin")
3535

3636
# go to the spawn page
@@ -40,12 +40,21 @@ async def test_spawn_page(app, minimal_repo, image_name):
4040

4141
# add a new envionment
4242
name, ref = image_name.split(":")
43-
r = await add_environment(app, repo=minimal_repo, name=name, ref=ref)
43+
r = await add_environment(
44+
app, repo=minimal_repo, name=name, ref=ref, provider="git"
45+
)
4446
assert r.status_code == 200
45-
await wait_for_image(image_name=image_name)
47+
await wait_for_image(image_name=docker_image_name)
4648

4749
# the environment should be on the page
48-
r = await get_page("spawn", app, cookies=cookies, allow_redirects=False)
50+
r = await get_page(
51+
"services/tljh_repo2docker/environments",
52+
app,
53+
cookies=cookies,
54+
allow_redirects=True,
55+
hub=False,
56+
)
4957
r.raise_for_status()
58+
5059
assert r.status_code == 200
5160
assert minimal_repo in r.text

tljh_repo2docker/tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from .utils import remove_docker_image
44

5+
56
@pytest.fixture(scope="session")
67
def minimal_repo():
78
return "https://github.com/plasmabio/tljh-repo2docker-test-binder"

tljh_repo2docker/tests/local_build/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from tljh_repo2docker import tljh_custom_jupyterhub_config
77

8+
89
@pytest.fixture(scope="module")
910
def generated_image_name():
1011
return "plasmabio-tljh-repo2docker-test-binder:HEAD"
@@ -50,4 +51,3 @@ async def app(hub_app):
5051

5152
app = await hub_app(config=config)
5253
return app
53-

tljh_repo2docker/tests/utils.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,24 @@ def get_service_page(path, app, **kw):
4949
return async_requests.get(url, **kw)
5050

5151

52-
async def add_environment(app, *, repo, ref="HEAD", name="", memory="", cpu=""):
52+
async def add_environment(
53+
app, *, repo, ref="HEAD", name="", memory="", cpu="", provider=None
54+
):
5355
"""Use the POST endpoint to add a new environment"""
56+
data = {
57+
"repo": repo,
58+
"ref": ref,
59+
"name": name,
60+
"memory": memory,
61+
"cpu": cpu,
62+
}
63+
if provider:
64+
data["provider"] = provider
5465
r = await api_request(
5566
app,
5667
"environments",
5768
method="post",
58-
data=json.dumps(
59-
{
60-
"repo": repo,
61-
"ref": ref,
62-
"name": name,
63-
"memory": memory,
64-
"cpu": cpu,
65-
}
66-
),
69+
data=json.dumps(data),
6770
)
6871
return r
6972

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

ui-tests/binderhub_config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
c.BinderHub.enable_api_only_mode = True
2121

2222
use_registry = bool(os.getenv("BINDERHUB_USE_REGISTRY", False))
23+
c.BinderHub.use_registry = use_registry
24+
2325
if use_registry:
24-
c.BinderHub.use_registry = use_registry
2526
c.BinderHub.image_prefix = os.getenv(
2627
"BINDERHUB_IMAGE_PREFIX", ""
2728
) # https://binderhub.readthedocs.io/en/latest/zero-to-binderhub/setup-binderhub.html#id2

0 commit comments

Comments
 (0)