class TestsWithDB(TestCaseWithDB):
"""Tests requiring DB, but not server setup."""
checked_class = Condition
-
- def test_Condition_saving_and_caching(self) -> None:
- """Test .save/.save_core."""
- kwargs = {'id_': 1, 'is_active': False}
- self.check_saving_and_caching(**kwargs)
- # check .id_ set if None, and versioned attributes too
- c = Condition(None)
- c.save(self.db_conn)
- self.assertEqual(c.id_, 2)
- self.check_saving_of_versioned('title', str)
- self.check_saving_of_versioned('description', str)
+ default_init_kwargs = {'is_active': False}
+ test_versioneds = {'title': str, 'description': str}
def test_Condition_from_table_row(self) -> None:
"""Test .from_table_row() properly reads in class from DB"""
checked_class = Day
default_ids = ('2024-01-01', '2024-01-02', '2024-01-03')
- def test_Day_saving_and_caching(self) -> None:
- """Test .save/.save_core."""
+ def test_saving_and_caching(self) -> None:
+ """Test storage of instances.
+
+ We don't use the parent class's method here because the checked class
+ has too different a handling of IDs.
+ """
kwargs = {'date': self.default_ids[0], 'comment': 'foo'}
self.check_saving_and_caching(**kwargs)
class TestsWithDB(TestCaseWithDB):
"""Module tests requiring DB setup."""
checked_class = Process
+ test_versioneds = {'title': str, 'description': str, 'effort': float}
def three_processes(self) -> tuple[Process, Process, Process]:
"""Return three saved processes."""
p.save(self.db_conn)
return p, set_1, set_2, set_3
- def test_Process_saving_and_caching(self) -> None:
+ def test_Process_conditions_saving(self) -> None:
"""Test .save/.save_core."""
- kwargs = {'id_': 1}
- self.check_saving_and_caching(**kwargs)
- self.check_saving_of_versioned('title', str)
- self.check_saving_of_versioned('description', str)
- self.check_saving_of_versioned('effort', float)
p, set1, set2, set3 = self.p_of_conditions()
p.uncache()
r = Process.by_id(self.db_conn, p.id_)
class TestsWithDBForProcessStep(TestCaseWithDB):
"""Module tests requiring DB setup."""
checked_class = ProcessStep
-
- def test_ProcessStep_saving_and_caching(self) -> None:
- """Test .save/.save_core."""
- kwargs = {'id_': 1,
- 'owner_id': 2,
- 'step_process_id': 3,
- 'parent_step_id': 4}
- self.check_saving_and_caching(**kwargs)
+ default_init_kwargs = {'owner_id': 2, 'step_process_id': 3,
+ 'parent_step_id': 4}
def test_ProcessStep_from_table_row(self) -> None:
"""Test .from_table_row() properly reads in class from DB"""
class TestsWithDB(TestCaseWithDB):
"""Tests requiring DB, but not server setup."""
checked_class = Todo
+ default_init_kwargs = {'process': None, 'is_done': False,
+ 'date': '2024-01-01'}
def setUp(self) -> None:
super().setUp()
self.cond1.save(self.db_conn)
self.cond2 = Condition(None)
self.cond2.save(self.db_conn)
+ self.default_init_kwargs['process'] = self.proc
def test_Todo_init(self) -> None:
"""Test creation of Todo and what they default to."""
self.assertEqual(todo_yes_id.enables, [])
self.assertEqual(todo_yes_id.disables, [])
- def test_Todo_saving_and_caching(self) -> None:
- """Test .save."""
- kwargs = {'id_': 1,
- 'process': self.proc,
- 'is_done': False,
- 'date': self.date1}
- self.check_saving_and_caching(**kwargs)
- todo = Todo(None, self.proc, False, self.date1)
- todo.save(self.db_conn)
- self.assertEqual(todo.id_, 2)
-
def test_Todo_by_id(self) -> None:
"""Test findability of Todos."""
todo = Todo(1, self.proc, False, self.date1)
"""Module tests not requiring DB setup."""
checked_class: Any
default_ids: tuple[int | str, int | str, int | str] = (1, 2, 3)
+ default_init_kwargs: dict[str, Any] = {}
+ test_versioneds: dict[str, type] = {}
def setUp(self) -> None:
Condition.empty_cache()
self.db_conn.close()
remove_file(self.db_file.path)
+ def test_saving_and_caching(self) -> None:
+ """Test storage and initialization of instances and attributes."""
+ if not hasattr(self, 'checked_class'):
+ return
+ self.check_saving_and_caching(id_=1, **self.default_init_kwargs)
+ obj = self.checked_class(None, **self.default_init_kwargs)
+ obj.save(self.db_conn)
+ self.assertEqual(obj.id_, 2)
+ for k, v in self.test_versioneds.items():
+ self.check_saving_of_versioned(k, v)
+
def check_storage(self, content: list[Any]) -> None:
"""Test cache and DB equal content."""
expected_cache = {}