+
+ def test_Day_by_date(self):
+ """Test Day.by_date()."""
+ timestamp = datetime.now().timestamp()
+ db_file = DatabaseFile(f'test_db:{timestamp}')
+ db_file.remake()
+ conn = DatabaseConnection(db_file)
+ self.assertEqual(None, Day.by_date(conn, '2024-01-01'))
+ Day('2024-01-01').save(conn)
+ self.assertEqual(Day('2024-01-01'), Day.by_date(conn, '2024-01-01'))
+ conn.close()
+ remove_file(db_file.path)
+
+ def test_Day_all(self):
+ """Test Day.all(), especially in regards to date range filtering."""
+ timestamp = datetime.now().timestamp()
+ db_file = DatabaseFile(f'test_db:{timestamp}')
+ db_file.remake()
+ conn = DatabaseConnection(db_file)
+ day1 = Day('2024-01-01')
+ day2 = Day('2024-01-02')
+ day3 = Day('2024-01-03')
+ day1.save(conn)
+ day2.save(conn)
+ day3.save(conn)
+ self.assertEqual(Day.all(conn), [day1, day2, day3])
+ self.assertEqual(Day.all(conn, ('', '')), [day1, day2, day3])
+ self.assertEqual(Day.all(conn, ('2024-01-01', '2024-01-03')),
+ [day1, day2, day3])
+ self.assertEqual(Day.all(conn, ('2024-01-02', '2024-01-03')),
+ [day2, day3])
+ self.assertEqual(Day.all(conn, ('2024-01-03', '')), [day3])
+ self.assertEqual(Day.all(conn, ('2024-01-01', '')), [day1, day2, day3])
+ self.assertEqual(Day.all(conn, ('', '2024-01-02')), [day1, day2])
+ self.assertEqual(Day.all(conn, ('2024-01-03, 2024-01-01')), [])
+ conn.close()
+ remove_file(db_file.path)