test config dir setup

including upgrading old config files
This commit is contained in:
Min RK
2018-08-28 14:16:09 +02:00
parent 2bf23f0b28
commit 4b79993ea0
2 changed files with 49 additions and 2 deletions

View File

@@ -1,10 +1,57 @@
"""
Unit test functions in installer.py
"""
from tljh import installer
import os
from datetime import date
from tljh import installer
def test_ensure_node():
installer.ensure_node()
assert os.path.exists('/usr/bin/node')
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

View File

@@ -336,7 +336,7 @@ def ensure_symlinks(prefix):
os.symlink(tljh_config_src, tljh_config_dest)
def setup_plugins(plugins):
def setup_plugins(plugins=None):
"""
Install plugins & setup a pluginmanager
"""