2018-08-12 09:47:32 -07:00
|
|
|
"""
|
2023-06-08 22:44:21 +02:00
|
|
|
Test the plugin in integration-tests/plugins/simplest that makes use of all tljh
|
|
|
|
|
recognized plugin hooks that are defined in tljh/hooks.py.
|
2018-08-12 09:47:32 -07:00
|
|
|
"""
|
|
|
|
|
import os
|
|
|
|
|
import subprocess
|
2020-01-13 18:38:47 +02:00
|
|
|
|
2023-05-15 08:51:35 +00:00
|
|
|
from ruamel.yaml import YAML
|
|
|
|
|
|
2020-01-13 18:38:47 +02:00
|
|
|
from tljh import user
|
2023-05-15 08:51:35 +00:00
|
|
|
from tljh.config import CONFIG_FILE, HUB_ENV_PREFIX, USER_ENV_PREFIX
|
2018-08-12 09:47:32 -07:00
|
|
|
|
2023-06-08 22:44:21 +02:00
|
|
|
GIT_REPO_PATH = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
2021-11-03 23:55:34 +01:00
|
|
|
yaml = YAML(typ="rt")
|
2018-08-12 09:47:32 -07:00
|
|
|
|
|
|
|
|
|
2023-06-08 22:44:21 +02:00
|
|
|
def test_tljh_extra_user_conda_packages():
|
|
|
|
|
subprocess.check_call([f"{USER_ENV_PREFIX}/bin/python3", "-c", "import tqdm"])
|
2018-08-12 09:47:32 -07:00
|
|
|
|
|
|
|
|
|
2023-06-08 22:44:21 +02:00
|
|
|
def test_tljh_extra_user_pip_packages():
|
2021-11-03 23:55:34 +01:00
|
|
|
subprocess.check_call([f"{USER_ENV_PREFIX}/bin/python3", "-c", "import django"])
|
2018-08-12 09:47:32 -07:00
|
|
|
|
2023-06-08 22:44:21 +02:00
|
|
|
|
|
|
|
|
def test_tljh_extra_hub_pip_packages():
|
2021-11-03 23:55:34 +01:00
|
|
|
subprocess.check_call([f"{HUB_ENV_PREFIX}/bin/python3", "-c", "import there"])
|
2019-05-31 16:52:51 -07:00
|
|
|
|
2018-08-12 09:47:32 -07:00
|
|
|
|
2023-06-08 22:44:21 +02:00
|
|
|
def test_tljh_extra_apt_packages():
|
|
|
|
|
assert os.path.exists("/usr/games/sl")
|
2018-08-12 09:47:32 -07:00
|
|
|
|
|
|
|
|
|
2023-06-08 22:44:21 +02:00
|
|
|
def test_tljh_custom_jupyterhub_config():
|
2018-08-12 09:47:32 -07:00
|
|
|
"""
|
2023-06-08 22:44:21 +02:00
|
|
|
Test that the provided tljh_custom_jupyterhub_config hook has made the tljh
|
|
|
|
|
jupyterhub load additional jupyterhub config.
|
2018-08-12 09:47:32 -07:00
|
|
|
"""
|
2023-06-08 22:44:21 +02:00
|
|
|
tljh_jupyterhub_config = os.path.join(GIT_REPO_PATH, "tljh", "jupyterhub_config.py")
|
|
|
|
|
output = subprocess.check_output(
|
|
|
|
|
[
|
|
|
|
|
f"{HUB_ENV_PREFIX}/bin/python3",
|
|
|
|
|
"-m",
|
|
|
|
|
"jupyterhub",
|
|
|
|
|
"--show-config",
|
|
|
|
|
"--config",
|
|
|
|
|
tljh_jupyterhub_config,
|
|
|
|
|
],
|
|
|
|
|
text=True,
|
|
|
|
|
)
|
|
|
|
|
assert "jupyterhub_config_set_by_simplest_plugin" in output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_tljh_config_post_install():
|
2019-05-31 23:35:08 -07:00
|
|
|
"""
|
2023-06-08 22:44:21 +02:00
|
|
|
Test that the provided tljh_config_post_install hook has made tljh recognize
|
|
|
|
|
additional tljh config.
|
2019-05-31 23:35:08 -07:00
|
|
|
"""
|
2023-06-08 22:44:21 +02:00
|
|
|
with open(CONFIG_FILE) as f:
|
|
|
|
|
tljh_config = yaml.load(f)
|
|
|
|
|
assert tljh_config["Test"]["tljh_config_set_by_simplest_plugin"]
|
2019-06-27 11:45:36 +02:00
|
|
|
|
|
|
|
|
|
2023-06-08 22:44:21 +02:00
|
|
|
def test_tljh_post_install():
|
2019-06-27 11:45:36 +02:00
|
|
|
"""
|
2023-06-08 22:44:21 +02:00
|
|
|
Test that the provided tljh_post_install hook has been executed by looking
|
|
|
|
|
for a specific file written.
|
2019-06-27 11:45:36 +02:00
|
|
|
"""
|
2023-06-08 22:44:21 +02:00
|
|
|
with open("test_tljh_post_install") as f:
|
2019-07-02 12:53:06 +02:00
|
|
|
content = f.read()
|
2023-06-08 22:44:21 +02:00
|
|
|
assert "file_written_by_simplest_plugin" in content
|
2019-07-02 12:53:06 +02:00
|
|
|
|
2019-12-03 09:43:16 +01:00
|
|
|
|
2023-06-08 22:44:21 +02:00
|
|
|
def test_tljh_new_user_create():
|
2019-12-03 09:43:16 +01:00
|
|
|
"""
|
2023-06-08 22:44:21 +02:00
|
|
|
Test that the provided tljh_new_user_create hook has been executed by
|
|
|
|
|
looking for a specific file written.
|
2019-12-03 09:43:16 +01:00
|
|
|
"""
|
2023-06-08 22:44:21 +02:00
|
|
|
# Trigger the hook by letting tljh's code create a user
|
2021-11-01 09:42:45 +01:00
|
|
|
username = "user1"
|
2020-01-13 18:38:47 +02:00
|
|
|
user.ensure_user(username)
|
|
|
|
|
|
2021-10-28 09:37:50 +02:00
|
|
|
with open("test_new_user_create") as f:
|
2019-12-03 09:43:16 +01:00
|
|
|
content = f.read()
|
2023-06-08 22:44:21 +02:00
|
|
|
assert "file_written_by_simplest_plugin" in content
|
|
|
|
|
assert username in content
|