mybuddy/reports/tests/graphs/tests_sleep_pattern.py

31 lines
843 B
Python
Raw Normal View History

2022-06-17 13:40:28 +00:00
# -*- 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"))