Refactor core forms test base class

The extra child added in the base classes caused failures with the `test_child_with_one_child` test.
This commit is contained in:
Christopher C. Wells 2020-01-30 11:35:43 -08:00 committed by Christopher Charbonneau Wells
parent 1b536ff6ed
commit f7d9f6b361
1 changed files with 29 additions and 24 deletions

View File

@ -56,11 +56,6 @@ class InitialValuesTestCase(FormsTestCaseBase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(InitialValuesTestCase, cls).setUpClass() super(InitialValuesTestCase, cls).setUpClass()
cls.child_two = models.Child.objects.create(
first_name='Child',
last_name='Two',
birth_date=timezone.localdate()
)
cls.timer = models.Timer.objects.create( cls.timer = models.Timer.objects.create(
user=cls.user, user=cls.user,
start=timezone.localtime() - timezone.timedelta(minutes=30) start=timezone.localtime() - timezone.timedelta(minutes=30)
@ -71,16 +66,27 @@ class InitialValuesTestCase(FormsTestCaseBase):
self.assertEqual(page.context['form'].initial['child'], self.child) self.assertEqual(page.context['form'].initial['child'], self.child)
def test_child_with_parameter(self): def test_child_with_parameter(self):
child_two = models.Child.objects.create(
first_name='Child',
last_name='Two',
birth_date=timezone.localdate()
)
page = self.c.get('/sleep/add/') page = self.c.get('/sleep/add/')
self.assertTrue('child' not in page.context['form'].initial) self.assertTrue('child' not in page.context['form'].initial)
page = self.c.get('/sleep/add/?child={}'.format(self.child.slug)) page = self.c.get('/sleep/add/?child={}'.format(self.child.slug))
self.assertEqual(page.context['form'].initial['child'], self.child) self.assertEqual(page.context['form'].initial['child'], self.child)
page = self.c.get('/sleep/add/?child={}'.format(self.child_two.slug)) page = self.c.get('/sleep/add/?child={}'.format(child_two.slug))
self.assertEqual(page.context['form'].initial['child'], self.child_two) self.assertEqual(page.context['form'].initial['child'], child_two)
def test_feeding_type(self): def test_feeding_type(self):
child_two = models.Child.objects.create(
first_name='Child',
last_name='Two',
birth_date=timezone.localdate()
)
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=timezone.localtime() - timezone.timedelta(hours=4),
@ -89,7 +95,7 @@ class InitialValuesTestCase(FormsTestCaseBase):
method='left breast' method='left breast'
) )
f_two = models.Feeding.objects.create( f_two = models.Feeding.objects.create(
child=self.child_two, child=child_two,
start=timezone.localtime() - timezone.timedelta(hours=4), start=timezone.localtime() - timezone.timedelta(hours=4),
end=timezone.localtime() - timezone.timedelta(hours=3, minutes=30), end=timezone.localtime() - timezone.timedelta(hours=3, minutes=30),
type='formula', type='formula',
@ -102,8 +108,7 @@ class InitialValuesTestCase(FormsTestCaseBase):
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)
page = self.c.get('/feedings/add/?child={}'.format( page = self.c.get('/feedings/add/?child={}'.format(child_two.slug))
self.child_two.slug))
self.assertEqual(page.context['form'].initial['type'], f_two.type) self.assertEqual(page.context['form'].initial['type'], f_two.type)
def test_timer_set(self): def test_timer_set(self):
@ -133,16 +138,16 @@ class InitialValuesTestCase(FormsTestCaseBase):
self.assertEqual(self.localtime_string(self.timer.end), params['end']) self.assertEqual(self.localtime_string(self.timer.end), params['end'])
class ChildFormsTestCaseBase(FormsTestCaseBase): class ChildFormsTestCase(FormsTestCaseBase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(ChildFormsTestCaseBase, cls).setUpClass() super(ChildFormsTestCase, cls).setUpClass()
cls.child = models.Child.objects.first() cls.child = models.Child.objects.first()
def test_add(self): def test_add(self):
params = { params = {
'first_name': 'Child', 'first_name': 'Child',
'last_name': 'One', 'last_name': 'Two',
'birth_date': timezone.localdate() 'birth_date': timezone.localdate()
} }
page = self.c.post('/children/add/', params, follow=True) page = self.c.post('/children/add/', params, follow=True)
@ -177,10 +182,10 @@ class ChildFormsTestCaseBase(FormsTestCaseBase):
self.assertContains(page, 'Child entry deleted') self.assertContains(page, 'Child entry deleted')
class DiaperChangeFormsTestCaseBase(FormsTestCaseBase): class DiaperChangeFormsTestCase(FormsTestCaseBase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(DiaperChangeFormsTestCaseBase, cls).setUpClass() super(DiaperChangeFormsTestCase, cls).setUpClass()
cls.change = models.DiaperChange.objects.create( cls.change = models.DiaperChange.objects.create(
child=cls.child, child=cls.child,
time=timezone.localtime(), time=timezone.localtime(),
@ -237,10 +242,10 @@ class DiaperChangeFormsTestCaseBase(FormsTestCaseBase):
self.assertContains(page, 'Diaper Change entry deleted') self.assertContains(page, 'Diaper Change entry deleted')
class FeedingFormsTestCaseBase(FormsTestCaseBase): class FeedingFormsTestCase(FormsTestCaseBase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(FeedingFormsTestCaseBase, cls).setUpClass() super(FeedingFormsTestCase, cls).setUpClass()
cls.feeding = models.Feeding.objects.create( cls.feeding = models.Feeding.objects.create(
child=cls.child, child=cls.child,
start=timezone.localtime() - timezone.timedelta(hours=2), start=timezone.localtime() - timezone.timedelta(hours=2),
@ -303,10 +308,10 @@ class FeedingFormsTestCaseBase(FormsTestCaseBase):
self.assertContains(page, 'Feeding entry deleted') self.assertContains(page, 'Feeding entry deleted')
class SleepFormsTestCaseBase(FormsTestCaseBase): class SleepFormsTestCase(FormsTestCaseBase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(SleepFormsTestCaseBase, cls).setUpClass() super(SleepFormsTestCase, cls).setUpClass()
cls.sleep = models.Sleep.objects.create( cls.sleep = models.Sleep.objects.create(
child=cls.child, child=cls.child,
start=timezone.localtime() - timezone.timedelta(hours=6), start=timezone.localtime() - timezone.timedelta(hours=6),
@ -357,10 +362,10 @@ class SleepFormsTestCaseBase(FormsTestCaseBase):
self.assertContains(page, 'Sleep entry deleted') self.assertContains(page, 'Sleep entry deleted')
class TemperatureFormsTestCaseBase(FormsTestCaseBase): class TemperatureFormsTestCase(FormsTestCaseBase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(TemperatureFormsTestCaseBase, cls).setUpClass() super(TemperatureFormsTestCase, cls).setUpClass()
cls.temp = models.Temperature.objects.create( cls.temp = models.Temperature.objects.create(
child=cls.child, child=cls.child,
temperature=98.6, temperature=98.6,
@ -404,10 +409,10 @@ class TemperatureFormsTestCaseBase(FormsTestCaseBase):
self.assertContains(page, 'Temperature entry deleted') self.assertContains(page, 'Temperature entry deleted')
class TummyTimeFormsTestCaseBase(FormsTestCaseBase): class TummyTimeFormsTestCase(FormsTestCaseBase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(TummyTimeFormsTestCaseBase, cls).setUpClass() super(TummyTimeFormsTestCase, cls).setUpClass()
cls.tt = models.TummyTime.objects.create( cls.tt = models.TummyTime.objects.create(
child=cls.child, child=cls.child,
start=timezone.localtime() - timezone.timedelta(hours=2), start=timezone.localtime() - timezone.timedelta(hours=2),
@ -457,7 +462,7 @@ class TummyTimeFormsTestCaseBase(FormsTestCaseBase):
self.assertContains(page, 'Tummy Time entry deleted') self.assertContains(page, 'Tummy Time entry deleted')
class TimerFormsTestCaseBase(FormsTestCaseBase): class TimerFormsTestCase(FormsTestCaseBase):
def test_add(self): def test_add(self):
params = { params = {
'child': self.child.id, 'child': self.child.id,