6
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-12-12 06:07:56 +00:00

Minor formatting and fix tests

This commit is contained in:
Régis Behmo 2019-06-05 19:57:30 +02:00
parent bc21102cf4
commit a0146de611
6 changed files with 25 additions and 8 deletions

View File

@ -21,9 +21,8 @@ config = {
templates = os.path.join(HERE, "templates")
scripts = {
"init": ["minio-client"]
}
scripts = {"init": ["minio-client"]}
def patches():
all_patches = {}

View File

@ -66,6 +66,7 @@ class PluginsTests(unittest.TestCase):
def test_configure(self):
config = {"ID": "id"}
defaults = {}
class plugin1:
config = {
"add": {"PARAM1": "value1", "PARAM2": "value2"},
@ -104,6 +105,7 @@ class PluginsTests(unittest.TestCase):
def test_configure_set_random_string(self):
config = {}
class plugin1:
config = {"set": {"PARAM1": "{{ 128|random_string }}"}}
@ -116,8 +118,10 @@ class PluginsTests(unittest.TestCase):
def test_configure_default_value_with_previous_definition(self):
config = {}
defaults = {"PARAM1": "value"}
class plugin1:
config = {"defaults": {"PARAM2": "{{ PARAM1 }}"}}
with unittest.mock.patch.object(
plugins, "iter_enabled", return_value=[("plugin1", plugin1)]
):
@ -127,6 +131,7 @@ class PluginsTests(unittest.TestCase):
def test_scripts(self):
class plugin1:
scripts = {"init": ["myclient"]}
with unittest.mock.patch.object(
plugins, "iter_enabled", return_value=[("plugin1", plugin1)]
):

View File

@ -176,8 +176,7 @@ def https_create(root):
fmt.echo_info("HTTPS is not activated: certificate generation skipped")
return
# TODO this is not going to work anymore
script = runner.render("certbot", "create")
script = runner.render("scripts", "certbot", "create")
if config["WEB_PROXY"]:
fmt.echo_info(
@ -305,7 +304,16 @@ def portainer(root, port):
class ScriptRunner(scripts.BaseRunner):
def exec(self, service, command):
docker_compose(self.root, self.config, "run", "--rm", "--entrypoint", "sh -e -c", service, command)
docker_compose(
self.root,
self.config,
"run",
"--rm",
"--entrypoint",
"sh -e -c",
service,
command,
)
def docker_compose(root, config, *command):

View File

@ -111,6 +111,7 @@ def load_required(config, defaults):
if key not in config:
config[key] = env.render_unknown(config, defaults[key])
def load_plugins(config, defaults):
"""
Add, override and set new defaults from plugins.

View File

@ -160,6 +160,7 @@ def render_unknown(config, value):
return render_str(config, value)
return value
def render_str(config, text):
"""
Args:

View File

@ -10,9 +10,12 @@ class BaseRunner:
self.config = config
def run(self, service, *path):
command = env.render_file(self.config, *path).strip()
command = self.render(*path)
self.exec(service, command)
def render(self, *path):
return env.render_file(self.config, *path).strip()
def exec(self, service, command):
raise NotImplementedError