tags
This commit is contained in:
1 parent
02cbacabe0
commit
f8b59c6b17
7 files changed
+71
-56
No files matched your search
@@ -64,53 +64,3 @@ class db_tests(TestWithDB):
|
||||
autos = list(self.db.list_automations(0, 10))
|
||||
self.assertEqual(len(autos), 1)
|
||||
self.assertTrue(autos[0] == originals[1])
|
||||
|
||||
def test_delete_automations(self):
|
||||
originals = [
|
||||
ExtenededAutomation(
|
||||
id="test",
|
||||
alias="test",
|
||||
source_file="automation.yaml",
|
||||
source_file_type="obj",
|
||||
configuration_key="automation",
|
||||
),
|
||||
ExtenededAutomation(
|
||||
id="test2",
|
||||
alias="test",
|
||||
source_file="automation.yaml",
|
||||
source_file_type="obj",
|
||||
action=[{"event": {"nice": "one"}, "event_type": "custom"}],
|
||||
configuration_key="automation",
|
||||
),
|
||||
]
|
||||
self.assertEqual(self.db.count_automations(), 0)
|
||||
self.db.upsert_automations(originals)
|
||||
self.assertEqual(self.db.count_automations(), 2)
|
||||
self.db.delete_automations(originals)
|
||||
self.assertEqual(self.db.count_automations(), 0)
|
||||
|
||||
def test_delete_automations_by_source_type(self):
|
||||
originals = [
|
||||
ExtenededAutomation(
|
||||
id="test",
|
||||
alias="test",
|
||||
source_file="automation2.yaml",
|
||||
source_file_type="obj",
|
||||
configuration_key="automation",
|
||||
),
|
||||
ExtenededAutomation(
|
||||
id="test2",
|
||||
alias="test",
|
||||
source_file="automation.yaml",
|
||||
source_file_type="obj",
|
||||
action=[{"event": {"nice": "one"}, "event_type": "custom"}],
|
||||
configuration_key="automation",
|
||||
),
|
||||
]
|
||||
self.assertEqual(self.db.count_automations(), 0)
|
||||
self.db.upsert_automations(originals)
|
||||
self.assertEqual(self.db.count_automations(), 2)
|
||||
self.db.delete_automations_in_source_file(Path("automation2.yaml"))
|
||||
self.assertEqual(self.db.count_automations(), 1)
|
||||
[auto] = self.db.list_automations(0, 10)
|
||||
self.assertEqual(auto.id, "test2")
|
||||
@@ -6,6 +6,7 @@ from src.automations_v2.loader import (
|
||||
extract_automation_paths,
|
||||
load_automation_path,
|
||||
)
|
||||
from src.automations_v2.tags import TagManager
|
||||
from src.automations_v2.types import ExtenededAutomation
|
||||
from src.hass_config.loader import HassConfig
|
||||
from tests.utils import (
|
||||
@@ -22,7 +23,9 @@ class loader_tests(TestCase):
|
||||
def test_load_automation_list_file(self):
|
||||
automations = list(
|
||||
load_automation_path(
|
||||
HA_CONFIG2_EXAMPLE / "automations.yaml", configuration_key="automation"
|
||||
HA_CONFIG2_EXAMPLE / "automations.yaml",
|
||||
configuration_key="automation",
|
||||
tag_manager=TagManager({"type": "routine"}),
|
||||
)
|
||||
)
|
||||
self.assertEqual(len(automations), 1)
|
||||
@@ -36,6 +39,7 @@ class loader_tests(TestCase):
|
||||
alias="Climate - Pref temperature ",
|
||||
description="",
|
||||
mode="single",
|
||||
tags={"type": "routine"},
|
||||
trigger=[
|
||||
{
|
||||
"platform": "state",
|
||||
@@ -64,6 +68,7 @@ class loader_tests(TestCase):
|
||||
load_automation_path(
|
||||
HA_CONFIG4_EXAMPLE / "automations" / "notify_washer.yaml",
|
||||
configuration_key="automation base",
|
||||
tag_manager=TagManager({"1659114647067": {"room": "laundry"}}),
|
||||
)
|
||||
)
|
||||
self.assertEqual(len(automations), 1)
|
||||
@@ -77,6 +82,7 @@ class loader_tests(TestCase):
|
||||
alias="Notify Washer",
|
||||
description="Example",
|
||||
mode="single",
|
||||
tags={"room": "laundry"},
|
||||
trigger=[
|
||||
{
|
||||
"platform": "homeassistant",
|
||||
@@ -97,13 +103,25 @@ class loader_tests(TestCase):
|
||||
def test_load_automation_empty_file(self):
|
||||
file_path = Path(mktemp())
|
||||
file_path.touch()
|
||||
automations = list(load_automation_path(file_path, configuration_key="automation ui"))
|
||||
automations = list(
|
||||
load_automation_path(
|
||||
file_path,
|
||||
configuration_key="automation ui",
|
||||
tag_manager=TagManager(),
|
||||
)
|
||||
)
|
||||
self.assertEqual(len(automations), 0)
|
||||
|
||||
def test_load_automation_none_existing_file(self):
|
||||
file_path = Path(mktemp())
|
||||
file_path.unlink(missing_ok=True)
|
||||
automations = list(load_automation_path(file_path, configuration_key="automation manual"))
|
||||
automations = list(
|
||||
load_automation_path(
|
||||
file_path,
|
||||
configuration_key="automation manual",
|
||||
tag_manager=TagManager(),
|
||||
)
|
||||
)
|
||||
self.assertEqual(len(automations), 0)
|
||||
|
||||
def test_extract_all_automation_files(self):
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from pathlib import Path
|
||||
from tempfile import mktemp
|
||||
|
||||
from src import yaml_serializer
|
||||
from src.automations_v2.errors import (
|
||||
@@ -24,6 +25,7 @@ class manager_tests(TestWithDB):
|
||||
self.config_path = create_copy_of_example_config(ha_config_example)
|
||||
self.automation_manager = AutomationManager(
|
||||
HassConfig(self.config_path),
|
||||
Path(mktemp()),
|
||||
self.db_file,
|
||||
)
|
||||
return self.config_path, self.automation_manager
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
from pathlib import Path
|
||||
from tempfile import mktemp
|
||||
from unittest import TestCase
|
||||
|
||||
from src.automations_v2.tags import TagManager
|
||||
|
||||
|
||||
class tag_tests(TestCase):
|
||||
def test_load_and_save(self):
|
||||
tmp_file = Path(mktemp()).with_suffix(".yml")
|
||||
tags = TagManager()
|
||||
tags[0] = {"Room": "Kitchen", "Type": "Lights"}
|
||||
tags[1] = {}
|
||||
|
||||
tags.save(tmp_file)
|
||||
loaded_tags = TagManager.load(tmp_file)
|
||||
assert loaded_tags.keys() == tags.keys()
|
||||
Reference in new issue
Block a user