no longer need to mock out generate_traefik_api_credentials

This commit is contained in:
Min RK
2019-02-22 11:39:40 +01:00
parent fd114e9030
commit af36ee73e4
2 changed files with 9 additions and 35 deletions

View File

@@ -128,9 +128,7 @@ 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, mock.patch( ) as check_active:
"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')
@@ -153,44 +151,29 @@ 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])
with mock.patch( cfg = configurer.load_config()
"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"])
with mock.patch( cfg = configurer.load_config()
"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"])
with mock.patch( cfg = configurer.load_config()
"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"])
with mock.patch( cfg = configurer.load_config()
"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"])
with mock.patch( cfg = configurer.load_config()
"tljh.configurer.generate_traefik_api_credentials"
) as generate_credentials:
cfg = configurer.load_config()
assert cfg['foo']['bar'] == [2] assert cfg['foo']['bar'] == [2]

View File

@@ -18,10 +18,7 @@ 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")
with mock.patch( traefik.ensure_traefik_config(str(state_dir))
"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:
@@ -56,10 +53,7 @@ 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"]
) )
with mock.patch( traefik.ensure_traefik_config(str(state_dir))
"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()
@@ -98,10 +92,7 @@ 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")
with mock.patch( traefik.ensure_traefik_config(str(state_dir))
"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()