refactor(data): add in new config for builder

we are doing phase one of the four phase migration on the builder config
This commit is contained in:
Charlton Austin 2017-03-16 18:51:42 -04:00
parent 123d003d4e
commit f701677a8e
4 changed files with 86 additions and 6 deletions

View file

View file

@ -0,0 +1,44 @@
import os
def _get_config_expand(config):
""" Get config with both context and dockerfile_path written to it """
if config and "subdir" in config and "context" not in config:
config_expand = dict(config)
config_expand["context"] = _create_context(config["subdir"])
config_expand["dockerfile_path"] = _create_dockerfile_path(config["subdir"])
return config_expand
return config or {}
def _create_context(current_subdir):
""" Create context from current subdir """
if current_subdir.endswith("Dockerfile"):
context, _ = os.path.split(current_subdir)
if context == "":
return os.path.sep
return context
if current_subdir == "":
current_subdir = os.path.sep + current_subdir
if current_subdir[len(current_subdir) - 1] != os.path.sep:
current_subdir += os.path.sep
context, _ = os.path.split(current_subdir)
return context
def _create_dockerfile_path(current_subdir):
""" Create dockefile path from current subdir """
if current_subdir.endswith("Dockerfile"):
return current_subdir
if current_subdir == "":
current_subdir = os.path.sep + current_subdir
if current_subdir[len(current_subdir) - 1] != os.path.sep:
current_subdir += os.path.sep
return current_subdir + "Dockerfile"

View file

@ -0,0 +1,30 @@
import pytest
from data.model.helpers.build_helper import _get_config_expand
@pytest.mark.parametrize('org_config,expected', [
# Empty config
(None, {}),
# No subdir in config
({}, {}),
({"subdir": ""}, {"context": "/", "dockerfile_path": "/Dockerfile", "subdir": ""}),
({"subdir": "/"}, {"context": "/", "dockerfile_path": "/Dockerfile", "subdir": "/"}),
({"subdir": "/Dockerfile"}, {"context": "/", "dockerfile_path": "/Dockerfile", "subdir": "/Dockerfile"}),
({"subdir": "a"}, {"context": "a", "dockerfile_path": "a/Dockerfile", "subdir": "a"}),
({"subdir": "Dockerfile"}, {"context": "/", "dockerfile_path": "Dockerfile", "subdir": "Dockerfile"}),
({"subdir": "server.Dockerfile"},
{"context": "/", "dockerfile_path": "server.Dockerfile", "subdir": "server.Dockerfile"}),
({"subdir": "/a/b/Dockerfile"},
{"context": "/a/b", "dockerfile_path": "/a/b/Dockerfile", "subdir": "/a/b/Dockerfile"}),
({"subdir": "/a/b/server.Dockerfile"},
{"context": "/a/b", "dockerfile_path": "/a/b/server.Dockerfile", "subdir": "/a/b/server.Dockerfile"}),
({"subdir": "a/b/Dockerfile"}, {"context": "a/b", "dockerfile_path": "a/b/Dockerfile", "subdir": "a/b/Dockerfile"}),
({"subdir": "a/b/server.Dockerfile"},
{"context": "a/b", "dockerfile_path": "a/b/server.Dockerfile", "subdir": "a/b/server.Dockerfile"}),
({"subdir": "/a/b/c", "context": "slime"}, {"context": "slime", "subdir": "/a/b/c"}),
])
def test_super_user_build_endpoints(org_config, expected):
assert _get_config_expand(org_config) == expected