2018-07-19 17:30:09 -07:00
|
|
|
"""
|
|
|
|
|
Unit test functions in installer.py
|
|
|
|
|
"""
|
|
|
|
|
import os
|
2018-08-28 14:16:09 +02:00
|
|
|
from datetime import date
|
|
|
|
|
|
|
|
|
|
from tljh import installer
|
|
|
|
|
|
2018-07-19 17:30:09 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_ensure_node():
|
|
|
|
|
installer.ensure_node()
|
|
|
|
|
assert os.path.exists('/usr/bin/node')
|
2018-08-28 14:16:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_ensure_config_yaml(tljh_dir):
|
|
|
|
|
pm = installer.setup_plugins()
|
|
|
|
|
installer.ensure_config_yaml(pm)
|
|
|
|
|
assert os.path.exists(installer.CONFIG_FILE)
|
|
|
|
|
assert os.path.isdir(installer.CONFIG_DIR)
|
|
|
|
|
assert os.path.isdir(os.path.join(installer.CONFIG_DIR, 'jupyterhub_config.d'))
|
|
|
|
|
assert not os.path.exists(installer.OLD_CONFIG_FILE)
|
|
|
|
|
|
|
|
|
|
# run again, with old config in the way and no new config
|
|
|
|
|
upgraded_config = 'old: config\n'
|
|
|
|
|
with open(installer.OLD_CONFIG_FILE, 'w') as f:
|
|
|
|
|
f.write(upgraded_config)
|
|
|
|
|
os.remove(installer.CONFIG_FILE)
|
|
|
|
|
installer.ensure_config_yaml(pm)
|
|
|
|
|
assert os.path.exists(installer.CONFIG_FILE)
|
|
|
|
|
assert not os.path.exists(installer.OLD_CONFIG_FILE)
|
|
|
|
|
with open(installer.CONFIG_FILE) as f:
|
|
|
|
|
assert f.read() == upgraded_config
|
|
|
|
|
|
|
|
|
|
# run again, this time with both old and new config
|
|
|
|
|
duplicate_config = 'dupe: config\n'
|
|
|
|
|
with open(installer.OLD_CONFIG_FILE, 'w') as f:
|
|
|
|
|
f.write(duplicate_config)
|
|
|
|
|
installer.ensure_config_yaml(pm)
|
|
|
|
|
assert os.path.exists(installer.CONFIG_FILE)
|
|
|
|
|
assert not os.path.exists(installer.OLD_CONFIG_FILE)
|
|
|
|
|
# didn't clobber config:
|
|
|
|
|
with open(installer.CONFIG_FILE) as f:
|
|
|
|
|
assert f.read() == upgraded_config
|
|
|
|
|
|
|
|
|
|
# preserved old config
|
|
|
|
|
backup_config = installer.CONFIG_FILE + f".old.{date.today().isoformat()}"
|
|
|
|
|
assert os.path.exists(backup_config)
|
|
|
|
|
with open(backup_config) as f:
|
|
|
|
|
assert f.read() == duplicate_config
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|