mirror of
https://github.com/evennia/evennia.git
synced 2026-04-01 13:37:17 +02:00
validatorfuncs.future must create utcnow() time-aware so comparison with generated datetime can be done.
This commit is contained in:
parent
84cd18ce74
commit
b1683219ac
2 changed files with 12 additions and 12 deletions
|
|
@ -54,18 +54,18 @@ class TestValidatorFuncs(TestCase):
|
|||
with self.assertRaises(ValueError):
|
||||
validatorfuncs.duration(d)
|
||||
|
||||
# def test_future_ok(self):
|
||||
# year = int(datetime.datetime.utcnow().strftime("%Y"))
|
||||
# for f in [f'Jan 2 12:00 {year+1}', f'Dec 31 00:00 {year+1}']:
|
||||
# self.assertTrue(
|
||||
# isinstance(validatorfuncs.future(f, from_tz=pytz.UTC),
|
||||
# datetime.timedelta))
|
||||
def test_future_ok(self):
|
||||
year = int(datetime.datetime.utcnow().strftime("%Y"))
|
||||
for f in [f'Jan 2 12:00 {year+1}', f'Dec 31 00:00 {year+1}']:
|
||||
self.assertTrue(
|
||||
isinstance(validatorfuncs.future(f, from_tz=pytz.UTC),
|
||||
datetime.datetime))
|
||||
|
||||
# def test_future_raises_ValueError(self):
|
||||
# year = int(datetime.datetime.utcnow().strftime("%Y"))
|
||||
# for f in [f'Jan 2 12:00 {year-1}', f'Dec 31 00:00 {year-1}']:
|
||||
# with self.assertRaises(ValueError):
|
||||
# validatorfuncs.future(f, from_tz=pytz.UTC)
|
||||
def test_future_raises_ValueError(self):
|
||||
year = int(datetime.datetime.utcnow().strftime("%Y"))
|
||||
for f in [f'Jan 2 12:00 {year-1}', f'Dec 31 00:00 {year-1}']:
|
||||
with self.assertRaises(ValueError):
|
||||
validatorfuncs.future(f, from_tz=pytz.UTC)
|
||||
|
||||
def test_signed_integer_ok(self):
|
||||
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):
|
||||
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!")
|
||||
return time
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue