updated api for tag support

This commit is contained in:
ari committed 2022-04-22 12:51:57 -04:00
1 parent 4f78e42699
commit baada590c5
10 files changed
+95 -69

No files matched your search

+2 -2
View File
@@ -1,7 +1,7 @@
from unittest import TestCase
from fastapi.testclient import TestClient
from src.api.app import make_app
from src.automations.types import AutomationData, AutomationMetdata
from src.automations.types import AutomationData, AutomationMetdata, ExtenededAutomationData
from tests.utils import get_example_automation_loader
@@ -108,7 +108,7 @@ class automation_update_tests(BaseTestCase):
resp = self.client.post("/automations/list", json={"limit": 1, "offset": 20})
new_auto = resp.json()["data"][0]
self.assertNotEqual(original_auto, new_auto)
self.assertEqual(AutomationData(metadata=AutomationMetdata(id="testme")).dict(), new_auto)
self.assertEqual(ExtenededAutomationData(metadata=AutomationMetdata(id="testme")).dict(), new_auto)
class automation_delete_tests(BaseTestCase):
+21 -21
View File
@@ -2,8 +2,8 @@ from unittest import TestCase
from src.automations.types import (
AutomationActionNode,
AutomationConditionNode,
AutomationData,
AutomationMetdata,
ExtenededAutomationData,
)
from src.automations.loader import load_automation
from src.yaml_serializer.types import (
@@ -16,30 +16,29 @@ class loader_tests(TestCase):
def test_load_automation_runs(self):
auto = list(
load_automation(
[
{
"id": "1616887975473",
"alias": "Home Assistant Off",
"description": "",
"trigger": [{"platform": "homeassistant", "event": "shutdown"}],
"condition": ["states(time.time) >= '10:00:00'"],
"action": [
{
"device_id": SecretValue("my_mobile_phone", "..."),
"domain": "mobile_app",
"type": "notify",
"title": "Hassio Status",
"message": "Hassio Is turning off...",
}
],
"mode": "single",
}
]
{
"id": "1616887975473",
"alias": "Home Assistant Off",
"description": "",
"trigger": [{"platform": "homeassistant", "event": "shutdown"}],
"condition": ["states(time.time) >= '10:00:00'"],
"action": [
{
"device_id": SecretValue("my_mobile_phone", "..."),
"domain": "mobile_app",
"type": "notify",
"title": "Hassio Status",
"message": "Hassio Is turning off...",
}
],
"mode": "single",
},
{}
)
)
self.assertEqual(
auto[0],
AutomationData(
ExtenededAutomationData(
metadata=AutomationMetdata(
id="1616887975473",
alias="Home Assistant Off",
@@ -63,5 +62,6 @@ class loader_tests(TestCase):
},
),
],
tags={}
),
)
+13 -13
View File
@@ -1,6 +1,6 @@
from unittest import TestCase
from src.automations.errors import FailedDeletion, InvalidAutomationFile
from src.automations.types import AutomationData, AutomationMetdata
from src.automations.types import AutomationMetdata, ExtenededAutomationData
from tests.utils import (
get_dummy_automation_loader,
get_example_automation_loader,
@@ -43,7 +43,7 @@ class manager_tests(TestCase):
[],
automation_in_conifguration_mode="none",
)
manager.update(1, AutomationData(metadata=AutomationMetdata(id="test1")))
manager.update(1, ExtenededAutomationData(metadata=AutomationMetdata(id="test1")))
auto = manager.get(0)
self.assertIsNotNone(auto)
self.assertEqual(auto.metadata.id, "test1") # type: ignore
@@ -51,7 +51,7 @@ class manager_tests(TestCase):
def test_create_automation_with_example_folder(self):
_, _, manager = get_example_automation_loader()
self.assertEqual(manager.get_total_items(), 28)
manager.update(32, AutomationData(metadata=AutomationMetdata(id="test1")))
manager.update(32, ExtenededAutomationData(metadata=AutomationMetdata(id="test1")))
auto = manager.get(28)
self.assertIsNotNone(auto)
self.assertEqual(manager.get_total_items(), 29)
@@ -60,24 +60,24 @@ class manager_tests(TestCase):
def test_update_automation(self):
_, _, manager = get_dummy_automation_loader(
[
AutomationData(metadata=AutomationMetdata(id="test1")),
AutomationData(metadata=AutomationMetdata(id="test2")),
AutomationData(metadata=AutomationMetdata(id="test3")),
ExtenededAutomationData(metadata=AutomationMetdata(id="test1")),
ExtenededAutomationData(metadata=AutomationMetdata(id="test2")),
ExtenededAutomationData(metadata=AutomationMetdata(id="test3")),
],
automation_in_conifguration_mode="none",
)
auto = manager.get(0)
self.assertEqual(auto.metadata.id, "test1") # type: ignore
manager.update(0, AutomationData(metadata=AutomationMetdata(id="toaster-7")))
manager.update(0, ExtenededAutomationData(metadata=AutomationMetdata(id="toaster-7")))
auto = manager.get(0)
self.assertEqual(auto.metadata.id, "toaster-7") # type: ignore
def test_delete_automation(self):
_, _, manager = get_dummy_automation_loader(
[
AutomationData(metadata=AutomationMetdata(id="test1")),
AutomationData(metadata=AutomationMetdata(id="test2")),
AutomationData(metadata=AutomationMetdata(id="test3")),
ExtenededAutomationData(metadata=AutomationMetdata(id="test1")),
ExtenededAutomationData(metadata=AutomationMetdata(id="test2")),
ExtenededAutomationData(metadata=AutomationMetdata(id="test3")),
],
automation_in_conifguration_mode="none",
)
@@ -90,9 +90,9 @@ class manager_tests(TestCase):
def test_failed_deletion_automation(self):
_, _, manager = get_dummy_automation_loader(
[
AutomationData(metadata=AutomationMetdata(id="test1")),
AutomationData(metadata=AutomationMetdata(id="test2")),
AutomationData(metadata=AutomationMetdata(id="test3")),
ExtenededAutomationData(metadata=AutomationMetdata(id="test1")),
ExtenededAutomationData(metadata=AutomationMetdata(id="test2")),
ExtenededAutomationData(metadata=AutomationMetdata(id="test3")),
],
automation_in_conifguration_mode="none",
)
+4 -4
View File
@@ -1,17 +1,17 @@
from pathlib import Path
from tempfile import mkdtemp
from tempfile import mktemp
from unittest import TestCase
from src.automations.tags import TagManager
class tag_tests(TestCase):
def test_load_and_save(self):
tmp_file = Path(mkdtemp())
tmp_file = Path(mktemp()).with_suffix('.yml')
tags = TagManager()
tags['id#1'] = ['home things', 'barns', 'kitchen']
tags['id#2'] = ['kitchen']
tags[0] = {'Room': "Kitchen", "Type": 'Lights'}
tags[1] = {}
tags.save(tmp_file)
loaded_tags = TagManager.load(tmp_file)