-
Notifications
You must be signed in to change notification settings - Fork 362
/
Copy pathtest_simplest_plugin.py
86 lines (65 loc) · 2.44 KB
/
test_simplest_plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""
Test the plugin in integration-tests/plugins/simplest that makes use of all tljh
recognized plugin hooks that are defined in tljh/hooks.py.
"""
import os
import subprocess
from ruamel.yaml import YAML
from tljh import user
from tljh.config import CONFIG_FILE, HUB_ENV_PREFIX, USER_ENV_PREFIX
GIT_REPO_PATH = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
yaml = YAML(typ="rt")
def test_tljh_extra_user_conda_packages():
subprocess.check_call([f"{USER_ENV_PREFIX}/bin/python3", "-c", "import tqdm"])
def test_tljh_extra_user_pip_packages():
subprocess.check_call([f"{USER_ENV_PREFIX}/bin/python3", "-c", "import django"])
def test_tljh_extra_hub_pip_packages():
subprocess.check_call([f"{HUB_ENV_PREFIX}/bin/python3", "-c", "import there"])
def test_tljh_extra_apt_packages():
assert os.path.exists("/usr/games/sl")
def test_tljh_custom_jupyterhub_config():
"""
Test that the provided tljh_custom_jupyterhub_config hook has made the tljh
jupyterhub load additional jupyterhub config.
"""
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():
"""
Test that the provided tljh_config_post_install hook has made tljh recognize
additional tljh config.
"""
with open(CONFIG_FILE) as f:
tljh_config = yaml.load(f)
assert tljh_config["Test"]["tljh_config_set_by_simplest_plugin"]
def test_tljh_post_install():
"""
Test that the provided tljh_post_install hook has been executed by looking
for a specific file written.
"""
with open("test_tljh_post_install") as f:
content = f.read()
assert "file_written_by_simplest_plugin" in content
def test_tljh_new_user_create():
"""
Test that the provided tljh_new_user_create hook has been executed by
looking for a specific file written.
"""
# Trigger the hook by letting tljh's code create a user
username = "user1"
user.ensure_user(username)
with open("test_new_user_create") as f:
content = f.read()
assert "file_written_by_simplest_plugin" in content
assert username in content