Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Make tests more robusts

Roland Geider7a4b7e25c087
diff --git a/wger/exercises/tests/test_deletion_log.py b/wger/exercises/tests/test_deletion_log.py
index 76ef30c8b..55bb28609 100644
--- a/wger/exercises/tests/test_deletion_log.py
+++ b/wger/exercises/tests/test_deletion_log.py
@@ -41,34 +41,25 @@ class DeletionLogTestCase(WgerTestCase):
exercise.delete()
# Exercise is deleted
- count_exercise_logs = DeletionLog.objects.filter(
+ log = DeletionLog.objects.get(
model_type=DeletionLog.MODEL_EXERCISE,
uuid=exercise.uuid,
- ).count()
- log = DeletionLog.objects.get(pk=1)
-
- self.assertEqual(count_exercise_logs, 1)
- self.assertEqual(log.model_type, DeletionLog.MODEL_EXERCISE)
- self.assertEqual(log.uuid, exercise.uuid)
+ )
self.assertEqual(log.comment, 'Exercise base of An exercise')
self.assertEqual(log.replaced_by, None)
# All translations are also deleted
- count = DeletionLog.objects.filter(model_type=DeletionLog.MODEL_TRANSLATION).count()
- self.assertEqual(count, 2)
-
- # First translation
- log2 = DeletionLog.objects.get(pk=4)
- self.assertEqual(log2.model_type, DeletionLog.MODEL_TRANSLATION)
- self.assertEqual(log2.uuid, UUID('9838235c-e38f-4ca6-921e-9d237d8e0813'))
- self.assertEqual(log2.comment, 'An exercise')
+ translation_logs = DeletionLog.objects.filter(
+ model_type=DeletionLog.MODEL_TRANSLATION,
+ ).order_by('uuid')
+ self.assertEqual(translation_logs.count(), 2)
+
+ log2 = translation_logs.get(uuid=UUID('13b532f9-d208-462e-a000-7b9982b2b53e'))
+ self.assertEqual(log2.comment, 'Test exercise 123')
self.assertEqual(log2.replaced_by, None)
- # Second translation
- log3 = DeletionLog.objects.get(pk=5)
- self.assertEqual(log3.model_type, DeletionLog.MODEL_TRANSLATION)
- self.assertEqual(log3.uuid, UUID('13b532f9-d208-462e-a000-7b9982b2b53e'))
- self.assertEqual(log3.comment, 'Test exercise 123')
+ log3 = translation_logs.get(uuid=UUID('9838235c-e38f-4ca6-921e-9d237d8e0813'))
+ self.assertEqual(log3.comment, 'An exercise')
self.assertEqual(log3.replaced_by, None)
def test_exercise_with_replaced_by(self):
@@ -82,10 +73,10 @@ class DeletionLogTestCase(WgerTestCase):
exercise.delete(replace_by='ae3328ba-9a35-4731-bc23-5da50720c5aa')
# Exercise is deleted
- log = DeletionLog.objects.get(pk=1)
-
- self.assertEqual(log.model_type, DeletionLog.MODEL_EXERCISE)
- self.assertEqual(log.uuid, exercise.uuid)
+ log = DeletionLog.objects.get(
+ model_type=DeletionLog.MODEL_EXERCISE,
+ uuid=exercise.uuid,
+ )
self.assertEqual(log.replaced_by, UUID('ae3328ba-9a35-4731-bc23-5da50720c5aa'))
def test_exercise_replace_by_updates_workout_logs(self):
@@ -146,9 +137,10 @@ class DeletionLogTestCase(WgerTestCase):
exercise.delete(replace_by='12345678-1234-1234-1234-1234567890ab')
# Exercise is deleted
- log = DeletionLog.objects.get(pk=1)
-
- self.assertEqual(log.model_type, DeletionLog.MODEL_EXERCISE)
+ log = DeletionLog.objects.get(
+ model_type=DeletionLog.MODEL_EXERCISE,
+ uuid=exercise.uuid,
+ )
self.assertEqual(log.replaced_by, None)
def test_translation(self):
diff --git a/wger/exercises/tests/test_exercise.py b/wger/exercises/tests/test_exercise.py
index 693f7531d..cf566b237 100644
--- a/wger/exercises/tests/test_exercise.py
+++ b/wger/exercises/tests/test_exercise.py
@@ -120,10 +120,10 @@ class ExerciseCustomApiTestCase(ExerciseCrudApiTestCase):
response = self.client.delete(url)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
- log = DeletionLog.objects.get(pk=1)
-
- self.assertEqual(log.model_type, 'base')
- self.assertEqual(log.uuid, UUID('acad3949-36fb-4481-9a72-be2ddae2bc05'))
+ log = DeletionLog.objects.get(
+ model_type=DeletionLog.MODEL_EXERCISE,
+ uuid=UUID('acad3949-36fb-4481-9a72-be2ddae2bc05'),
+ )
self.assertEqual(log.replaced_by, UUID('ae3328ba-9a35-4731-bc23-5da50720c5aa'))
def test_cant_change_license(self):