mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
Add relevant tests and formatting
This commit is contained in:
committed by
GeorgianaElena
parent
66cd578d75
commit
f799206920
@@ -2,6 +2,7 @@
|
|||||||
Test configurer
|
Test configurer
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from traitlets import Dict
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@@ -62,6 +63,22 @@ def apply_mock_config(overrides):
|
|||||||
return c
|
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():
|
def test_default_memory_limit():
|
||||||
"""
|
"""
|
||||||
Test default per user 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.JupyterHub.authenticator_class == 'dummyauthenticator.DummyAuthenticator'
|
||||||
assert c.DummyAuthenticator.password == 'test'
|
assert c.DummyAuthenticator.password == 'test'
|
||||||
|
|
||||||
from traitlets import Dict
|
|
||||||
def test_user_groups():
|
def test_user_groups():
|
||||||
"""
|
"""
|
||||||
Test setting user groups
|
Test setting user groups
|
||||||
@@ -143,9 +160,9 @@ def test_user_groups():
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
assert c.UserCreatingSpawner.user_groups == {
|
assert c.UserCreatingSpawner.user_groups == {
|
||||||
"g1": ["u1", "u2"],
|
"g1": ["u1", "u2"],
|
||||||
"g2": ["u3", "u4"]
|
"g2": ["u3", "u4"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_auth_firstuse():
|
def test_auth_firstuse():
|
||||||
@@ -213,9 +230,9 @@ def test_cull_service_default():
|
|||||||
c = apply_mock_config({})
|
c = apply_mock_config({})
|
||||||
|
|
||||||
cull_cmd = [
|
cull_cmd = [
|
||||||
sys.executable, '-m', 'jupyterhub_idle_culler',
|
sys.executable, '-m', 'jupyterhub_idle_culler',
|
||||||
'--timeout=600', '--cull-every=60', '--concurrency=5',
|
'--timeout=600', '--cull-every=60', '--concurrency=5',
|
||||||
'--max-age=0'
|
'--max-age=0'
|
||||||
]
|
]
|
||||||
assert c.JupyterHub.services == [{
|
assert c.JupyterHub.services == [{
|
||||||
'name': 'cull-idle',
|
'name': 'cull-idle',
|
||||||
@@ -238,9 +255,9 @@ def test_set_cull_service():
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
cull_cmd = [
|
cull_cmd = [
|
||||||
sys.executable, '-m', 'jupyterhub_idle_culler',
|
sys.executable, '-m', 'jupyterhub_idle_culler',
|
||||||
'--timeout=600', '--cull-every=10', '--concurrency=5',
|
'--timeout=600', '--cull-every=10', '--concurrency=5',
|
||||||
'--max-age=60', '--cull-users'
|
'--max-age=60', '--cull-users'
|
||||||
]
|
]
|
||||||
assert c.JupyterHub.services == [{
|
assert c.JupyterHub.services == [{
|
||||||
'name': 'cull-idle',
|
'name': 'cull-idle',
|
||||||
@@ -276,4 +293,3 @@ def test_auth_native():
|
|||||||
})
|
})
|
||||||
assert c.JupyterHub.authenticator_class == 'nativeauthenticator.NativeAuthenticator'
|
assert c.JupyterHub.authenticator_class == 'nativeauthenticator.NativeAuthenticator'
|
||||||
assert c.NativeAuthenticator.open_signup == True
|
assert c.NativeAuthenticator.open_signup == True
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ def set_item_in_config(config, property_path, value):
|
|||||||
|
|
||||||
return config_copy
|
return config_copy
|
||||||
|
|
||||||
|
|
||||||
def unset_item_from_config(config, property_path):
|
def unset_item_from_config(config, property_path):
|
||||||
"""
|
"""
|
||||||
Unset key at property_path in config & return new config.
|
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
|
return config_copy
|
||||||
|
|
||||||
|
|
||||||
def add_item_to_config(config, property_path, value):
|
def add_item_to_config(config, property_path, value):
|
||||||
"""
|
"""
|
||||||
Add an item to a list in config.
|
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:
|
with open(config_path, 'w') as f:
|
||||||
yaml.dump(config, f)
|
yaml.dump(config, f)
|
||||||
|
|
||||||
|
|
||||||
def check_hub_ready():
|
def check_hub_ready():
|
||||||
from .configurer import load_config
|
from .configurer import load_config
|
||||||
|
|
||||||
@@ -250,6 +253,7 @@ def check_hub_ready():
|
|||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def reload_component(component):
|
def reload_component(component):
|
||||||
"""
|
"""
|
||||||
Reload a TLJH component.
|
Reload a TLJH component.
|
||||||
@@ -392,13 +396,16 @@ def main(argv=None):
|
|||||||
if args.action == 'show':
|
if args.action == 'show':
|
||||||
show_config(args.config_path)
|
show_config(args.config_path)
|
||||||
elif args.action == 'set':
|
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':
|
elif args.action == 'unset':
|
||||||
unset_config_value(args.config_path, args.key_path)
|
unset_config_value(args.config_path, args.key_path)
|
||||||
elif args.action == 'add-item':
|
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':
|
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':
|
elif args.action == 'reload':
|
||||||
reload_component(args.component)
|
reload_component(args.component)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user