move config migration to its own file

This commit is contained in:
Min RK
2018-08-31 12:17:16 +02:00
parent 37ad207be9
commit 5df106fa82
5 changed files with 139 additions and 63 deletions

View File

@@ -2,12 +2,10 @@
Unit test functions in installer.py
"""
import os
from datetime import date
from tljh import installer
def test_ensure_node():
installer.ensure_node()
assert os.path.exists('/usr/bin/node')
@@ -19,39 +17,5 @@ def test_ensure_config_yaml(tljh_dir):
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
# verify that old config doesn't exist
assert not os.path.exists(os.path.join(tljh_dir, 'config.yaml'))