From b16ae56b9c1a5bb799594fdd759a400d40488350 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Sun, 17 Mar 2024 04:03:34 +0100 Subject: [PATCH] Require explicit call to Day.save to have any Day committed to DB. --- plomtask/days.py | 7 +++---- plomtask/http.py | 6 +++--- tests/test_days.py | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/plomtask/days.py b/plomtask/days.py index 02ad1a8..17bb463 100644 --- a/plomtask/days.py +++ b/plomtask/days.py @@ -25,10 +25,9 @@ class Day: if not self.datetime: raise HandledException(f'Given date of wrong format: {self.date}') - @classmethod - def add(cls, db_conn: DatabaseConnection, date: str): - """Add (or re-write) new Day(date) to database.""" - db_conn.exec('REPLACE INTO days VALUES (?)', (date,)) + def save(self, db_conn: DatabaseConnection): + """Add (or re-write) self to database.""" + db_conn.exec('REPLACE INTO days VALUES (?)', (self.date,)) @classmethod def from_table_row(cls, row: Row): diff --git a/plomtask/http.py b/plomtask/http.py index 2039cf9..9956a72 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -49,9 +49,9 @@ class TaskHandler(BaseHTTPRequestHandler): def do_GET_calendar(self): """Show sorted Days.""" conn = DatabaseConnection(self.server.db) - Day.add(conn, '2024-01-03') - Day.add(conn, '2024-01-01') - Day.add(conn, '2024-01-02') + Day('2024-01-03').save(conn) + Day('2024-01-01').save(conn) + Day('2024-01-02').save(conn) days = Day.all(conn) conn.commit() conn.close() diff --git a/tests/test_days.py b/tests/test_days.py index 02f72af..828e5e8 100644 --- a/tests/test_days.py +++ b/tests/test_days.py @@ -9,7 +9,7 @@ class DayTests(TestCase): """Tests for testing the days module.""" def test_Day_dates(self): - """Test Day's date format..""" + """Test Day's date format.""" with self.assertRaises(HandledException): Day('foo') with self.assertRaises(HandledException): -- 2.30.2