Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Remove null constraint from the order field in SlotEntry and add some tests

Roland Geider65eb06ace40a
diff --git a/wger/manager/models/slot_entry.py b/wger/manager/models/slot_entry.py
index 7bae76835..711008f3e 100644
--- a/wger/manager/models/slot_entry.py
+++ b/wger/manager/models/slot_entry.py
@@ -140,7 +140,6 @@ class SlotEntry(models.Model):
order = models.PositiveIntegerField(
blank=True,
- null=True,
db_index=True,
)
diff --git a/wger/manager/tests/test_slot_entry.py b/wger/manager/tests/test_slot_entry.py
index 3e148ced6..a6976986c 100644
--- a/wger/manager/tests/test_slot_entry.py
+++ b/wger/manager/tests/test_slot_entry.py
@@ -58,6 +58,24 @@ class SlotEntryTestCase(WgerTestCase):
)
self.slot_entry.save()
+ def test_auto_add_order(self):
+ """
+ Test that the order is automatically added if not provided
+ """
+ slot_entry_2 = SlotEntry(slot_id=1, exercise_id=2, order=None)
+ slot_entry_2.save()
+
+ slot_entry_3 = SlotEntry(slot_id=1, exercise_id=3, order=7)
+ slot_entry_3.save()
+
+ slot_entry_4 = SlotEntry(slot_id=1, exercise_id=3)
+ slot_entry_4.save()
+
+ self.assertEqual(self.slot_entry.order, 1)
+ self.assertEqual(slot_entry_2.order, 2)
+ self.assertEqual(slot_entry_3.order, 7)
+ self.assertEqual(slot_entry_4.order, 8)
+
def test_weight_config(self):
"""
Test that the weight is correctly calculated for each step / iteration