diff --git a/tests/test_configurer.py b/tests/test_configurer.py index fa3090e..5380861 100644 --- a/tests/test_configurer.py +++ b/tests/test_configurer.py @@ -2,6 +2,7 @@ Test configurer """ +from traitlets import Dict import os import sys @@ -62,6 +63,22 @@ def apply_mock_config(overrides): return c +def test_default_base_url(): + """ + Test default JupyterHub base_url + """ + c = apply_mock_config({}) + assert c.JupyterHub.base_url == '/' + + +def test_set_base_url(): + """ + Test set JupyterHub base_url + """ + c = apply_mock_config({'base_url': '/custom-base'}) + assert c.JupyterHub.base_url == '/custom-base' + + def test_default_memory_limit(): """ Test default per user memory limit @@ -129,7 +146,7 @@ def test_auth_dummy(): assert c.JupyterHub.authenticator_class == 'dummyauthenticator.DummyAuthenticator' assert c.DummyAuthenticator.password == 'test' -from traitlets import Dict + def test_user_groups(): """ Test setting user groups @@ -143,9 +160,9 @@ def test_user_groups(): } }) assert c.UserCreatingSpawner.user_groups == { - "g1": ["u1", "u2"], - "g2": ["u3", "u4"] - } + "g1": ["u1", "u2"], + "g2": ["u3", "u4"] + } def test_auth_firstuse(): @@ -213,9 +230,9 @@ def test_cull_service_default(): c = apply_mock_config({}) cull_cmd = [ - sys.executable, '-m', 'jupyterhub_idle_culler', - '--timeout=600', '--cull-every=60', '--concurrency=5', - '--max-age=0' + sys.executable, '-m', 'jupyterhub_idle_culler', + '--timeout=600', '--cull-every=60', '--concurrency=5', + '--max-age=0' ] assert c.JupyterHub.services == [{ 'name': 'cull-idle', @@ -238,9 +255,9 @@ def test_set_cull_service(): } }) cull_cmd = [ - sys.executable, '-m', 'jupyterhub_idle_culler', - '--timeout=600', '--cull-every=10', '--concurrency=5', - '--max-age=60', '--cull-users' + sys.executable, '-m', 'jupyterhub_idle_culler', + '--timeout=600', '--cull-every=10', '--concurrency=5', + '--max-age=60', '--cull-users' ] assert c.JupyterHub.services == [{ 'name': 'cull-idle', @@ -276,4 +293,3 @@ def test_auth_native(): }) assert c.JupyterHub.authenticator_class == 'nativeauthenticator.NativeAuthenticator' assert c.NativeAuthenticator.open_signup == True - diff --git a/tljh/config.py b/tljh/config.py index a30f176..ec235f4 100644 --- a/tljh/config.py +++ b/tljh/config.py @@ -61,6 +61,7 @@ def set_item_in_config(config, property_path, value): return config_copy + def unset_item_from_config(config, property_path): """ Unset key at property_path in config & return new config. @@ -105,6 +106,7 @@ def unset_item_from_config(config, property_path): return config_copy + def add_item_to_config(config, property_path, value): """ Add an item to a list in config. @@ -238,6 +240,7 @@ def remove_config_value(config_path, key_path, value): with open(config_path, 'w') as f: yaml.dump(config, f) + def check_hub_ready(): from .configurer import load_config @@ -250,6 +253,7 @@ def check_hub_ready(): except: return False + def reload_component(component): """ Reload a TLJH component. @@ -392,13 +396,16 @@ def main(argv=None): if args.action == 'show': show_config(args.config_path) elif args.action == 'set': - set_config_value(args.config_path, args.key_path, parse_value(args.value)) + set_config_value(args.config_path, args.key_path, + parse_value(args.value)) elif args.action == 'unset': unset_config_value(args.config_path, args.key_path) elif args.action == 'add-item': - add_config_value(args.config_path, args.key_path, parse_value(args.value)) + add_config_value(args.config_path, args.key_path, + parse_value(args.value)) elif args.action == 'remove-item': - remove_config_value(args.config_path, args.key_path, parse_value(args.value)) + remove_config_value(args.config_path, args.key_path, + parse_value(args.value)) elif args.action == 'reload': reload_component(args.component) else: