From a0ec0591e4535cb46ef56a832b3f7abe1a596198 Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Fri, 14 Feb 2020 10:16:36 -0800 Subject: [PATCH] Remove timezone overrides from tests Tests will now use the timezone from a Settings model instance. --- api/tests.py | 10 ---------- dashboard/tests/tests_templatetags.py | 12 +++++++++--- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/api/tests.py b/api/tests.py index 6e282e30..33c14fe5 100644 --- a/api/tests.py +++ b/api/tests.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from django.test import override_settings from django.urls import reverse from rest_framework import status @@ -8,7 +7,6 @@ from rest_framework.test import APITestCase from core import models -@override_settings(TIME_ZONE='US/Eastern') class ChildAPITestCase(APITestCase): fixtures = ['tests.json'] endpoint = reverse('api:child-list') @@ -45,7 +43,6 @@ class ChildAPITestCase(APITestCase): self.assertEqual(obj.first_name, data['first_name']) -@override_settings(TIME_ZONE='US/Eastern') class DiaperChangeAPITestCase(APITestCase): fixtures = ['tests.json'] endpoint = reverse('api:diaperchange-list') @@ -89,7 +86,6 @@ class DiaperChangeAPITestCase(APITestCase): self.assertEqual(obj.amount, data['amount']) -@override_settings(TIME_ZONE='US/Eastern') class FeedingAPITestCase(APITestCase): fixtures = ['tests.json'] endpoint = reverse('api:feeding-list') @@ -130,7 +126,6 @@ class FeedingAPITestCase(APITestCase): self.assertEqual(obj.type, data['type']) -@override_settings(TIME_ZONE='US/Eastern') class NoteAPITestCase(APITestCase): fixtures = ['tests.json'] endpoint = reverse('api:note-list') @@ -165,7 +160,6 @@ class NoteAPITestCase(APITestCase): self.assertEqual(obj.note, data['note']) -@override_settings(TIME_ZONE='US/Eastern') class SleepAPITestCase(APITestCase): fixtures = ['tests.json'] endpoint = reverse('api:sleep-list') @@ -202,7 +196,6 @@ class SleepAPITestCase(APITestCase): self.assertEqual(str(obj.duration), '3:30:00') -@override_settings(TIME_ZONE='US/Eastern') class TemperatureAPITestCase(APITestCase): fixtures = ['tests.json'] endpoint = reverse('api:temperature-list') @@ -237,7 +230,6 @@ class TemperatureAPITestCase(APITestCase): self.assertEqual(str(obj.temperature), data['temperature']) -@override_settings(TIME_ZONE='US/Eastern') class TimerAPITestCase(APITestCase): fixtures = ['tests.json'] endpoint = reverse('api:timer-list') @@ -275,7 +267,6 @@ class TimerAPITestCase(APITestCase): self.assertEqual(obj.name, data['name']) -@override_settings(TIME_ZONE='US/Eastern') class TummyTimeAPITestCase(APITestCase): fixtures = ['tests.json'] endpoint = reverse('api:tummytime-list') @@ -313,7 +304,6 @@ class TummyTimeAPITestCase(APITestCase): self.assertEqual(str(obj.duration), '0:05:30') -@override_settings(TIME_ZONE='US/Eastern') class WeightAPITestCase(APITestCase): fixtures = ['tests.json'] endpoint = reverse('api:weight-list') diff --git a/dashboard/tests/tests_templatetags.py b/dashboard/tests/tests_templatetags.py index 849d5f22..e272d085 100644 --- a/dashboard/tests/tests_templatetags.py +++ b/dashboard/tests/tests_templatetags.py @@ -1,13 +1,15 @@ # -*- coding: utf-8 -*- +import pytz + from django.contrib.auth.models import User -from django.test import TestCase, override_settings +from django.test import TestCase from django.utils import timezone +from babybuddy.models import Settings from core import models from dashboard.templatetags import cards -@override_settings(TIME_ZONE='US/Eastern') class TemplateTagsTestCase(TestCase): fixtures = ['tests.json'] @@ -15,6 +17,11 @@ class TemplateTagsTestCase(TestCase): def setUpClass(cls): super(TemplateTagsTestCase, cls).setUpClass() cls.child = models.Child.objects.first() + + # Ensure timezone matches the one defined by fixtures. + user_timezone = Settings.objects.first().timezone + timezone.activate(pytz.timezone(user_timezone)) + # Test file data uses a basis date of 2017-11-18. date = timezone.localtime().strptime('2017-11-18', '%Y-%m-%d') cls.date = timezone.make_aware(date) @@ -67,7 +74,6 @@ class TemplateTagsTestCase(TestCase): def test_card_sleep_naps_day(self): data = cards.card_sleep_naps_day(self.child, self.date) - cards.card_sleep_naps_day(self.child) self.assertEqual(data['type'], 'sleep') self.assertEqual(data['total'], timezone.timedelta(0, 9000)) self.assertEqual(data['count'], 2)