From: Christian Heller Date: Sun, 17 Mar 2024 03:03:34 +0000 (+0100) Subject: Require explicit call to Day.save to have any Day committed to DB. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/static/%7B%7Bprefix%7D%7D/ledger?a=commitdiff_plain;h=b16ae56b9c1a5bb799594fdd759a400d40488350;p=plomtask Require explicit call to Day.save to have any Day committed to DB. --- 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):