From 989eda89068e0deb546a69fcadd21262c4be1553 Mon Sep 17 00:00:00 2001 From: GeorgianaElena Date: Thu, 11 Jul 2019 20:51:51 +0300 Subject: [PATCH 1/2] Append admin cmd option --- tljh/installer.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tljh/installer.py b/tljh/installer.py index 05055e2..9dc1c89 100644 --- a/tljh/installer.py +++ b/tljh/installer.py @@ -286,7 +286,9 @@ def ensure_admins(admins): config = {} config['users'] = config.get('users', {}) - config['users']['admin'] = list(admins) + # Flatten admin lists + config['users']['admin'] = [admin for admin_sublist in admins + for admin in admin_sublist] with open(config_path, 'w+') as f: yaml.dump(config, f) @@ -440,6 +442,7 @@ def main(): argparser.add_argument( '--admin', nargs='*', + action='append', help='List of usernames set to be admin' ) argparser.add_argument( From 55e9aa2c2986879c4aa9f4a5dbc12a0db7e4ed7e Mon Sep 17 00:00:00 2001 From: GeorgianaElena Date: Mon, 15 Jul 2019 12:02:18 +0300 Subject: [PATCH 2/2] Test multiple admins on install --- tests/test_installer.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_installer.py b/tests/test_installer.py index d97f01b..4613cb7 100644 --- a/tests/test_installer.py +++ b/tests/test_installer.py @@ -4,6 +4,7 @@ Unit test functions in installer.py import os from tljh import installer +from tljh.yaml import yaml def test_ensure_node(): @@ -19,3 +20,16 @@ def test_ensure_config_yaml(tljh_dir): assert os.path.isdir(os.path.join(installer.CONFIG_DIR, 'jupyterhub_config.d')) # verify that old config doesn't exist assert not os.path.exists(os.path.join(tljh_dir, 'config.yaml')) + +def test_ensure_admins(tljh_dir): + # --admin option called multiple times on the installer + # creates a list of argument lists. + admins = [['a1'], ['a2'], ['a3']] + installer.ensure_admins(admins) + + config_path = installer.CONFIG_FILE + with open(config_path, 'r') as f: + config = yaml.load(f) + + # verify the list was flattened + assert config['users']['admin'] == ['a1', 'a2', 'a3']