fixed test cases

This commit is contained in:
ari committed 2022-05-16 10:29:05 -04:00
1 parent edc65da14b
commit ef5e66a8f1
6 files changed
+55 -14

No files matched your search

+3 -3
View File
@@ -1,5 +1,4 @@
import os
from typing import cast
from decouple import config
from pathlib import Path
from .loader import HassConfig
@@ -15,8 +14,9 @@ def find_hass_config() -> HassConfig:
print("|-> ", path)
return HassConfig(path)
if "HASSIO_TOKEN" in os.environ:
return HassConfig(Path("/config"))
config_dir = Path("/config")
if config_dir.is_dir():
return HassConfig(config_dir)
"""Put together the default configuration directory based on the OS."""
data_dir = Path(config("APPDATA", None) if os.name == "nt" else os.path.expanduser("~"))
+1
View File
@@ -34,6 +34,7 @@ def normalize_obj(obj: Any) -> Any:
or isinstance(obj, int)
or isinstance(obj, float)
or isinstance(obj, bool)
or obj is None
):
return obj
else:
@@ -0,0 +1,15 @@
- id: '1652069225859'
alias: 'Climate - Pref temperature '
description: ''
trigger:
- platform: state
entity_id: input_number.preferred_temperature
condition: []
action:
- service: climate.set_temperature
data:
temperature:
'[object Object]':
target:
entity_id: climate.main_floor
mode: single
@@ -0,0 +1,2 @@
# empty configuration file
cloud:
+29 -7
View File
@@ -3,7 +3,7 @@ from unittest import TestCase
from fastapi.testclient import TestClient
from src.api.app import make_app
from src.automations.types import AutomationData, AutomationMetdata, ExtenededAutomationData
from tests.utils import get_example_automation_loader
from tests.utils import HA_CONFIG2_EXAMPLE, get_example_automation_loader
class BaseTestCase(TestCase):
@@ -17,6 +17,13 @@ class BaseTestCase(TestCase):
class automation_list_tests(BaseTestCase):
test_params = {
"total": 28,
"subtest2_found_items": 3,
"subtest1_found_items": 10
}
def test_get_list_of_everything(self):
data = self.client.post(
"/automations/list",
@@ -34,8 +41,8 @@ class automation_list_tests(BaseTestCase):
"limit": 50,
},
)
self.assertEqual(d["totalItems"], 28)
self.assertEqual(len(d["data"]), 28)
self.assertEqual(d["totalItems"], self.test_params['total'])
self.assertEqual(len(d["data"]), self.test_params['total'])
def test_subset1(self):
data = self.client.post(
@@ -54,8 +61,8 @@ class automation_list_tests(BaseTestCase):
"limit": 10,
},
)
self.assertEqual(d["totalItems"], 28)
self.assertEqual(len(d["data"]), 10)
self.assertEqual(d["totalItems"], self.test_params['total'])
self.assertEqual(len(d["data"]), self.test_params["subtest1_found_items"])
def test_subset2(self):
data = self.client.post(
@@ -74,8 +81,23 @@ class automation_list_tests(BaseTestCase):
"limit": 10,
},
)
self.assertEqual(d["totalItems"], 28)
self.assertEqual(len(d["data"]), 3)
self.assertEqual(d["totalItems"], self.test_params['total'])
self.assertEqual(len(d["data"]), self.test_params["subtest2_found_items"])
class automation2_lists_tests(automation_list_tests):
test_params = {
"total": 1,
"subtest2_found_items": 0,
"subtest1_found_items": 1,
}
def setUp(self) -> None:
(
self.config_folder,
self.hass_config,
self.automation_loader,
) = get_example_automation_loader(HA_CONFIG2_EXAMPLE)
self.client = TestClient(make_app(self.automation_loader))
class automation_update_tests(BaseTestCase):
+5 -4
View File
@@ -12,21 +12,22 @@ from src.yaml_serializer.types import IncludedYaml
THIS_FOLDER = Path(__file__).parent
SAMPLES_FOLDER = THIS_FOLDER / "samples"
HA_CONFIG_EXAMPLE = SAMPLES_FOLDER / "config"
HA_CONFIG2_EXAMPLE = SAMPLES_FOLDER / "config-2"
def get_example_automation_loader() -> Tuple[Path, HassConfig, AutomationManager]:
def get_example_automation_loader(config_to_copy: Path = HA_CONFIG_EXAMPLE) -> Tuple[Path, HassConfig, AutomationManager]:
"""Creates an example automation loader from the samples folder
Returns:
Tuple[Path, HassConfig, AutomationManager]
"""
root_folder = create_copy_of_example_config()
root_folder = create_copy_of_example_config(config_to_copy)
hass_config = HassConfig(root_folder)
automation_loader = AutomationManager(hass_config)
return root_folder, hass_config, automation_loader
def create_copy_of_example_config() -> Path:
def create_copy_of_example_config(config_to_copy: Path = HA_CONFIG_EXAMPLE) -> Path:
"""Creates a copy of the example config folder
Returns:
@@ -34,7 +35,7 @@ def create_copy_of_example_config() -> Path:
"""
root_folder = Path(mkdtemp())
root_folder.rmdir()
copytree(HA_CONFIG_EXAMPLE, root_folder)
copytree(config_to_copy, root_folder)
return root_folder