lib: test edgecase for timedelta_from_string
This commit is contained in:
parent
1c0a6efeb1
commit
f056b026d6
|
@ -20,6 +20,8 @@ class TestTimeUtils(TestCase):
|
||||||
"""Test invalid expression"""
|
"""Test invalid expression"""
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
timedelta_from_string("foo")
|
timedelta_from_string("foo")
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
timedelta_from_string("bar=baz")
|
||||||
|
|
||||||
def test_validation(self):
|
def test_validation(self):
|
||||||
"""Test Django model field validator"""
|
"""Test Django model field validator"""
|
|
@ -35,4 +35,6 @@ def timedelta_from_string(expr: str) -> datetime.timedelta:
|
||||||
if key.lower() not in ALLOWED_KEYS:
|
if key.lower() not in ALLOWED_KEYS:
|
||||||
continue
|
continue
|
||||||
kwargs[key.lower()] = float(value)
|
kwargs[key.lower()] = float(value)
|
||||||
|
if len(kwargs) < 1:
|
||||||
|
raise ValueError("No valid keys to pass to timedelta")
|
||||||
return datetime.timedelta(**kwargs)
|
return datetime.timedelta(**kwargs)
|
||||||
|
|
Reference in New Issue