This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2020-02-14 14:19:48 +00:00
|
|
|
"""Test time utils"""
|
|
|
|
from datetime import timedelta
|
|
|
|
|
|
|
|
from django.core.exceptions import ValidationError
|
|
|
|
from django.test import TestCase
|
|
|
|
|
2020-07-20 09:35:16 +00:00
|
|
|
from passbook.lib.utils.time import timedelta_from_string, timedelta_string_validator
|
2020-02-14 14:19:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestTimeUtils(TestCase):
|
|
|
|
"""Test time-utils"""
|
|
|
|
|
|
|
|
def test_valid(self):
|
|
|
|
"""Test valid expression"""
|
|
|
|
expr = "hours=3;minutes=1"
|
|
|
|
expected = timedelta(hours=3, minutes=1)
|
|
|
|
self.assertEqual(timedelta_from_string(expr), expected)
|
|
|
|
|
|
|
|
def test_invalid(self):
|
|
|
|
"""Test invalid expression"""
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
timedelta_from_string("foo")
|
|
|
|
|
|
|
|
def test_validation(self):
|
|
|
|
"""Test Django model field validator"""
|
|
|
|
with self.assertRaises(ValidationError):
|
|
|
|
timedelta_string_validator("foo")
|