mirror of https://github.com/snachodog/mybuddy.git
Correct exception catch for `timesince`
This commit is contained in:
parent
39c1e98d8c
commit
43ab2694b4
|
@ -22,7 +22,7 @@ def child_age_string(birth_date):
|
||||||
return ""
|
return ""
|
||||||
try:
|
try:
|
||||||
return timesince.timesince(birth_date, depth=1)
|
return timesince.timesince(birth_date, depth=1)
|
||||||
except (ValueError, TypeError):
|
except AttributeError:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,14 +24,32 @@ class TemplateTagsTestCase(TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_child_age_string(self):
|
def test_child_age_string(self):
|
||||||
date = timezone.localtime() - timezone.timedelta(days=0, hours=6)
|
self.assertEqual(
|
||||||
self.assertEqual("6\xa0hours", duration.child_age_string(date))
|
"6\xa0hours",
|
||||||
date = timezone.localdate() - timezone.timedelta(days=1, hours=6)
|
duration.child_age_string(
|
||||||
self.assertEqual("1\xa0day", duration.child_age_string(date))
|
timezone.localtime() - timezone.timedelta(days=0, hours=6)
|
||||||
date = timezone.localdate() - timezone.timedelta(days=45)
|
),
|
||||||
self.assertEqual("1\xa0month", duration.child_age_string(date))
|
)
|
||||||
date = timezone.localdate() - timezone.timedelta(days=95)
|
self.assertEqual(
|
||||||
self.assertEqual("3\xa0months", duration.child_age_string(date))
|
"1\xa0day",
|
||||||
|
duration.child_age_string(
|
||||||
|
timezone.localdate() - timezone.timedelta(days=1, hours=6)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
"1\xa0month",
|
||||||
|
duration.child_age_string(
|
||||||
|
timezone.localdate() - timezone.timedelta(days=45)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
"3\xa0months",
|
||||||
|
duration.child_age_string(
|
||||||
|
timezone.localdate() - timezone.timedelta(days=95)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
self.assertEqual("", duration.child_age_string(None))
|
||||||
|
self.assertEqual("", duration.child_age_string("not a date!!"))
|
||||||
|
|
||||||
def test_duration_duration_string(self):
|
def test_duration_duration_string(self):
|
||||||
delta = timezone.timedelta(hours=1, minutes=30, seconds=15)
|
delta = timezone.timedelta(hours=1, minutes=30, seconds=15)
|
||||||
|
|
Loading…
Reference in New Issue