added yaml deserializer and move all yamll stuff to one folder

This commit is contained in:
Ari Sosnovsky committed 2021-11-11 11:51:58 -05:00
1 parent a05c1b9dca
commit 2768975f9d
12 files changed
+114 -37

No files matched your search

+5 -2
View File
@@ -1,3 +1,4 @@
from tempfile import mkdtemp
from unittest import TestCase
from src.config.AutomationLoader import (
AutomationActionNode,
@@ -10,8 +11,7 @@ from src.config.AutomationLoader import (
_parse_actions,
)
from src.json_serializer import NOT_IMPLEMENTED_SV_MSG
from src.config.HassSafeConstructor import (
HassConfig,
from src.yaml_serializer import (
SecretValue,
load_hass_config,
IncludedYaml,
@@ -20,6 +20,9 @@ from tests.utils import SAMPLE_HA_PATH
class config_finder_tests(TestCase):
def test_simple_made_up_config(self):
pass
def test_find_sample_config(self):
secrets, config = load_hass_config(SAMPLE_HA_PATH)
self.assertIsInstance(config["template"], IncludedYaml)
+1 -1
View File
@@ -1,6 +1,6 @@
import json
from unittest import TestCase
from src.config.HassSafeConstructor import SecretValue
from src.yaml_serializer import SecretValue
from src.json_serializer import json_dumps, NOT_IMPLEMENTED_SV_MSG
+23
View File
@@ -0,0 +1,23 @@
from pathlib import Path
from unittest import TestCase
from src.yaml_serializer import dump_yaml, IncludedYaml, SecretValue
class dumping_yamls_tests(TestCase):
def test_dumping_includes(self):
yaml = dump_yaml(
{
"automations": IncludedYaml(
"automations.yaml",
Path("/config/automations.yaml"),
[
{"id": "wow", "alias": "NO!"},
],
)
}
)
self.assertEqual(yaml, "automations: !include automations.yaml\n")
def test_dumping_secrets(self):
yaml = dump_yaml({"google_password": SecretValue("gpass", "supersec")})
self.assertEqual(yaml, "google_password: !secret gpass\n")
+17
View File
@@ -1,5 +1,22 @@
from tempfile import mkdtemp
from pathlib import Path
from typing import Optional
THIS_FOLDER = Path(__file__).parent
SAMPLE_HA_PATH = THIS_FOLDER / "samples"
SAMPLE_DB_PATH = SAMPLE_HA_PATH / "home-assistant_v2.db"
def create_dummy_auto_folder(
auto: dict,
secrets: Optional[dict] = None,
other_config: Optional[dict] = None,
include_auto_in_configuration: bool = False,
) -> Path:
root_folder = Path(mkdtemp())
configuration_yaml = {**other_config} if other_config is not None else {}
if include_auto_in_configuration:
configuration_yaml["automation"] = auto
else:
configuration_yaml["automation"] = "!include automations.yaml"
# (root_folder / 'automations.yaml').write_text(yaml)