validatorfuncs.future must create utcnow() time-aware so comparison with generated datetime can be done.
This commit is contained in:
parent
0244518aac
commit
7f14d3a167
2 changed files with 12 additions and 12 deletions
|
|
@ -54,18 +54,18 @@ class TestValidatorFuncs(TestCase):
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
validatorfuncs.duration(d)
|
validatorfuncs.duration(d)
|
||||||
|
|
||||||
# def test_future_ok(self):
|
def test_future_ok(self):
|
||||||
# year = int(datetime.datetime.utcnow().strftime("%Y"))
|
year = int(datetime.datetime.utcnow().strftime("%Y"))
|
||||||
# for f in [f'Jan 2 12:00 {year+1}', f'Dec 31 00:00 {year+1}']:
|
for f in [f'Jan 2 12:00 {year+1}', f'Dec 31 00:00 {year+1}']:
|
||||||
# self.assertTrue(
|
self.assertTrue(
|
||||||
# isinstance(validatorfuncs.future(f, from_tz=pytz.UTC),
|
isinstance(validatorfuncs.future(f, from_tz=pytz.UTC),
|
||||||
# datetime.timedelta))
|
datetime.datetime))
|
||||||
|
|
||||||
# def test_future_raises_ValueError(self):
|
def test_future_raises_ValueError(self):
|
||||||
# year = int(datetime.datetime.utcnow().strftime("%Y"))
|
year = int(datetime.datetime.utcnow().strftime("%Y"))
|
||||||
# for f in [f'Jan 2 12:00 {year-1}', f'Dec 31 00:00 {year-1}']:
|
for f in [f'Jan 2 12:00 {year-1}', f'Dec 31 00:00 {year-1}']:
|
||||||
# with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
# validatorfuncs.future(f, from_tz=pytz.UTC)
|
validatorfuncs.future(f, from_tz=pytz.UTC)
|
||||||
|
|
||||||
def test_signed_integer_ok(self):
|
def test_signed_integer_ok(self):
|
||||||
for si in ['123', '4567890', '001', '-123', '-45', '0']:
|
for si in ['123', '4567890', '001', '-123', '-45', '0']:
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ def duration(entry, option_key="Duration", **kwargs):
|
||||||
|
|
||||||
def future(entry, option_key="Future Datetime", from_tz=None, **kwargs):
|
def future(entry, option_key="Future Datetime", from_tz=None, **kwargs):
|
||||||
time = datetime(entry, option_key, from_tz=from_tz)
|
time = datetime(entry, option_key, from_tz=from_tz)
|
||||||
if time < _dt.datetime.utcnow():
|
if time < _dt.datetime.utcnow().replace(tzinfo=_dt.timezone.utc):
|
||||||
raise ValueError(f"That {option_key} is in the past! Must give a Future datetime!")
|
raise ValueError(f"That {option_key} is in the past! Must give a Future datetime!")
|
||||||
return time
|
return time
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue