-
Notifications
You must be signed in to change notification settings - Fork 14
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
Showing
5 changed files
with
133 additions
and
23 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import pytest | ||
import requests | ||
|
||
from requests.exceptions import ConnectionError | ||
|
||
|
||
def is_responsive(url): | ||
try: | ||
response = requests.get(url) | ||
if response.status_code == 200: | ||
return True | ||
except ConnectionError: | ||
return False | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def notebook_service(docker_ip, docker_services): | ||
"""Ensure that HTTP service is up and responsive.""" | ||
port = docker_services.port_for("lab", 8888) | ||
url = f"http://{docker_ip}:{port}" | ||
docker_services.wait_until_responsive( | ||
timeout=30.0, pause=0.1, check=lambda: is_responsive(url) | ||
) | ||
return url | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def docker_compose(docker_services): | ||
return docker_services._docker_compose | ||
|
||
|
||
@pytest.fixture | ||
def lab_exec(docker_compose): | ||
def execute(command, user=None, **kwargs): | ||
if user: | ||
command = f"exec -T --user={user} lab {command}" | ||
else: | ||
command = f"exec -T lab {command}" | ||
return docker_compose.execute(command, **kwargs) | ||
|
||
return execute | ||
|
||
|
||
@pytest.fixture | ||
def nb_user(docker_compose): | ||
return ( | ||
docker_compose.execute("exec -T lab bash -c 'echo \"$NB_USER\"'") | ||
.decode() | ||
.strip() | ||
) |
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,46 @@ | ||
--- | ||
version: '3.4' | ||
|
||
services: | ||
|
||
database: | ||
image: postgres:12.3 | ||
#container_name: aiida-database | ||
environment: | ||
POSTGRES_USER: pguser | ||
POSTGRES_PASSWORD: password | ||
volumes: | ||
- aiida-postgres-db:/var/lib/postgresql/data | ||
restart: always | ||
|
||
messaging: | ||
image: rabbitmq:3.8.3-management | ||
#container_name: aiida-rmq | ||
environment: | ||
RABBITMQ_DEFAULT_USER: guest | ||
RABBITMQ_DEFAULT_PASS: guest | ||
volumes: | ||
- aiida-rmq-data:/var/lib/rabbitmq/ | ||
restart: always | ||
|
||
lab: | ||
image: aiidalab-docker-stack:latest | ||
environment: | ||
RMQHOST: messaging | ||
TZ: Europe/Zurich | ||
DOCKER_STACKS_JUPYTER_CMD: notebook | ||
SETUP_DEFAULT_AIIDA_PROFILE: 'true' | ||
AIIDALAB_DEFAULT_APPS: '' | ||
volumes: | ||
- aiidalab-home-folder:/home/jovyan | ||
depends_on: | ||
- database | ||
- messaging | ||
ports: | ||
- 8888:8888 | ||
|
||
|
||
volumes: | ||
aiida-postgres-db: | ||
aiida-rmq-data: | ||
aiidalab-home-folder: |
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,4 @@ | ||
docker-compose==1.29.2 | ||
pytest==7.1.2 | ||
pytest-docker==1.0.0 | ||
requests==2.28.1 |
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,26 @@ | ||
import requests | ||
|
||
|
||
def test_notebook_service_available(notebook_service): | ||
response = requests.get(f"{notebook_service}/") | ||
assert response.status_code == 200 | ||
|
||
|
||
def test_pip_check(lab_exec): | ||
lab_exec("pip check") | ||
|
||
|
||
def test_aiidalab_available(lab_exec, nb_user): | ||
output = lab_exec("aiidalab --version", user=nb_user).decode().strip().lower() | ||
assert "aiidalab" in output | ||
|
||
|
||
def test_create_conda_environment(lab_exec, nb_user): | ||
output = lab_exec("conda create -y -n tmp", user=nb_user).decode().strip() | ||
assert "conda activate tmp" in output | ||
|
||
|
||
def test_verdi_status(lab_exec, nb_user): | ||
output = lab_exec("verdi status", user=nb_user).decode().strip() | ||
assert "Connected to RabbitMQ" in output | ||
assert "Daemon is running" in output |