Tests for initial feeding methods (#127)

This commit is contained in:
Peter Hardy 2020-03-28 21:54:07 +11:00
parent 4581722e0b
commit dfd89ae339
1 changed files with 24 additions and 4 deletions

View File

@ -87,29 +87,49 @@ class InitialValuesTestCase(FormsTestCaseBase):
last_name='Two', last_name='Two',
birth_date=timezone.localdate() birth_date=timezone.localdate()
) )
child_three = models.Child.objects.create(
first_name='Child',
last_name='Three',
birth_date=timezone.localdate()
)
start_time = timezone.localtime() - timezone.timedelta(hours=4)
end_time = timezone.localtime() - timezone.timedelta(hours=3, minutes=30)
f_one = models.Feeding.objects.create( f_one = models.Feeding.objects.create(
child=self.child, child=self.child,
start=timezone.localtime() - timezone.timedelta(hours=4), start=start_time,
end=timezone.localtime() - timezone.timedelta(hours=3, minutes=30), end=end_time,
type='breast milk', type='breast milk',
method='left breast' method='left breast'
) )
f_two = models.Feeding.objects.create( f_two = models.Feeding.objects.create(
child=child_two, child=child_two,
start=timezone.localtime() - timezone.timedelta(hours=4), start=start_time,
end=timezone.localtime() - timezone.timedelta(hours=3, minutes=30), end=end_time,
type='formula', type='formula',
method='bottle' method='bottle'
) )
f_three = models.Feeding.objects.create(
child=child_three,
start=start_time,
end=end_time,
type='fortified breast milk',
method='bottle'
)
page = self.c.get('/feedings/add/') page = self.c.get('/feedings/add/')
self.assertTrue('type' not in page.context['form'].initial) self.assertTrue('type' not in page.context['form'].initial)
page = self.c.get('/feedings/add/?child={}'.format(self.child.slug)) page = self.c.get('/feedings/add/?child={}'.format(self.child.slug))
self.assertEqual(page.context['form'].initial['type'], f_one.type) self.assertEqual(page.context['form'].initial['type'], f_one.type)
self.assertFalse('method' in page.context['form'].initial)
page = self.c.get('/feedings/add/?child={}'.format(child_two.slug)) page = self.c.get('/feedings/add/?child={}'.format(child_two.slug))
self.assertEqual(page.context['form'].initial['type'], f_two.type) self.assertEqual(page.context['form'].initial['type'], f_two.type)
self.assertEqual(page.context['form'].initial['method'], f_two.method)
page = self.c.get('/feedings/add/?child={}'.format(child_three.slug))
self.assertEqual(page.context['form'].initial['type'], f_three.type)
self.assertEqual(page.context['form'].initial['method'], f_three.method)
def test_timer_set(self): def test_timer_set(self):
self.timer.stop() self.timer.stop()