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 9e12d3ff665550f3fb23bb603e639ce8efbf60ff..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
@@
-59,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."""
@@
-119,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 = {'day_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)