From 1b536ff6ed08e5011cf087ab193f77808c2e282f Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Thu, 30 Jan 2020 11:30:41 -0800 Subject: [PATCH] Update tests for timers list template tag --- dashboard/tests/tests_templatetags.py | 39 +++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/dashboard/tests/tests_templatetags.py b/dashboard/tests/tests_templatetags.py index 0c009489..849d5f22 100644 --- a/dashboard/tests/tests_templatetags.py +++ b/dashboard/tests/tests_templatetags.py @@ -115,10 +115,45 @@ class TemplateTagsTestCase(TestCase): self.assertEqual(data['stats'], stats) def test_card_timer_list(self): - models.Timer(user=User.objects.first()).save() + user = User.objects.first() + child = models.Child.objects.first() + child_two = models.Child.objects.create( + first_name='Child', + last_name='Two', + birth_date=timezone.localdate() + ) + timers = { + 'no_child': models.Timer.objects.create( + user=user, + start=timezone.localtime() - timezone.timedelta(hours=3) + ), + 'child': models.Timer.objects.create( + user=user, + child=child, + start=timezone.localtime() - timezone.timedelta(hours=2) + ), + 'child_two': models.Timer.objects.create( + user=user, + child=child_two, + start=timezone.localtime() - timezone.timedelta(hours=1) + ), + } + data = cards.card_timer_list() self.assertIsInstance(data['instances'][0], models.Timer) - self.assertEqual(data['instances'][0], models.Timer.objects.first()) + self.assertEqual(len(data['instances']), 3) + + data = cards.card_timer_list(child) + self.assertIsInstance(data['instances'][0], models.Timer) + self.assertTrue(timers['no_child'] in data['instances']) + self.assertTrue(timers['child'] in data['instances']) + self.assertFalse(timers['child_two'] in data['instances']) + + data = cards.card_timer_list(child_two) + self.assertIsInstance(data['instances'][0], models.Timer) + self.assertTrue(timers['no_child'] in data['instances']) + self.assertTrue(timers['child_two'] in data['instances']) + self.assertFalse(timers['child'] in data['instances']) def test_card_tummytime_last(self): data = cards.card_tummytime_last(self.child)