home · contact · privacy
Require explicit call to Day.save to have any Day committed to DB.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 17 Mar 2024 03:03:34 +0000 (04:03 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 17 Mar 2024 03:03:34 +0000 (04:03 +0100)
plomtask/days.py
plomtask/http.py
tests/test_days.py

index 02ad1a8f5223e1dbaee1ef445fd4e9b211ad4842..17bb46329760beb078a6497d68bd7b0a39a05e3e 100644 (file)
@@ -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):
index 2039cf91351db9c866fa75c3ec4c974d388490ce..9956a7251501758d795032903afb0d52c0e195b6 100644 (file)
@@ -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()
index 02f72af140dd13cbc189af14ade4b856cf1a4c63..828e5e895f8a53c6ad71bb65c151721ec6b7a5a7 100644 (file)
@@ -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):