from tests.utils import TestCaseWithDB, TestCaseWithServer
from plomtask.dating import date_in_n_days
from plomtask.days import Day
-from plomtask.exceptions import BadFormatException
class TestsSansDB(TestCase):
legal_ids = ['2024-01-01']
illegal_ids = ['foo', '2024-02-30', '2024-02-01 23:00:00']
- def test_Day_valid_date(self) -> None:
- """Test Day's date format validation and parsing."""
- with self.assertRaises(BadFormatException):
- Day('foo')
- with self.assertRaises(BadFormatException):
- Day('2024-02-30')
- with self.assertRaises(BadFormatException):
- Day('2024-02-01 23:00:00')
- self.assertEqual(datetime(2024, 1, 1), Day('2024-01-01').datetime)
+ def test_Day_datetime_weekday_neighbor_dates(self) -> None:
+ """Test Day's date parsing."""
+ self.assertEqual(datetime(2024, 5, 1), Day('2024-05-01').datetime)
+ self.assertEqual('Sunday', Day('2024-03-17').weekday)
+ self.assertEqual('2023-12-31', Day('2024-01-01').prev_date)
+ self.assertEqual('2023-03-01', Day('2023-02-28').next_date)
def test_Day_sorting(self) -> None:
"""Test sorting by .__lt__ and Day.__eq__."""
days = [day3, day1, day2]
self.assertEqual(sorted(days), [day1, day2, day3])
- def test_Day_weekday(self) -> None:
- """Test Day.weekday."""
- self.assertEqual(Day('2024-03-17').weekday, 'Sunday')
-
- def test_Day_neighbor_dates(self) -> None:
- """Test Day.prev_date and Day.next_date."""
- self.assertEqual(Day('2024-01-01').prev_date, '2023-12-31')
- self.assertEqual(Day('2023-02-28').next_date, '2023-03-01')
-
class TestsWithDB(TestCaseWithDB):
"""Tests requiring DB, but not server setup."""
self.assertEqual(todo_yes_id.enables, [])
self.assertEqual(todo_yes_id.disables, [])
- def test_Todo_by_id(self) -> None:
- """Test findability of Todos."""
- todo = Todo(1, self.proc, False, self.date1)
- todo.save(self.db_conn)
- self.assertEqual(Todo.by_id(self.db_conn, 1), todo)
- with self.assertRaises(NotFoundException):
- Todo.by_id(self.db_conn, 0)
- with self.assertRaises(NotFoundException):
- Todo.by_id(self.db_conn, 2)
-
def test_Todo_by_date(self) -> None:
"""Test findability of Todos by date."""
t1 = Todo(None, self.proc, False, self.date1)