2018-08-12 09:47:32 -07:00
|
|
|
"""
|
|
|
|
|
Test simplest plugin
|
|
|
|
|
"""
|
|
|
|
|
from ruamel.yaml import YAML
|
2019-05-31 23:35:08 -07:00
|
|
|
import requests
|
2018-08-12 09:47:32 -07:00
|
|
|
import os
|
|
|
|
|
import subprocess
|
2020-01-13 18:38:47 +02:00
|
|
|
|
2019-05-31 16:52:51 -07:00
|
|
|
from tljh.config import CONFIG_FILE, USER_ENV_PREFIX, HUB_ENV_PREFIX
|
2020-01-13 18:38:47 +02:00
|
|
|
from tljh import user
|
2018-08-12 09:47:32 -07:00
|
|
|
|
|
|
|
|
yaml = YAML(typ='rt')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_apt_packages():
|
|
|
|
|
"""
|
|
|
|
|
Test extra apt packages are installed
|
|
|
|
|
"""
|
2018-08-12 09:55:20 -07:00
|
|
|
assert os.path.exists('/usr/games/sl')
|
2018-08-12 09:47:32 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_pip_packages():
|
|
|
|
|
"""
|
2019-05-31 16:52:51 -07:00
|
|
|
Test extra user & hub pip packages are installed
|
2018-08-12 09:47:32 -07:00
|
|
|
"""
|
|
|
|
|
subprocess.check_call([
|
2018-08-31 12:25:30 +02:00
|
|
|
f'{USER_ENV_PREFIX}/bin/python3',
|
2018-08-12 09:47:32 -07:00
|
|
|
'-c',
|
|
|
|
|
'import django'
|
|
|
|
|
])
|
|
|
|
|
|
2019-05-31 16:52:51 -07:00
|
|
|
subprocess.check_call([
|
|
|
|
|
f'{HUB_ENV_PREFIX}/bin/python3',
|
|
|
|
|
'-c',
|
|
|
|
|
'import there'
|
|
|
|
|
])
|
|
|
|
|
|
2018-08-12 09:47:32 -07:00
|
|
|
|
|
|
|
|
def test_conda_packages():
|
|
|
|
|
"""
|
|
|
|
|
Test extra user conda packages are installed
|
|
|
|
|
"""
|
|
|
|
|
subprocess.check_call([
|
2018-08-31 12:25:30 +02:00
|
|
|
f'{USER_ENV_PREFIX}/bin/python3',
|
2018-08-12 09:47:32 -07:00
|
|
|
'-c',
|
|
|
|
|
'import hypothesis'
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_config_hook():
|
|
|
|
|
"""
|
|
|
|
|
Check config changes are present
|
|
|
|
|
"""
|
2018-08-31 12:25:30 +02:00
|
|
|
with open(CONFIG_FILE) as f:
|
2018-08-12 09:47:32 -07:00
|
|
|
data = yaml.load(f)
|
|
|
|
|
|
2018-08-31 12:25:30 +02:00
|
|
|
assert data['simplest_plugin']['present']
|
2019-05-31 23:35:08 -07:00
|
|
|
|
2019-06-27 11:45:36 +02:00
|
|
|
|
2019-05-31 23:35:08 -07:00
|
|
|
def test_jupyterhub_config_hook():
|
|
|
|
|
"""
|
|
|
|
|
Test that tmpauthenticator is enabled by our custom config plugin
|
|
|
|
|
"""
|
|
|
|
|
resp = requests.get('http://localhost/hub/tmplogin', allow_redirects=False)
|
|
|
|
|
assert resp.status_code == 302
|
|
|
|
|
assert resp.headers['Location'] == '/hub/spawn'
|
2019-06-27 11:45:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_post_install_hook():
|
|
|
|
|
"""
|
2019-07-02 12:53:06 +02:00
|
|
|
Test that the test_post_install file has the correct content
|
2019-06-27 11:45:36 +02:00
|
|
|
"""
|
2019-07-02 12:53:06 +02:00
|
|
|
with open("test_post_install") as f:
|
|
|
|
|
content = f.read()
|
|
|
|
|
|
|
|
|
|
assert content == "123456789"
|
2019-12-03 09:43:16 +01:00
|
|
|
|
|
|
|
|
|
2020-01-13 18:38:47 +02:00
|
|
|
def test_new_user_create():
|
2019-12-03 09:43:16 +01:00
|
|
|
"""
|
|
|
|
|
Test that plugin receives username as arg
|
|
|
|
|
"""
|
2020-01-13 18:38:47 +02:00
|
|
|
username="user1"
|
|
|
|
|
# Call ensure_user to make sure the user plugin gets called
|
|
|
|
|
user.ensure_user(username)
|
|
|
|
|
|
|
|
|
|
with open(f"test_new_user_create") as f:
|
2019-12-03 09:43:16 +01:00
|
|
|
content = f.read()
|
|
|
|
|
|
2020-01-13 18:38:47 +02:00
|
|
|
assert content == username
|