using in-memory db

This commit is contained in:
ari committed 2022-08-31 15:44:52 -04:00
1 parent 00c234541d
commit 499752e02f
6 files changed
+51 -115

No files matched your search

+3 -14
View File
@@ -1,23 +1,12 @@
from pathlib import Path
from src.automations.errors import DBDataError
from src.automations.errors import DBDataError, RepeatedAutomationId
from src.automations.types import ExtenededAutomation
from .utils import TestWithDB
class db_tests(TestWithDB):
def test_db_creation(self):
with self.db.get_cur() as cur:
cur.execute("SELECT name FROM sqlite_master WHERE type ='table'")
tables = cur.fetchall()
self.assertListEqual(tables, [("autos",)])
self.db.create_db()
with self.db.get_cur() as cur:
cur.execute("SELECT name FROM sqlite_master WHERE type ='table'")
tables = cur.fetchall()
self.assertListEqual(tables, [("autos",)])
def test_insert_automations(self):
originals = [
ExtenededAutomation(
@@ -61,7 +50,7 @@ class db_tests(TestWithDB):
configuration_key=["automation"],
),
]
with self.assertRaises(DBDataError) as err:
with self.assertRaises(RepeatedAutomationId):
self.db.insert_automations(originals)
autos = list(self.db.list_automations(0, 10))
self.assertEqual(len(autos), 0)
self.assertEqual(len(autos), 1)
@@ -28,7 +28,6 @@ class manager_tests(TestWithDB):
self.config_path = create_copy_of_example_config(ha_config_example)
self.automation_manager = AutomationManager(
HassConfig(self.config_path),
self.db_file,
)
return self.config_path, self.automation_manager
@@ -54,10 +53,6 @@ class manager_tests(TestWithDB):
{"platform": "zone", "entity_id": "person.thor", "zone": "zone.azguard"}
)
automation_manager.update(automation)
self.assertEqual(
automation_manager.get("sublist3-mlist2").trigger,
[],
)
automation_manager.reload()
self.assertEqual(
automation_manager.get("sublist3-mlist2").trigger,
+1 -12
View File
@@ -1,19 +1,8 @@
from pathlib import Path
from tempfile import mktemp
from unittest import TestCase
from src.automations.db import AutomationDBConnection
def make_temp_db():
return AutomationDBConnection(Path(mktemp() + ".db"))
class TestWithDB(TestCase):
def setUp(self) -> None:
self.db = make_temp_db()
self.db.create_db()
self.db_file = self.db.db_file
def tearDown(self) -> None:
self.db_file.unlink()
self.db = AutomationDBConnection()