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):
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()
"""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):