-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a51368
commit 01ce6c1
Showing
11 changed files
with
201 additions
and
69 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from pathlib import Path | ||
import sys | ||
|
||
import pytest | ||
from traitlets.config import Config | ||
|
||
from tljh_repo2docker import tljh_custom_jupyterhub_config | ||
|
||
ROOT = Path(__file__).parents[3] | ||
|
||
binderhub_service_name = "binder" | ||
binderhub_config = ROOT / "ui-tests" / "binderhub_config.py" | ||
tljh_repo2docker_config = ROOT / "ui-tests" / "tljh_repo2docker_binderhub.py" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def generated_image_name(): | ||
return "plasmabio-tljh-repo2docker-test-binder:HEAD" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def image_name(): | ||
return "tljh-repo2docker-test:HEAD" | ||
|
||
|
||
@pytest.fixture | ||
async def app(hub_app): | ||
config = Config() | ||
tljh_custom_jupyterhub_config(config) | ||
|
||
config.JupyterHub.services.extend( | ||
[ | ||
{ | ||
"name": binderhub_service_name, | ||
"admin": True, | ||
"command": [ | ||
sys.executable, | ||
"-m", | ||
"binderhub", | ||
f"--config={binderhub_config}", | ||
], | ||
"url": "http://localhost:8585", | ||
"oauth_client_id": "service-binderhub", | ||
"oauth_no_confirm": True, | ||
}, | ||
{ | ||
"name": "tljh_repo2docker", | ||
"url": "http://127.0.0.1:6789", | ||
"command": [ | ||
sys.executable, | ||
"-m", | ||
"tljh_repo2docker", | ||
"--ip", | ||
"127.0.0.1", | ||
"--port", | ||
"6789", | ||
"--config", | ||
f"{tljh_repo2docker_config}", | ||
], | ||
"oauth_no_confirm": True, | ||
}, | ||
] | ||
) | ||
|
||
config.JupyterHub.load_roles = [ | ||
{ | ||
"description": "Role for tljh_repo2docker service", | ||
"name": "tljh-repo2docker-service", | ||
"scopes": [ | ||
"read:users", | ||
"read:roles:users", | ||
"admin:servers", | ||
"access:services!service=binder", | ||
], | ||
"services": ["tljh_repo2docker"], | ||
} | ||
] | ||
|
||
app = await hub_app(config=config) | ||
return app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import pytest | ||
from jupyterhub.tests.utils import get_page | ||
|
||
from ..utils import add_environment, get_service_page, wait_for_image | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_images_list_admin(app): | ||
cookies = await app.login_user("admin") | ||
r = await get_service_page( | ||
"environments", | ||
app, | ||
cookies=cookies, | ||
allow_redirects=True, | ||
) | ||
r.raise_for_status() | ||
assert ( | ||
'{"repo_providers": [{"label": "Git", "value": "git"}], "use_binderhub": true, "images": [], "default_mem_limit": "None", "default_cpu_limit":"None", "machine_profiles": [{"cpu": 2, "label": "Small", "memory": 2}, {"cpu": 4, "label": "Medium", "memory": 4}, {"cpu": 8, "label": "Large", "memory": 8}]}' | ||
in r.text | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_images_list_not_admin(app): | ||
cookies = await app.login_user("wash") | ||
r = await get_service_page( | ||
"environments", app, cookies=cookies, allow_redirects=True | ||
) | ||
assert r.status_code == 403 | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_spawn_page(app, minimal_repo, image_name): | ||
cookies = await app.login_user("admin") | ||
|
||
# go to the spawn page | ||
r = await get_page("spawn", app, cookies=cookies, allow_redirects=False) | ||
r.raise_for_status() | ||
assert minimal_repo not in r.text | ||
|
||
# add a new envionment | ||
name, ref = image_name.split(":") | ||
r = await add_environment(app, repo=minimal_repo, name=name, ref=ref) | ||
assert r.status_code == 200 | ||
await wait_for_image(image_name=image_name) | ||
|
||
# the environment should be on the page | ||
r = await get_page("spawn", app, cookies=cookies, allow_redirects=False) | ||
r.raise_for_status() | ||
assert r.status_code == 200 | ||
assert minimal_repo in r.text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,19 @@ | ||
import sys | ||
|
||
import pytest | ||
from aiodocker import Docker, DockerError | ||
from traitlets.config import Config | ||
|
||
from tljh_repo2docker import tljh_custom_jupyterhub_config | ||
|
||
|
||
async def remove_docker_image(image_name): | ||
async with Docker() as docker: | ||
try: | ||
await docker.images.delete(image_name, force=True) | ||
except DockerError: | ||
pass | ||
|
||
from .utils import remove_docker_image | ||
|
||
@pytest.fixture(scope="module") | ||
@pytest.fixture(scope="session") | ||
def minimal_repo(): | ||
return "https://github.com/plasmabio/tljh-repo2docker-test-binder" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
@pytest.fixture(scope="session") | ||
def minimal_repo_uppercase(): | ||
return "https://github.com/plasmabio/TLJH-REPO2DOCKER-TEST-BINDER" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def generated_image_name(): | ||
return "plasmabio-tljh-repo2docker-test-binder:HEAD" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def image_name(): | ||
return "tljh-repo2docker-test:HEAD" | ||
|
||
|
||
@pytest.fixture | ||
async def app(hub_app): | ||
config = Config() | ||
tljh_custom_jupyterhub_config(config) | ||
|
||
config.JupyterHub.services.extend( | ||
[ | ||
{ | ||
"name": "tljh_repo2docker", | ||
"url": "http://127.0.0.1:6789", | ||
"command": [ | ||
sys.executable, | ||
"-m", | ||
"tljh_repo2docker", | ||
"--ip", | ||
"127.0.0.1", | ||
"--port", | ||
"6789", | ||
], | ||
"oauth_no_confirm": True, | ||
} | ||
] | ||
) | ||
|
||
config.JupyterHub.load_roles = [ | ||
{ | ||
"description": "Role for tljh_repo2docker service", | ||
"name": "tljh-repo2docker-service", | ||
"scopes": ["read:users", "read:roles:users", "admin:servers"], | ||
"services": ["tljh_repo2docker"], | ||
} | ||
] | ||
|
||
app = await hub_app(config=config) | ||
return app | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
async def remove_all_test_images(image_name, generated_image_name, app): | ||
yield | ||
async def remove_all_test_images(image_name, generated_image_name): | ||
|
||
await remove_docker_image(image_name) | ||
await remove_docker_image(generated_image_name) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import sys | ||
|
||
import pytest | ||
from traitlets.config import Config | ||
|
||
from tljh_repo2docker import tljh_custom_jupyterhub_config | ||
|
||
@pytest.fixture(scope="module") | ||
def generated_image_name(): | ||
return "plasmabio-tljh-repo2docker-test-binder:HEAD" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def image_name(): | ||
return "tljh-repo2docker-test:HEAD" | ||
|
||
|
||
@pytest.fixture | ||
async def app(hub_app): | ||
config = Config() | ||
tljh_custom_jupyterhub_config(config) | ||
|
||
config.JupyterHub.services.extend( | ||
[ | ||
{ | ||
"name": "tljh_repo2docker", | ||
"url": "http://127.0.0.1:6789", | ||
"command": [ | ||
sys.executable, | ||
"-m", | ||
"tljh_repo2docker", | ||
"--ip", | ||
"127.0.0.1", | ||
"--port", | ||
"6789", | ||
], | ||
"oauth_no_confirm": True, | ||
} | ||
] | ||
) | ||
|
||
config.JupyterHub.load_roles = [ | ||
{ | ||
"description": "Role for tljh_repo2docker service", | ||
"name": "tljh-repo2docker-service", | ||
"scopes": ["read:users", "read:roles:users", "admin:servers"], | ||
"services": ["tljh_repo2docker"], | ||
} | ||
] | ||
|
||
app = await hub_app(config=config) | ||
return app | ||
|
2 changes: 1 addition & 1 deletion
2
tljh_repo2docker/tests/test_builder.py → ...2docker/tests/local_build/test_builder.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tljh_repo2docker/tests/test_images.py → ...o2docker/tests/local_build/test_images.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters