home
·
contact
·
privacy
projects
/
plomtask
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Improve InputsParser tests.
[plomtask]
/
tests
/
days.py
diff --git
a/tests/days.py
b/tests/days.py
index 1f0e55d871b282881dc0fee2f7e2fc91a591d243..286f75815ef51e74ade9e15e96bdb85dc4218a4b 100644
(file)
--- a/
tests/days.py
+++ b/
tests/days.py
@@
-2,7
+2,8
@@
from unittest import TestCase
from datetime import datetime
from tests.utils import TestCaseWithDB, TestCaseWithServer
from unittest import TestCase
from datetime import datetime
from tests.utils import TestCaseWithDB, TestCaseWithServer
-from plomtask.days import Day, todays_date
+from plomtask.dating import date_in_n_days
+from plomtask.days import Day
from plomtask.exceptions import BadFormatException
from plomtask.exceptions import BadFormatException
@@
-42,8
+43,12
@@
class TestsWithDB(TestCaseWithDB):
checked_class = Day
default_ids = ('2024-01-01', '2024-01-02', '2024-01-03')
checked_class = Day
default_ids = ('2024-01-01', '2024-01-02', '2024-01-03')
- def test_Day_saving_and_caching(self) -> None:
- """Test .save/.save_core."""
+ def test_saving_and_caching(self) -> None:
+ """Test storage of instances.
+
+ We don't use the parent class's method here because the checked class
+ has too different a handling of IDs.
+ """
kwargs = {'date': self.default_ids[0], 'comment': 'foo'}
self.check_saving_and_caching(**kwargs)
kwargs = {'date': self.default_ids[0], 'comment': 'foo'}
self.check_saving_and_caching(**kwargs)
@@
-55,40
+60,38
@@
class TestsWithDB(TestCaseWithDB):
"""Test .by_id()."""
self.check_by_id()
"""Test .by_id()."""
self.check_by_id()
- def test_Day_
all
(self) -> None:
- """Test Day.
all(), especially in regards to date range filtering
."""
+ def test_Day_
by_date_range_filled
(self) -> None:
+ """Test Day.
by_date_range_filled
."""
date1, date2, date3 = self.default_ids
day1, day2, day3 = self.check_all()
date1, date2, date3 = self.default_ids
day1, day2, day3 = self.check_all()
- self.assertEqual(Day.all(self.db_conn, ('', '')),
- [day1, day2, day3])
# check date range is a closed interval
# check date range is a closed interval
- self.assertEqual(Day.
all(self.db_conn, (date1, date3)
),
+ self.assertEqual(Day.
by_date_range_filled(self.db_conn, date1, date3
),
[day1, day2, day3])
# check first date range value excludes what's earlier
[day1, day2, day3])
# check first date range value excludes what's earlier
- self.assertEqual(Day.
all(self.db_conn, (date2, date3)
),
+ self.assertEqual(Day.
by_date_range_filled(self.db_conn, date2, date3
),
[day2, day3])
[day2, day3])
- self.assertEqual(Day.all(self.db_conn, (date3, '')),
- [day3])
# check second date range value excludes what's later
# check second date range value excludes what's later
- self.assertEqual(Day.
all(self.db_conn, ('', date2)
),
+ self.assertEqual(Day.
by_date_range_filled(self.db_conn, date1, date2
),
[day1, day2])
# check swapped (impossible) date range returns emptiness
[day1, day2])
# check swapped (impossible) date range returns emptiness
- self.assertEqual(Day.
all(self.db_conn, (date3, date1)
),
+ self.assertEqual(Day.
by_date_range_filled(self.db_conn, date3, date1
),
[])
# check fill_gaps= instantiates unsaved dates within date range
# (but does not store them)
[])
# check fill_gaps= instantiates unsaved dates within date range
# (but does not store them)
- day4 = Day('2024-01-04')
day5 = Day('2024-01-05')
day6 = Day('2024-01-06')
day6.save(self.db_conn)
day5 = Day('2024-01-05')
day6 = Day('2024-01-06')
day6.save(self.db_conn)
- self.assertEqual(Day.all(self.db_conn, (date2, '2024-01-07'),
- fill_gaps=True),
- [day2, day3, day4, day5, day6])
+ day7 = Day('2024-01-07')
+ self.assertEqual(Day.by_date_range_filled(self.db_conn,
+ day5.date, day7.date),
+ [day5, day6, day7])
self.check_storage([day1, day2, day3, day6])
# check 'today' is interpreted as today's date
self.check_storage([day1, day2, day3, day6])
# check 'today' is interpreted as today's date
- today = Day(
todays_date(
))
+ today = Day(
date_in_n_days(0
))
today.save(self.db_conn)
today.save(self.db_conn)
- self.assertEqual(Day.all(self.db_conn, ('today', 'today')), [today])
+ self.assertEqual(Day.by_date_range_filled(self.db_conn,
+ 'today', 'today'),
+ [today])
def test_Day_remove(self) -> None:
"""Test .remove() effects on DB and cache."""
def test_Day_remove(self) -> None:
"""Test .remove() effects on DB and cache."""
@@
-96,7
+99,7
@@
class TestsWithDB(TestCaseWithDB):
def test_Day_singularity(self) -> None:
"""Test pointers made for single object keep pointing to it."""
def test_Day_singularity(self) -> None:
"""Test pointers made for single object keep pointing to it."""
- self.check_singularity('comment', 'boo')
+ self.check_singularity('
day_
comment', 'boo')
class TestsWithServer(TestCaseWithServer):
class TestsWithServer(TestCaseWithServer):
@@
-115,8
+118,8
@@
class TestsWithServer(TestCaseWithServer):
def test_do_POST_day(self) -> None:
"""Test POST /day."""
def test_do_POST_day(self) -> None:
"""Test POST /day."""
- form_data = {'
comment': '
'}
+ form_data = {'
day_comment': '', 'make_type': 'full
'}
self.check_post(form_data, '/day', 400)
self.check_post(form_data, '/day?date=foo', 400)
self.check_post(form_data, '/day', 400)
self.check_post(form_data, '/day?date=foo', 400)
- self.check_post(form_data, '/day?date=2024-01-01', 302)
+ self.check_post(form_data, '/day?date=2024-01-01
&make_type=full
', 302)
self.check_post({'foo': ''}, '/day?date=2024-01-01', 400)
self.check_post({'foo': ''}, '/day?date=2024-01-01', 400)