def setUp(self) -> None:
super().setUp()
self.db_conn.exec(SQL_TEST_TABLE)
+ self.test_parent = TestParentType(1)
+ self.attr = VersionedAttribute(self.test_parent,
+ 'versioned_tests', 'A')
def test_VersionedAttribute_save(self) -> None:
"""Test .save() to write to DB."""
- test_parent = TestParentType(1)
- attr = VersionedAttribute(test_parent, 'versioned_tests', 'A')
# check mere .set() calls do not by themselves reflect in the DB
- attr.set('B')
+ self.attr.set('B')
self.assertEqual([],
self.db_conn.row_where('versioned_tests',
'parent', 1))
# check .save() makes history appear in DB
- attr.save(self.db_conn)
+ self.attr.save(self.db_conn)
vals_found = []
for row in self.db_conn.row_where('versioned_tests', 'parent', 1):
vals_found += [row[2]]
self.assertEqual(['B'], vals_found)
# check .save() also updates history in DB
- attr.set('C')
- attr.save(self.db_conn)
+ self.attr.set('C')
+ self.attr.save(self.db_conn)
vals_found = []
for row in self.db_conn.row_where('versioned_tests', 'parent', 1):
vals_found += [row[2]]
def test_VersionedAttribute_history_from_row(self) -> None:
""""Test .history_from_row() properly interprets DB rows."""
- test_parent = TestParentType(1)
- attr = VersionedAttribute(test_parent, 'versioned_tests', 'A')
- attr.set('B')
- attr.set('C')
- attr.save(self.db_conn)
- loaded_attr = VersionedAttribute(test_parent, 'versioned_tests', 'A')
+ self.attr.set('B')
+ self.attr.set('C')
+ self.attr.save(self.db_conn)
+ loaded_attr = VersionedAttribute(self.test_parent,
+ 'versioned_tests', 'A')
for row in self.db_conn.row_where('versioned_tests', 'parent', 1):
loaded_attr.history_from_row(row)
- for timestamp, value in attr.history.items():
+ for timestamp, value in self.attr.history.items():
self.assertEqual(value, loaded_attr.history[timestamp])
- self.assertEqual(len(attr.history.keys()),
+ self.assertEqual(len(self.attr.history.keys()),
len(loaded_attr.history.keys()))