manager code

This commit is contained in:
ari committed 2021-12-30 23:16:15 -05:00
1 parent 8adb86b2ec
commit ef5715ea6c
9 files changed
+66 -35

No files matched your search

@@ -0,0 +1,23 @@
from unittest import TestCase
from tests.utils import HA_CONFIG_EXAMPLE, create_dummy_config_folder
from src.hass_config.loader import HassConfig
from src.automations.manager import AutomationManager
example_hass_config = HassConfig(HA_CONFIG_EXAMPLE)
example_automation_loader = AutomationManager(example_hass_config)
class manager_tests(TestCase):
def test_find_limit_and_get(self):
first_auto_with_find = list(example_automation_loader.find(limit=1))
first_auto_with_get = example_automation_loader.get(0)
self.assertEqual(first_auto_with_find[0], first_auto_with_get)
def test_find_at_most_with_offset(self):
autos = list(example_automation_loader.find(limit=10, offset=10))
self.assertTrue(len(autos), 10)
def test_find_invalid(self):
self.assertIsNone(example_automation_loader.get(-1))
self.assertIsNone(example_automation_loader.get(1_000))
self.assertIsNone(example_automation_loader.get(31))
@@ -221,21 +221,6 @@ class parser_tests(TestCase):
for expected, parsed in zip(expected_process, _parse_actions(raw_conditions)):
self.assertEqual(parsed, expected)
# def test_finding_with_AutomationLoader(self):
# automation_loader = AutomationLoader(load_hass_config(SAMPLE_HA_PATH))
# first_auto_with_find = list(automation_loader.find(limit=1))
# first_auto_with_get = automation_loader.get(0)
# self.assertEqual(first_auto_with_find[0], first_auto_with_get)
# kitchen_autos = list(automation_loader.find(alias="kitchen"))
# self.assertTrue(len(kitchen_autos), 3)
# self.assertIsNone(automation_loader.get(-1))
# self.assertIsNone(automation_loader.get(1_000))
# self.assertIsNone(automation_loader.get(31))
# self.assertEqual(len(automation_loader), 31)
# def test_invalid_automations(self):
# with self.assertRaises(AutomationLoaderException):
# AutomationLoader(
@@ -1,9 +1,7 @@
from unittest import TestCase
from src.automations.types import AutomationData, AutomationMetdata
from src.hass_config.loader import HassConfig
from tests.utils import HA_CONFIG_EXAMPLE, create_dummy_config_folder
example_hass_config = HassConfig(HA_CONFIG_EXAMPLE)
from tests.utils import create_dummy_config_folder
class loader_tests(TestCase):
@@ -17,7 +15,7 @@ class loader_tests(TestCase):
self.assertTrue("automation" in hass_config.configurations)
self.assertEqual(hass_config.automations[0]["id"], "test")
def test_load_automation_from_config_yaml_inclue(self):
def test_load_automation_from_config_yaml_include(self):
folder = create_dummy_config_folder(
[AutomationData(metadata=AutomationMetdata(id="test"))],
automation_in_conifguration_mode="include",
+4 -4
View File
@@ -17,11 +17,11 @@ class dumping_yamls_tests(TestCase):
yaml = dump_yaml(
{
"automations": IncludedYaml(
Path("automations.yaml"),
"automations.yaml",
)
}
)
self.assertEqual(yaml, f"automations: !include {Path('automations.yaml').absolute()}\n")
self.assertEqual(yaml, "automations: !include automations.yaml\n")
def test_dumping_secrets(self):
yaml = dump_yaml({"google_password": SecretValue("gpass", "supersec")})
@@ -48,7 +48,7 @@ class dumping_yamls_tests(TestCase):
"name": "cool",
"google_password": SecretValue("gpass", "n/a"),
"sensor": IncludedYamlDir("include_dir_list", "sensors/*yaml"),
"automations": IncludedYaml(Path("automations.yaml").absolute()),
"automations": IncludedYaml("automations.yaml"),
},
)
self.assertEqual(
@@ -56,5 +56,5 @@ class dumping_yamls_tests(TestCase):
"name: cool\n"
"google_password: !secret gpass\n"
"sensor: !include_dir_list sensors/*yaml\n"
f"automations: !include {Path('automations.yaml').absolute()}\n",
f"automations: !include automations.yaml\n",
)
+1 -1
View File
@@ -35,7 +35,7 @@ def create_dummy_config_folder(
configuration_yaml["automation"] = auto_prims
elif automation_in_conifguration_mode == "include":
configuration_yaml["automation"] = IncludedYaml(
Path(root_folder / "automations.yaml"),
"automations.yaml",
)
if automation_in_conifguration_mode != "inline":
(root_folder / "automations.yaml").write_text(dump_yaml(auto_prims))