Self hosted FLOSS fitness/workout, nutrition and weight tracker
Remove slots from rest days and add tests
Roland Geider065d4328ed95
diff --git a/wger/manager/models/day.py b/wger/manager/models/day.pyindex d5dc3ba7e..bff23253a 100644--- a/wger/manager/models/day.py+++ b/wger/manager/models/day.py@@ -107,6 +107,15 @@ class Day(models.Model):"""return self.description+ def save(self, *args, **kwargs):++ # Rest days have no exercises+ if self.pk and self.is_rest:+ for slot in self.slots.all():+ slot.delete()++ return super().save(*args, **kwargs)+def get_owner_object(self):"""Returns the object that has owner informationdiff --git a/wger/manager/tests/test_day_ng.py b/wger/manager/tests/test_day.pysimilarity index 64%rename from wger/manager/tests/test_day_ng.pyrename to wger/manager/tests/test_day.pyindex 850ada3ad..7f35de196 100644--- a/wger/manager/tests/test_day_ng.py+++ b/wger/manager/tests/test_day.py@@ -12,10 +12,16 @@## You should have received a copy of the GNU Affero General Public License+# Standard Library+import datetime+# wgerfrom wger.core.tests.base_testcase import WgerTestCasefrom wger.manager.dataclasses import SetConfigData-from wger.manager.models import Day+from wger.manager.models import (+ Day,+ WorkoutLog,+)class DaySlotTestCase(WgerTestCase):@@ -133,3 +139,77 @@ class DaySlotTestCase(WgerTestCase):sets=3,),)+++class DayModelTestCase(WgerTestCase):+ """+ Tests the day model+ """++ def test_rest_day(self):+ """+ Test that a day marked as a rest day deletes all slots+ """++ day = Day.objects.get(pk=1)+ self.assertEqual(day.slots.count(), 3)++ day.is_rest = True+ day.save()+ self.assertEqual(day.slots.count(), 0)++ def test_no_rest_day(self):+ """+ Test that a regular day does not delete any slots+ """++ day = Day.objects.get(pk=1)+ self.assertEqual(day.slots.count(), 3)++ day.name = 'foo'+ day.save()+ self.assertEqual(day.slots.count(), 3)++ def test_can_proceed_future(self):+ """+ Test that can_proceed returns true when the date is in the future+ """++ day = Day.objects.get(pk=1)+ self.assertTrue(day.can_proceed(date=datetime.date.today() + datetime.timedelta(days=1)))++ def test_can_proceed_present(self):+ """+ Test that can_proceed returns true when need_logs_to_advance is false+ """++ day = Day.objects.get(pk=1)+ day.need_logs_to_advance = False+ self.assertTrue(day.can_proceed(date=datetime.date.today()))++ def test_can_proceed_no_logs(self):+ """+ Test that can_proceed returns false when need_logs_to_advance is true and there are no logs+ """++ day = Day.objects.get(pk=1)+ day.need_logs_to_advance = True+ self.assertFalse(day.can_proceed(date=datetime.date.today()))++ def test_can_proceed(self):+ """+ Test that can_proceed returns true when need_logs_to_advance is true and there are logs+ """++ day = Day.objects.get(pk=1)+ day.need_logs_to_advance = True+ WorkoutLog.objects.create(+ date=datetime.datetime.now(),+ weight_unit_id=1,+ repetition_unit_id=1,+ user=day.routine.user,+ reps=1,+ weight=1,+ exercise_id=1,+ )+ self.assertFalse(day.can_proceed(date=datetime.date.today()))