Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Fix two sources of flaky test failures

Roland Geider3fb2d99dbc98
diff --git a/wger/manager/tests/test_routine.py b/wger/manager/tests/test_routine.py
index 7605b4ae0..a4c29ab74 100644
--- a/wger/manager/tests/test_routine.py
+++ b/wger/manager/tests/test_routine.py
@@ -19,6 +19,7 @@ from unittest import mock
# Django
from django.conf import settings
from django.urls import reverse
+from django.utils import timezone
# wger
from wger.core.tests.api_base_test import ApiBaseResourceTestCase
@@ -169,7 +170,7 @@ class RoutineTestCase(WgerTestCase):
"""
# Arrange
- today = datetime.date.today()
+ today = timezone.localdate()
start = today - datetime.timedelta(days=5)
self.routine.start = start
self.routine.end = today + datetime.timedelta(weeks=3)
@@ -288,7 +289,7 @@ class RoutineTestCase(WgerTestCase):
"""
# Arrange
- today = datetime.date.today()
+ today = timezone.localdate()
start = today - datetime.timedelta(days=5)
self.routine.start = start
@@ -486,7 +487,7 @@ class RoutineTestCase(WgerTestCase):
"""
# Arrange
- today = datetime.date.today()
+ today = timezone.localdate()
start = today - datetime.timedelta(days=10)
self.routine.fit_in_week = True
diff --git a/wger/nutrition/tests/test_ingredient.py b/wger/nutrition/tests/test_ingredient.py
index 55ce6b27d..5b702c278 100644
--- a/wger/nutrition/tests/test_ingredient.py
+++ b/wger/nutrition/tests/test_ingredient.py
@@ -111,9 +111,10 @@ class EditIngredientTestCase(WgerEditTestCase):
"""
if self.current_user == 'admin':
ingredient = Ingredient.objects.get(pk=1)
- self.assertEqual(
- ingredient.last_update.replace(microsecond=0),
- datetime.datetime.now(tz=datetime.timezone.utc).replace(microsecond=0),
+ self.assertAlmostEqual(
+ ingredient.last_update,
+ datetime.datetime.now(tz=datetime.timezone.utc),
+ delta=datetime.timedelta(minutes=1),
)
@@ -144,9 +145,10 @@ class AddIngredientTestCase(WgerAddTestCase):
"""
if self.current_user == 'admin':
ingredient = Ingredient.objects.get(pk=self.pk_after)
- self.assertEqual(
- ingredient.created.replace(microsecond=0),
- datetime.datetime.now(tz=datetime.timezone.utc).replace(microsecond=0),
+ self.assertAlmostEqual(
+ ingredient.created,
+ datetime.datetime.now(tz=datetime.timezone.utc),
+ delta=datetime.timedelta(minutes=1),
)