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