Skip to content

Commit

Permalink
Merge pull request #399 from GeorgianaElena/add_append_to_arg
Browse files Browse the repository at this point in the history
Allow adding multiple admins during install
  • Loading branch information
yuvipanda committed Jul 15, 2019
2 parents 0ccf3e9 + 55e9aa2 commit f952e4e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 14 additions & 0 deletions tests/test_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os

from tljh import installer
from tljh.yaml import yaml


def test_ensure_node():
Expand All @@ -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']
5 changes: 4 additions & 1 deletion tljh/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -440,6 +442,7 @@ def main():
argparser.add_argument(
'--admin',
nargs='*',
action='append',
help='List of usernames set to be admin'
)
argparser.add_argument(
Expand Down

0 comments on commit f952e4e

Please sign in to comment.