Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add, fix and expand some of the tests
Roland Geidera6190ae975b5
diff --git a/wger/exercises/tests/muscles.py b/wger/exercises/tests/muscles.pyindex 3a7900295..bab887625 100644--- a/wger/exercises/tests/muscles.py+++ b/wger/exercises/tests/muscles.py@@ -30,7 +30,7 @@ class AddMuscleTestCase(WorkoutManagerAddTestCase):object_class = Muscleurl = 'muscle-add'- pk = 17+ pk = 4data = {'name': 'A new muscle','is_front': True}diff --git a/wger/manager/fixtures/test-workout-data.json b/wger/manager/fixtures/test-workout-data.jsonindex aadbed143..2256710c3 100644--- a/wger/manager/fixtures/test-workout-data.json+++ b/wger/manager/fixtures/test-workout-data.json@@ -79,7 +79,8 @@"training": 3,"description": "A cool day","day": [- 5+ 5,+ 3]}},diff --git a/wger/manager/tests/copy_workout.py b/wger/manager/tests/copy_workout.pyindex d5f59d1a3..81bd6feed 100644--- a/wger/manager/tests/copy_workout.py+++ b/wger/manager/tests/copy_workout.py@@ -12,12 +12,15 @@## You should have received a copy of the GNU Affero General Public License+import logging+from django.core.urlresolvers import reversefrom wger.manager.models import TrainingSchedule-from wger.manager.tests.testcase import WorkoutManagerTestCase+logger = logging.getLogger('workout_manager.custom')+class CopyWorkoutTestCase(WorkoutManagerTestCase):'''@@ -59,6 +62,35 @@ class CopyWorkoutTestCase(WorkoutManagerTestCase):else:self.assertEqual(response.status_code, 200)+ original = TrainingSchedule.objects.get(pk=3)+ copy = TrainingSchedule.objects.get(pk=4)++ days_original = original.day_set.all()+ days_copy = copy.day_set.all()++ # Test that the different attributes and objects are correctly copied over+ for i in range(0, original.day_set.count()):+ self.assertEqual(days_original[i].description, days_copy[i].description)++ for j in range(0, days_original[i].day.count()):+ self.assertEqual(days_original[i].day.all()[j], days_copy[i].day.all()[j])++ sets_original = days_original[i].set_set.all()+ sets_copy = days_copy[i].set_set.all()++ for j in range(days_original[i].set_set.count()):+ sets_original_id = sets_original[j].id+ sets_copy_id = sets_copy[j].id++ self.assertEqual(sets_original[j].sets, sets_copy[j].sets)+ self.assertEqual(sets_original[j].order, sets_copy[j].order)++ exercises_original = sets_original[j].exercises.all()+ exercises_copy = sets_copy[j].exercises.all()++ for k in range(sets_original[j].exercises.count()):+ self.assertEqual(exercises_original[k], exercises_copy[k])+def test_copy_workout_anonymous(self):'''Test copying a workout as anonymous userdiff --git a/wger/manager/tests/testcase.py b/wger/manager/tests/testcase.pyindex 6a6789c41..875afd16d 100644--- a/wger/manager/tests/testcase.py+++ b/wger/manager/tests/testcase.py@@ -27,7 +27,6 @@ STATUS_CODES_FAIL = (302, 403, 404)class WorkoutManagerTestCase(TestCase):fixtures = ('days_of_week',- 'muscles','test-user-data','test-weight-data','test-exercises',diff --git a/wger/manager/views/workout.py b/wger/manager/views/workout.pyindex e15eb66ee..14ff860ae 100644--- a/wger/manager/views/workout.py+++ b/wger/manager/views/workout.py@@ -132,9 +132,13 @@ def copy_workout(request, pk):sets = day.set_set.all()day_copy = day+ days_of_week = [i for i in day.day.all()]day_copy.pk = Noneday_copy.training = workout_copyday_copy.save()+ for i in days_of_week:+ day_copy.day.add(i)+ day_copy.save()# Copy the setsfor current_set in sets:diff --git a/wger/nutrition/tests/__init__.py b/wger/nutrition/tests/__init__.pyindex 803174a78..2a40c9312 100644--- a/wger/nutrition/tests/__init__.py+++ b/wger/nutrition/tests/__init__.py@@ -1,7 +1,7 @@from wger.nutrition.tests.plan import *from wger.nutrition.tests.copy_plan import *from wger.nutrition.tests.pdf import *-+from wger.nutrition.tests.nutritional_calculations import *from wger.nutrition.tests.ingredient import *from wger.nutrition.tests.ingredient_overview import *from wger.nutrition.tests.meal import *diff --git a/wger/nutrition/tests/nutritional_calculations.py b/wger/nutrition/tests/nutritional_calculations.pynew file mode 100644index 000000000..e700899e3--- /dev/null+++ b/wger/nutrition/tests/nutritional_calculations.py@@ -0,0 +1,119 @@+# This file is part of Workout Manager.+#+# Workout Manager is free software: you can redistribute it and/or modify+# it under the terms of the GNU Affero General Public License as published by+# the Free Software Foundation, either version 3 of the License, or+# (at your option) any later version.+#+# Workout Manager is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU Affero General Public License+# along with Workout Manager. If not, see <http://www.gnu.org/licenses/>.++import logging+import decimal++from wger.nutrition import models+from wger.manager.tests.testcase import WorkoutManagerTestCase++logger = logging.getLogger('workout_manager.custom')+++class NutritionalValuesCalculationsTestCase(WorkoutManagerTestCase):+ '''+ Tests the nutritional values calculators in the different models+ '''++ def test_calculations(self):+ plan = models.NutritionPlan(user_id=1, language_id=1)+ plan.save()++ meal = models.Meal(order=1)+ meal.plan = plan+ meal.save()++ ingredient = models.Ingredient.objects.get(pk=1)+ ingredient2 = models.Ingredient.objects.get(pk=2)+ ingredient3 = models.Ingredient.objects.get(pk=2)++ # One ingredient, 100 gr+ item = models.MealItem()+ item.meal = meal+ item.ingredient = ingredient+ item.weight_unit_id = None+ item.amount = 100+ item.order = 1+ item.save()++ result_item = item.get_nutritional_values()++ for i in result_item:+ self.assertEqual(result_item[i], getattr(ingredient, i))++ result_meal = meal.get_nutritional_values()+ self.assertEqual(result_item, result_meal)++ result_plan = plan.get_nutritional_values()+ self.assertEqual(result_meal, result_plan)++ # One ingredient, 1 x unit 3+ item.amount = 1+ item.weight_unit_id = 3+ item.save()++ result_item = item.get_nutritional_values()++ for i in result_item:+ self.assertEqual(result_item[i], getattr(ingredient, i) * decimal.Decimal(12.0) / 100)++ result_meal = meal.get_nutritional_values()+ self.assertEqual(result_item, result_meal)++ result_plan = plan.get_nutritional_values()+ self.assertEqual(result_meal, result_plan)++ # Add another ingredient, 200 gr+ item2 = models.MealItem()+ item2.meal = meal+ item2.ingredient = ingredient2+ item2.weight_unit_id = None+ item2.amount = 200+ item2.order = 1+ item2.save()++ result_item2 = item2.get_nutritional_values()++ result_total = {}+ for i in result_item2:+ self.assertEqual(result_item2[i], 2 * getattr(ingredient2, i))+ result_total[i] = result_item[i] + result_item2[i]++ result_meal = meal.get_nutritional_values()+ self.assertEqual(result_total, result_meal)++ result_plan = plan.get_nutritional_values()+ self.assertEqual(result_meal, result_plan)++ # Add another ingredient, 20 gr+ item3 = models.MealItem()+ item3.meal = meal+ item3.ingredient = ingredient3+ item3.weight_unit_id = None+ item3.amount = 20+ item3.order = 1+ item3.save()++ result_item3 = item3.get_nutritional_values()++ for i in result_item3:+ self.assertEqual(result_item3[i], getattr(ingredient3, i) * decimal.Decimal(20.0) / 100)+ result_total[i] = result_total[i] + result_item3[i]++ result_meal = meal.get_nutritional_values()+ self.assertEqual(result_total, result_meal)++ result_plan = plan.get_nutritional_values()+ self.assertEqual(result_meal, result_plan)