def test_should_read_history_from_db(self): store = LightsSqliteStore(self.test_db_file) history = store.read_history() assert_that(history, has_length(1)) entry = history[0] self.assert_entry_correct(entry)
def test_should_add_entry_to_history_db(self): store = LightsSqliteStore(self.temp_file.name) store.add_entry(True, SOURCE) conn = sqlite3.connect(self.temp_file.name) conn.row_factory = sqlite3.Row cursor = conn.cursor() rows = cursor.execute("SELECT * FROM history").fetchall() assert_that(rows, has_length(1)) entry = rows[0] assert_that(entry["timestamp"], is_(TIMESTAMP)) assert_that(entry["source"], is_(SOURCE)) assert_that(entry["state"], is_(True)) history = store.read_history() assert_that(history, has_length(1)) entry = history[0] self.assert_entry_correct(entry)