mirror of https://github.com/snachodog/mybuddy.git
Remove timezone overrides from tests
Tests will now use the timezone from a Settings model instance.
This commit is contained in:
parent
bcfa352b9b
commit
a0ec0591e4
10
api/tests.py
10
api/tests.py
|
@ -1,5 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from django.test import override_settings
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
@ -8,7 +7,6 @@ from rest_framework.test import APITestCase
|
||||||
from core import models
|
from core import models
|
||||||
|
|
||||||
|
|
||||||
@override_settings(TIME_ZONE='US/Eastern')
|
|
||||||
class ChildAPITestCase(APITestCase):
|
class ChildAPITestCase(APITestCase):
|
||||||
fixtures = ['tests.json']
|
fixtures = ['tests.json']
|
||||||
endpoint = reverse('api:child-list')
|
endpoint = reverse('api:child-list')
|
||||||
|
@ -45,7 +43,6 @@ class ChildAPITestCase(APITestCase):
|
||||||
self.assertEqual(obj.first_name, data['first_name'])
|
self.assertEqual(obj.first_name, data['first_name'])
|
||||||
|
|
||||||
|
|
||||||
@override_settings(TIME_ZONE='US/Eastern')
|
|
||||||
class DiaperChangeAPITestCase(APITestCase):
|
class DiaperChangeAPITestCase(APITestCase):
|
||||||
fixtures = ['tests.json']
|
fixtures = ['tests.json']
|
||||||
endpoint = reverse('api:diaperchange-list')
|
endpoint = reverse('api:diaperchange-list')
|
||||||
|
@ -89,7 +86,6 @@ class DiaperChangeAPITestCase(APITestCase):
|
||||||
self.assertEqual(obj.amount, data['amount'])
|
self.assertEqual(obj.amount, data['amount'])
|
||||||
|
|
||||||
|
|
||||||
@override_settings(TIME_ZONE='US/Eastern')
|
|
||||||
class FeedingAPITestCase(APITestCase):
|
class FeedingAPITestCase(APITestCase):
|
||||||
fixtures = ['tests.json']
|
fixtures = ['tests.json']
|
||||||
endpoint = reverse('api:feeding-list')
|
endpoint = reverse('api:feeding-list')
|
||||||
|
@ -130,7 +126,6 @@ class FeedingAPITestCase(APITestCase):
|
||||||
self.assertEqual(obj.type, data['type'])
|
self.assertEqual(obj.type, data['type'])
|
||||||
|
|
||||||
|
|
||||||
@override_settings(TIME_ZONE='US/Eastern')
|
|
||||||
class NoteAPITestCase(APITestCase):
|
class NoteAPITestCase(APITestCase):
|
||||||
fixtures = ['tests.json']
|
fixtures = ['tests.json']
|
||||||
endpoint = reverse('api:note-list')
|
endpoint = reverse('api:note-list')
|
||||||
|
@ -165,7 +160,6 @@ class NoteAPITestCase(APITestCase):
|
||||||
self.assertEqual(obj.note, data['note'])
|
self.assertEqual(obj.note, data['note'])
|
||||||
|
|
||||||
|
|
||||||
@override_settings(TIME_ZONE='US/Eastern')
|
|
||||||
class SleepAPITestCase(APITestCase):
|
class SleepAPITestCase(APITestCase):
|
||||||
fixtures = ['tests.json']
|
fixtures = ['tests.json']
|
||||||
endpoint = reverse('api:sleep-list')
|
endpoint = reverse('api:sleep-list')
|
||||||
|
@ -202,7 +196,6 @@ class SleepAPITestCase(APITestCase):
|
||||||
self.assertEqual(str(obj.duration), '3:30:00')
|
self.assertEqual(str(obj.duration), '3:30:00')
|
||||||
|
|
||||||
|
|
||||||
@override_settings(TIME_ZONE='US/Eastern')
|
|
||||||
class TemperatureAPITestCase(APITestCase):
|
class TemperatureAPITestCase(APITestCase):
|
||||||
fixtures = ['tests.json']
|
fixtures = ['tests.json']
|
||||||
endpoint = reverse('api:temperature-list')
|
endpoint = reverse('api:temperature-list')
|
||||||
|
@ -237,7 +230,6 @@ class TemperatureAPITestCase(APITestCase):
|
||||||
self.assertEqual(str(obj.temperature), data['temperature'])
|
self.assertEqual(str(obj.temperature), data['temperature'])
|
||||||
|
|
||||||
|
|
||||||
@override_settings(TIME_ZONE='US/Eastern')
|
|
||||||
class TimerAPITestCase(APITestCase):
|
class TimerAPITestCase(APITestCase):
|
||||||
fixtures = ['tests.json']
|
fixtures = ['tests.json']
|
||||||
endpoint = reverse('api:timer-list')
|
endpoint = reverse('api:timer-list')
|
||||||
|
@ -275,7 +267,6 @@ class TimerAPITestCase(APITestCase):
|
||||||
self.assertEqual(obj.name, data['name'])
|
self.assertEqual(obj.name, data['name'])
|
||||||
|
|
||||||
|
|
||||||
@override_settings(TIME_ZONE='US/Eastern')
|
|
||||||
class TummyTimeAPITestCase(APITestCase):
|
class TummyTimeAPITestCase(APITestCase):
|
||||||
fixtures = ['tests.json']
|
fixtures = ['tests.json']
|
||||||
endpoint = reverse('api:tummytime-list')
|
endpoint = reverse('api:tummytime-list')
|
||||||
|
@ -313,7 +304,6 @@ class TummyTimeAPITestCase(APITestCase):
|
||||||
self.assertEqual(str(obj.duration), '0:05:30')
|
self.assertEqual(str(obj.duration), '0:05:30')
|
||||||
|
|
||||||
|
|
||||||
@override_settings(TIME_ZONE='US/Eastern')
|
|
||||||
class WeightAPITestCase(APITestCase):
|
class WeightAPITestCase(APITestCase):
|
||||||
fixtures = ['tests.json']
|
fixtures = ['tests.json']
|
||||||
endpoint = reverse('api:weight-list')
|
endpoint = reverse('api:weight-list')
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import pytz
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
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 django.utils import timezone
|
||||||
|
|
||||||
|
from babybuddy.models import Settings
|
||||||
from core import models
|
from core import models
|
||||||
from dashboard.templatetags import cards
|
from dashboard.templatetags import cards
|
||||||
|
|
||||||
|
|
||||||
@override_settings(TIME_ZONE='US/Eastern')
|
|
||||||
class TemplateTagsTestCase(TestCase):
|
class TemplateTagsTestCase(TestCase):
|
||||||
fixtures = ['tests.json']
|
fixtures = ['tests.json']
|
||||||
|
|
||||||
|
@ -15,6 +17,11 @@ class TemplateTagsTestCase(TestCase):
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super(TemplateTagsTestCase, cls).setUpClass()
|
super(TemplateTagsTestCase, cls).setUpClass()
|
||||||
cls.child = models.Child.objects.first()
|
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.
|
# Test file data uses a basis date of 2017-11-18.
|
||||||
date = timezone.localtime().strptime('2017-11-18', '%Y-%m-%d')
|
date = timezone.localtime().strptime('2017-11-18', '%Y-%m-%d')
|
||||||
cls.date = timezone.make_aware(date)
|
cls.date = timezone.make_aware(date)
|
||||||
|
@ -67,7 +74,6 @@ class TemplateTagsTestCase(TestCase):
|
||||||
|
|
||||||
def test_card_sleep_naps_day(self):
|
def test_card_sleep_naps_day(self):
|
||||||
data = cards.card_sleep_naps_day(self.child, self.date)
|
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['type'], 'sleep')
|
||||||
self.assertEqual(data['total'], timezone.timedelta(0, 9000))
|
self.assertEqual(data['total'], timezone.timedelta(0, 9000))
|
||||||
self.assertEqual(data['count'], 2)
|
self.assertEqual(data['count'], 2)
|
||||||
|
|
Loading…
Reference in New Issue