From 4b79993ea074032a29a86886162776f9d361cf5d Mon Sep 17 00:00:00 2001 From: Min RK Date: Tue, 28 Aug 2018 14:16:09 +0200 Subject: [PATCH] test config dir setup including upgrading old config files --- tests/test_installer.py | 49 ++++++++++++++++++++++++++++++++++++++++- tljh/installer.py | 2 +- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/tests/test_installer.py b/tests/test_installer.py index b8a7834..f845209 100644 --- a/tests/test_installer.py +++ b/tests/test_installer.py @@ -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 + + + + + + + diff --git a/tljh/installer.py b/tljh/installer.py index f27af3e..70049a8 100644 --- a/tljh/installer.py +++ b/tljh/installer.py @@ -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 """