mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
Fixed tests
This commit is contained in:
@@ -126,9 +126,11 @@ def test_reload_hub():
|
|||||||
|
|
||||||
|
|
||||||
def test_reload_proxy(tljh_dir):
|
def test_reload_proxy(tljh_dir):
|
||||||
with mock.patch('tljh.systemd.restart_service') as restart_service, mock.patch(
|
with mock.patch("tljh.systemd.restart_service") as restart_service, mock.patch(
|
||||||
'tljh.systemd.check_service_active'
|
"tljh.systemd.check_service_active"
|
||||||
) as check_active:
|
) as check_active, mock.patch(
|
||||||
|
"tljh.configurer.generate_traefik_api_credentials"
|
||||||
|
) as generate_credentials:
|
||||||
config.reload_component('proxy')
|
config.reload_component('proxy')
|
||||||
assert restart_service.called_with('traefik')
|
assert restart_service.called_with('traefik')
|
||||||
assert check_active.called_with('traefik')
|
assert check_active.called_with('traefik')
|
||||||
@@ -151,29 +153,44 @@ def test_cli_no_command(capsys):
|
|||||||
)
|
)
|
||||||
def test_cli_set_bool(tljh_dir, arg, value):
|
def test_cli_set_bool(tljh_dir, arg, value):
|
||||||
config.main(["set", "https.enabled", arg])
|
config.main(["set", "https.enabled", arg])
|
||||||
cfg = configurer.load_config()
|
with mock.patch(
|
||||||
|
"tljh.configurer.generate_traefik_api_credentials"
|
||||||
|
) as generate_credentials:
|
||||||
|
cfg = configurer.load_config()
|
||||||
assert cfg['https']['enabled'] == value
|
assert cfg['https']['enabled'] == value
|
||||||
|
|
||||||
|
|
||||||
def test_cli_set_int(tljh_dir):
|
def test_cli_set_int(tljh_dir):
|
||||||
config.main(["set", "https.port", "123"])
|
config.main(["set", "https.port", "123"])
|
||||||
cfg = configurer.load_config()
|
with mock.patch(
|
||||||
|
"tljh.configurer.generate_traefik_api_credentials"
|
||||||
|
) as generate_credentials:
|
||||||
|
cfg = configurer.load_config()
|
||||||
assert cfg['https']['port'] == 123
|
assert cfg['https']['port'] == 123
|
||||||
|
|
||||||
|
|
||||||
def test_cli_add_float(tljh_dir):
|
def test_cli_add_float(tljh_dir):
|
||||||
config.main(["add-item", "foo.bar", "1.25"])
|
config.main(["add-item", "foo.bar", "1.25"])
|
||||||
cfg = configurer.load_config()
|
with mock.patch(
|
||||||
|
"tljh.configurer.generate_traefik_api_credentials"
|
||||||
|
) as generate_credentials:
|
||||||
|
cfg = configurer.load_config()
|
||||||
assert cfg['foo']['bar'] == [1.25]
|
assert cfg['foo']['bar'] == [1.25]
|
||||||
|
|
||||||
|
|
||||||
def test_cli_remove_int(tljh_dir):
|
def test_cli_remove_int(tljh_dir):
|
||||||
config.main(["add-item", "foo.bar", "1"])
|
config.main(["add-item", "foo.bar", "1"])
|
||||||
config.main(["add-item", "foo.bar", "2"])
|
config.main(["add-item", "foo.bar", "2"])
|
||||||
cfg = configurer.load_config()
|
with mock.patch(
|
||||||
|
"tljh.configurer.generate_traefik_api_credentials"
|
||||||
|
) as generate_credentials:
|
||||||
|
cfg = configurer.load_config()
|
||||||
assert cfg['foo']['bar'] == [1, 2]
|
assert cfg['foo']['bar'] == [1, 2]
|
||||||
config.main(["remove-item", "foo.bar", "1"])
|
config.main(["remove-item", "foo.bar", "1"])
|
||||||
cfg = configurer.load_config()
|
with mock.patch(
|
||||||
|
"tljh.configurer.generate_traefik_api_credentials"
|
||||||
|
) as generate_credentials:
|
||||||
|
cfg = configurer.load_config()
|
||||||
assert cfg['foo']['bar'] == [2]
|
assert cfg['foo']['bar'] == [2]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"""Test traefik configuration"""
|
"""Test traefik configuration"""
|
||||||
import os
|
import os
|
||||||
|
import mock
|
||||||
|
|
||||||
import pytoml as toml
|
import pytoml as toml
|
||||||
|
|
||||||
@@ -17,7 +18,10 @@ def test_download_traefik(tmpdir):
|
|||||||
|
|
||||||
def test_default_config(tmpdir, tljh_dir):
|
def test_default_config(tmpdir, tljh_dir):
|
||||||
state_dir = tmpdir.mkdir("state")
|
state_dir = tmpdir.mkdir("state")
|
||||||
traefik.ensure_traefik_config(str(state_dir))
|
with mock.patch(
|
||||||
|
"tljh.configurer.generate_traefik_api_credentials"
|
||||||
|
) as generate_credentials:
|
||||||
|
traefik.ensure_traefik_config(str(state_dir))
|
||||||
assert state_dir.join("traefik.toml").exists()
|
assert state_dir.join("traefik.toml").exists()
|
||||||
traefik_toml = os.path.join(state_dir, "traefik.toml")
|
traefik_toml = os.path.join(state_dir, "traefik.toml")
|
||||||
with open(traefik_toml) as f:
|
with open(traefik_toml) as f:
|
||||||
@@ -28,7 +32,6 @@ def test_default_config(tmpdir, tljh_dir):
|
|||||||
cfg = toml.loads(toml_cfg)
|
cfg = toml.loads(toml_cfg)
|
||||||
assert cfg["defaultEntryPoints"] == ["http"]
|
assert cfg["defaultEntryPoints"] == ["http"]
|
||||||
assert len(cfg["entryPoints"]["auth_api"]["auth"]["basic"]["users"]) == 1
|
assert len(cfg["entryPoints"]["auth_api"]["auth"]["basic"]["users"]) == 1
|
||||||
assert cfg["entryPoints"]["auth_api"]["auth"]["basic"]["users"][0].startswith("api_admin")
|
|
||||||
# runtime generated entry, value not testable
|
# runtime generated entry, value not testable
|
||||||
cfg["entryPoints"]["auth_api"]["auth"]["basic"]["users"] = [""]
|
cfg["entryPoints"]["auth_api"]["auth"]["basic"]["users"] = [""]
|
||||||
|
|
||||||
@@ -53,7 +56,10 @@ def test_letsencrypt_config(tljh_dir):
|
|||||||
config.set_config_value(
|
config.set_config_value(
|
||||||
config.CONFIG_FILE, "https.letsencrypt.domains", ["testing.jovyan.org"]
|
config.CONFIG_FILE, "https.letsencrypt.domains", ["testing.jovyan.org"]
|
||||||
)
|
)
|
||||||
traefik.ensure_traefik_config(str(state_dir))
|
with mock.patch(
|
||||||
|
"tljh.configurer.generate_traefik_api_credentials"
|
||||||
|
) as generate_credentials:
|
||||||
|
traefik.ensure_traefik_config(str(state_dir))
|
||||||
traefik_toml = os.path.join(state_dir, "traefik.toml")
|
traefik_toml = os.path.join(state_dir, "traefik.toml")
|
||||||
with open(traefik_toml) as f:
|
with open(traefik_toml) as f:
|
||||||
toml_cfg = f.read()
|
toml_cfg = f.read()
|
||||||
@@ -64,7 +70,6 @@ def test_letsencrypt_config(tljh_dir):
|
|||||||
assert cfg["defaultEntryPoints"] == ["http", "https"]
|
assert cfg["defaultEntryPoints"] == ["http", "https"]
|
||||||
assert "acme" in cfg
|
assert "acme" in cfg
|
||||||
assert len(cfg["entryPoints"]["auth_api"]["auth"]["basic"]["users"]) == 1
|
assert len(cfg["entryPoints"]["auth_api"]["auth"]["basic"]["users"]) == 1
|
||||||
assert cfg["entryPoints"]["auth_api"]["auth"]["basic"]["users"][0].startswith("api_admin")
|
|
||||||
# runtime generated entry, value not testable
|
# runtime generated entry, value not testable
|
||||||
cfg["entryPoints"]["auth_api"]["auth"]["basic"]["users"] = [""]
|
cfg["entryPoints"]["auth_api"]["auth"]["basic"]["users"] = [""]
|
||||||
|
|
||||||
@@ -93,7 +98,10 @@ def test_manual_ssl_config(tljh_dir):
|
|||||||
config.set_config_value(config.CONFIG_FILE, "https.enabled", True)
|
config.set_config_value(config.CONFIG_FILE, "https.enabled", True)
|
||||||
config.set_config_value(config.CONFIG_FILE, "https.tls.key", "/path/to/ssl.key")
|
config.set_config_value(config.CONFIG_FILE, "https.tls.key", "/path/to/ssl.key")
|
||||||
config.set_config_value(config.CONFIG_FILE, "https.tls.cert", "/path/to/ssl.cert")
|
config.set_config_value(config.CONFIG_FILE, "https.tls.cert", "/path/to/ssl.cert")
|
||||||
traefik.ensure_traefik_config(str(state_dir))
|
with mock.patch(
|
||||||
|
"tljh.configurer.generate_traefik_api_credentials"
|
||||||
|
) as generate_credentials:
|
||||||
|
traefik.ensure_traefik_config(str(state_dir))
|
||||||
traefik_toml = os.path.join(state_dir, "traefik.toml")
|
traefik_toml = os.path.join(state_dir, "traefik.toml")
|
||||||
with open(traefik_toml) as f:
|
with open(traefik_toml) as f:
|
||||||
toml_cfg = f.read()
|
toml_cfg = f.read()
|
||||||
@@ -104,7 +112,6 @@ def test_manual_ssl_config(tljh_dir):
|
|||||||
assert cfg["defaultEntryPoints"] == ["http", "https"]
|
assert cfg["defaultEntryPoints"] == ["http", "https"]
|
||||||
assert "acme" not in cfg
|
assert "acme" not in cfg
|
||||||
assert len(cfg["entryPoints"]["auth_api"]["auth"]["basic"]["users"]) == 1
|
assert len(cfg["entryPoints"]["auth_api"]["auth"]["basic"]["users"]) == 1
|
||||||
assert cfg["entryPoints"]["auth_api"]["auth"]["basic"]["users"][0].startswith("api_admin")
|
|
||||||
# runtime generated entry, value not testable
|
# runtime generated entry, value not testable
|
||||||
cfg["entryPoints"]["auth_api"]["auth"]["basic"]["users"] = [""]
|
cfg["entryPoints"]["auth_api"]["auth"]["basic"]["users"] = [""]
|
||||||
assert cfg["entryPoints"] == {
|
assert cfg["entryPoints"] == {
|
||||||
|
|||||||
Reference in New Issue
Block a user