mirror of https://github.com/snachodog/mybuddy.git
Fix 500 in sleep pattern (#487)
This commit is contained in:
parent
a84087edf3
commit
c98f6cd433
|
@ -26,7 +26,9 @@ def sleep_pattern(sleeps):
|
||||||
last_end_time = None
|
last_end_time = None
|
||||||
adjustment = None
|
adjustment = None
|
||||||
|
|
||||||
days = _init_days(sleeps.first().start, sleeps.last().end)
|
first_day = timezone.localtime(sleeps.first().start)
|
||||||
|
last_day = timezone.localtime(sleeps.last().end)
|
||||||
|
days = _init_days(first_day, last_day)
|
||||||
|
|
||||||
for sleep in sleeps:
|
for sleep in sleeps:
|
||||||
start_time = timezone.localtime(sleep.start)
|
start_time = timezone.localtime(sleep.start)
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import datetime as dt
|
||||||
|
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
from core import models
|
||||||
|
from reports.graphs import sleep_pattern
|
||||||
|
|
||||||
|
|
||||||
|
class SleepPatternTestCase(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.original_tz = timezone.get_current_timezone()
|
||||||
|
self.tz = dt.timezone(dt.timedelta(days=-1, hours=1))
|
||||||
|
timezone.activate(self.tz)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
timezone.activate(self.original_tz)
|
||||||
|
|
||||||
|
def test_sleep_pattern(self):
|
||||||
|
|
||||||
|
c = models.Child(birth_date=dt.datetime.now())
|
||||||
|
c.save()
|
||||||
|
|
||||||
|
models.Sleep.objects.create(
|
||||||
|
child=c,
|
||||||
|
start=dt.datetime(2000, 1, 1, 0, 0, tzinfo=timezone.utc),
|
||||||
|
end=dt.datetime(2000, 1, 1, 0, 1, tzinfo=timezone.utc),
|
||||||
|
)
|
||||||
|
|
||||||
|
sleep_pattern(models.Sleep.objects.order_by("start"))
|
Loading…
Reference in New Issue