-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow use of environment variables for create-site script (Fixes #55)
- Loading branch information
Showing
7 changed files
with
141 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Allow use of environment variables for create-site script [@ericof] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from pathlib import Path | ||
|
||
import json | ||
|
||
|
||
truthy = frozenset(("t", "true", "y", "yes", "on", "1")) | ||
|
||
|
||
def asbool(s): | ||
"""Return the boolean value ``True`` if the case-lowered value of string | ||
input ``s`` is a :term:`truthy string`. If ``s`` is already one of the | ||
boolean values ``True`` or ``False``, return it.""" | ||
if s is None: | ||
return False | ||
if isinstance(s, bool): | ||
return s | ||
s = str(s).strip() | ||
return s.lower() in truthy | ||
|
||
|
||
def parse_answers(answers_file: Path, answers_env: dict) -> dict: | ||
answers = json.loads(answers_file.read_text()) | ||
for key in answers: | ||
env_value = answers_env.get(key, "") | ||
if key == "setup_content" and env_value.strip(): | ||
env_value = asbool(env_value) | ||
elif not env_value: | ||
continue | ||
# Override answers_file value | ||
answers[key] = env_value | ||
return answers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"site_id": "Plone", | ||
"title": "Plone Intranet by kitconcept", | ||
"description": "A Plone Intranet distribution provided by kitconcept GmbH", | ||
"default_language": "en", | ||
"portal_timezone": "Europe/Berlin", | ||
"workflow": "public", | ||
"setup_content": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from kitconcept.intranet.utils.scripts import parse_answers | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def answers_file(): | ||
path = Path(__file__).parent / "default.json" | ||
return path | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"key,value,expected", | ||
( | ||
("site_id", "", "Plone"), | ||
("site_id", "Site", "Site"), | ||
("title", "Foo Bar", "Foo Bar"), | ||
("description", "A new site", "A new site"), | ||
( | ||
"description", | ||
"", | ||
"A Plone Intranet distribution provided by kitconcept GmbH", | ||
), | ||
("default_language", "", "en"), | ||
("default_language", "de", "de"), | ||
("portal_timezone", "", "Europe/Berlin"), | ||
("portal_timezone", "UTC", "UTC"), | ||
("workflow", "", "public"), | ||
("workflow", "private", "private"), | ||
("setup_content", "", True), | ||
("setup_content", "f", False), | ||
), | ||
) | ||
def test_parse_answers(answers_file, key: str, value: str, expected: str | bool): | ||
answers = {key: value} | ||
result = parse_answers(answers_file, answers) | ||
assert result[key] == expected |