2017-10-25 14:20:13 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.core.management import call_command
|
|
|
|
from django.test import TestCase
|
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
|
from core import models
|
|
|
|
|
|
|
|
|
|
|
|
class ChildTestCase(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
call_command('migrate', verbosity=0)
|
|
|
|
|
|
|
|
def test_child_create(self):
|
|
|
|
child = models.Child.objects.create(
|
|
|
|
first_name='First',
|
|
|
|
last_name='Last',
|
|
|
|
birth_date=timezone.localdate()
|
|
|
|
)
|
|
|
|
self.assertEqual(child, models.Child.objects.get(first_name='First'))
|
|
|
|
self.assertEqual(child.slug, 'first-last')
|
|
|
|
self.assertEqual(str(child), 'First Last')
|
|
|
|
self.assertEqual(child.name(), 'First Last')
|
|
|
|
self.assertEqual(child.name(reverse=True), 'Last, First')
|
|
|
|
|
|
|
|
|
|
|
|
class DiaperChangeTestCase(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
call_command('migrate', verbosity=0)
|
|
|
|
self.child = models.Child.objects.create(
|
|
|
|
first_name='First',
|
|
|
|
last_name='Last',
|
|
|
|
birth_date=timezone.localdate()
|
|
|
|
)
|
|
|
|
self.change = models.DiaperChange.objects.create(
|
|
|
|
child=self.child,
|
|
|
|
time=timezone.localtime() - timezone.timedelta(days=1),
|
|
|
|
wet=1,
|
|
|
|
solid=1,
|
|
|
|
color='black'
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_diaperchange_create(self):
|
|
|
|
self.assertEqual(self.change, models.DiaperChange.objects.first())
|
|
|
|
self.assertEqual(str(self.change), 'Diaper Change')
|
|
|
|
|
|
|
|
def test_diaperchange_attributes(self):
|
|
|
|
self.assertListEqual(
|
|
|
|
self.change.attributes(), ['wet', 'solid', 'black'])
|
|
|
|
|
|
|
|
|
2019-05-02 17:19:56 +00:00
|
|
|
class FeedingTestCase(TestCase):
|
2017-10-25 14:20:13 +00:00
|
|
|
def setUp(self):
|
|
|
|
call_command('migrate', verbosity=0)
|
|
|
|
self.child = models.Child.objects.create(
|
|
|
|
first_name='First',
|
|
|
|
last_name='Last',
|
|
|
|
birth_date=timezone.localdate()
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_feeding_create(self):
|
|
|
|
feeding = models.Feeding.objects.create(
|
|
|
|
child=self.child,
|
|
|
|
start=timezone.localtime() - timezone.timedelta(minutes=30),
|
|
|
|
end=timezone.localtime(),
|
|
|
|
type='formula',
|
|
|
|
method='bottle',
|
|
|
|
amount=2
|
|
|
|
)
|
|
|
|
self.assertEqual(feeding, models.Feeding.objects.first())
|
|
|
|
self.assertEqual(str(feeding), 'Feeding')
|
2017-10-25 16:01:43 +00:00
|
|
|
self.assertEqual(feeding.duration, feeding.end - feeding.start)
|
2017-10-25 14:20:13 +00:00
|
|
|
|
2019-05-02 17:19:56 +00:00
|
|
|
def test_method_both_breasts(self):
|
|
|
|
feeding = models.Feeding.objects.create(
|
|
|
|
child=self.child,
|
|
|
|
start=timezone.localtime() - timezone.timedelta(minutes=30),
|
|
|
|
end=timezone.localtime(),
|
|
|
|
type='breast milk',
|
|
|
|
method='both breasts'
|
|
|
|
)
|
|
|
|
self.assertEqual(feeding, models.Feeding.objects.first())
|
|
|
|
self.assertEqual(str(feeding), 'Feeding')
|
|
|
|
self.assertEqual(feeding.method, 'both breasts')
|
|
|
|
|
2017-10-25 14:20:13 +00:00
|
|
|
|
|
|
|
class NoteTestCase(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
call_command('migrate', verbosity=0)
|
|
|
|
self.child = models.Child.objects.create(
|
|
|
|
first_name='First',
|
|
|
|
last_name='Last',
|
|
|
|
birth_date=timezone.localdate()
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_note_create(self):
|
|
|
|
note = models.Note.objects.create(
|
|
|
|
child=self.child, note='Note', time=timezone.localtime())
|
|
|
|
self.assertEqual(note, models.Note.objects.first())
|
|
|
|
self.assertEqual(str(note), 'Note')
|
|
|
|
|
|
|
|
|
|
|
|
class SleepTestCase(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
call_command('migrate', verbosity=0)
|
|
|
|
self.child = models.Child.objects.create(
|
|
|
|
first_name='First',
|
|
|
|
last_name='Last',
|
|
|
|
birth_date=timezone.localdate()
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_sleep_create(self):
|
|
|
|
sleep = models.Sleep.objects.create(
|
|
|
|
child=self.child,
|
|
|
|
start=timezone.localtime() - timezone.timedelta(minutes=30),
|
|
|
|
end=timezone.localtime(),
|
|
|
|
)
|
|
|
|
self.assertEqual(sleep, models.Sleep.objects.first())
|
|
|
|
self.assertEqual(str(sleep), 'Sleep')
|
2017-10-25 16:01:43 +00:00
|
|
|
self.assertEqual(sleep.duration, sleep.end - sleep.start)
|
2017-10-25 14:20:13 +00:00
|
|
|
|
|
|
|
|
2019-05-17 04:33:26 +00:00
|
|
|
class TemperatureTestCase(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
call_command('migrate', verbosity=0)
|
|
|
|
self.child = models.Child.objects.create(
|
|
|
|
first_name='First',
|
|
|
|
last_name='Last',
|
|
|
|
birth_date=timezone.localdate()
|
|
|
|
)
|
|
|
|
self.temp = models.Temperature.objects.create(
|
|
|
|
child=self.child,
|
|
|
|
time=timezone.localtime() - timezone.timedelta(days=1),
|
|
|
|
temperature=98.6
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_temperature_create(self):
|
|
|
|
self.assertEqual(self.temp, models.Temperature.objects.first())
|
|
|
|
self.assertEqual(str(self.temp), 'Temperature')
|
|
|
|
self.assertEqual(self.temp.temperature, 98.6)
|
|
|
|
|
|
|
|
|
2017-10-25 14:20:13 +00:00
|
|
|
class TimerTestCase(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
call_command('migrate', verbosity=0)
|
|
|
|
self.named = models.Timer.objects.create(
|
|
|
|
name='Named',
|
|
|
|
end=timezone.localtime(),
|
|
|
|
user=User.objects.first()
|
|
|
|
)
|
|
|
|
self.unnamed = models.Timer.objects.create(
|
|
|
|
end=timezone.localtime(),
|
|
|
|
user=User.objects.first()
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_timer_create(self):
|
|
|
|
self.assertEqual(self.named, models.Timer.objects.get(name='Named'))
|
|
|
|
self.assertEqual(str(self.named), 'Named')
|
|
|
|
self.assertEqual(self.unnamed, models.Timer.objects.get(name=None))
|
|
|
|
self.assertEqual(
|
|
|
|
str(self.unnamed), 'Timer #{}'.format(self.unnamed.id))
|
|
|
|
|
|
|
|
def test_timer_restart(self):
|
|
|
|
self.named.restart()
|
|
|
|
self.assertIsNone(self.named.end)
|
|
|
|
self.assertIsNone(self.named.duration)
|
|
|
|
self.assertTrue(self.named.active)
|
|
|
|
|
|
|
|
def test_timer_stop(self):
|
|
|
|
stop_time = timezone.localtime()
|
|
|
|
self.unnamed.stop(end=stop_time)
|
|
|
|
self.assertEqual(self.unnamed.end, stop_time)
|
|
|
|
self.assertEqual(
|
2017-10-25 16:01:43 +00:00
|
|
|
self.unnamed.duration.seconds,
|
|
|
|
(self.unnamed.end - self.unnamed.start).seconds)
|
2017-10-25 14:20:13 +00:00
|
|
|
self.assertFalse(self.unnamed.active)
|
|
|
|
|
2017-10-28 02:36:26 +00:00
|
|
|
def test_timer_duration(self):
|
2017-10-25 14:20:13 +00:00
|
|
|
timer = models.Timer.objects.create(user=User.objects.first())
|
|
|
|
# Timer.start uses auto_now_add, so it cannot be set in create().
|
|
|
|
timer.start = timezone.localtime() - timezone.timedelta(minutes=30)
|
|
|
|
timer.save()
|
2017-10-28 02:36:26 +00:00
|
|
|
timer.refresh_from_db()
|
2017-10-25 14:20:13 +00:00
|
|
|
|
|
|
|
self.assertEqual(
|
2017-10-28 02:36:26 +00:00
|
|
|
timer.duration.seconds,
|
2017-10-25 16:01:43 +00:00
|
|
|
timezone.timedelta(minutes=30).seconds)
|
2017-10-25 14:20:13 +00:00
|
|
|
timer.stop()
|
|
|
|
self.assertEqual(
|
2017-10-28 02:36:26 +00:00
|
|
|
timer.duration.seconds,
|
2017-10-25 16:01:43 +00:00
|
|
|
timezone.timedelta(minutes=30).seconds)
|
2017-10-25 14:20:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TummyTimeTestCase(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
call_command('migrate', verbosity=0)
|
|
|
|
self.child = models.Child.objects.create(
|
|
|
|
first_name='First',
|
|
|
|
last_name='Last',
|
|
|
|
birth_date=timezone.localdate()
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_tummytime_create(self):
|
|
|
|
tummy_time = models.TummyTime.objects.create(
|
|
|
|
child=self.child,
|
|
|
|
start=timezone.localtime() - timezone.timedelta(minutes=30),
|
|
|
|
end=timezone.localtime(),
|
|
|
|
)
|
|
|
|
self.assertEqual(tummy_time, models.TummyTime.objects.first())
|
|
|
|
self.assertEqual(str(tummy_time), 'Tummy Time')
|
2017-10-25 16:01:43 +00:00
|
|
|
self.assertEqual(
|
|
|
|
tummy_time.duration, tummy_time.end - tummy_time.start)
|