Self hosted FLOSS fitness/workout, nutrition and weight tracker
Test adding and editing a meal item
Roland Geiderf6b3fdcc470d
diff --git a/wger/manager/tests/testcase.py b/wger/manager/tests/testcase.pyindex eff3a03ce..e7ee24165 100644--- a/wger/manager/tests/testcase.py+++ b/wger/manager/tests/testcase.py@@ -22,6 +22,8 @@ from django.test import TestCasefrom django.test import LiveServerTestCasefrom django.db import models+STATUS_CODES_FAIL = (302, 403, 404)+class WorkoutManagerTestCase(TestCase):fixtures = ('days_of_week',@@ -107,7 +109,7 @@ class WorkoutManagerDeleteTestCase(WorkoutManagerTestCase):self.assertEqual(count_before, count_after)if fail:- self.assertIn(response.status_code, (403, 302))+ self.assertIn(response.status_code, STATUS_CODES_FAIL)else:self.assertEqual(response.status_code, 200)@@ -116,7 +118,7 @@ class WorkoutManagerDeleteTestCase(WorkoutManagerTestCase):count_after = self.object_class.objects.count()if fail:- self.assertIn(response.status_code, (403, 302))+ self.assertIn(response.status_code, STATUS_CODES_FAIL)self.assertEqual(count_before, count_after)else:self.assertEqual(response.status_code, 302)@@ -182,7 +184,7 @@ class WorkoutManagerEditTestCase(WorkoutManagerTestCase):entry_before = self.object_class.objects.get(pk=self.pk)if fail:- self.assertIn(response.status_code, (302, 403))+ self.assertIn(response.status_code, STATUS_CODES_FAIL)self.assertTemplateUsed('login.html')else:@@ -201,7 +203,7 @@ class WorkoutManagerEditTestCase(WorkoutManagerTestCase):# Check the resultsif fail:- self.assertIn(response.status_code, (302, 403))+ self.assertIn(response.status_code, STATUS_CODES_FAIL)self.assertTemplateUsed('login.html')self.assertEqual(entry_before, entry_after)@@ -269,8 +271,8 @@ class WorkoutManagerAddTestCase(WorkoutManagerTestCase):response = self.client.get(self.url)if fail:- self.assertIn(response.status_code, (302, 403))- self.assertTemplateUsed('login.html')+ self.assertIn(response.status_code, STATUS_CODES_FAIL)+ #self.assertTemplateUsed('login.html')else:self.assertEqual(response.status_code, 200)@@ -286,7 +288,7 @@ class WorkoutManagerAddTestCase(WorkoutManagerTestCase):count_after = self.object_class.objects.count()if fail:- self.assertIn(response.status_code, (302, 403))+ self.assertIn(response.status_code, STATUS_CODES_FAIL)self.assertTemplateUsed('login.html')self.assertRaises(self.object_class.DoesNotExist,diff --git a/wger/nutrition/fixtures/test-nutrition-data.json b/wger/nutrition/fixtures/test-nutrition-data.jsonindex 719346d70..45905b65e 100644--- a/wger/nutrition/fixtures/test-nutrition-data.json+++ b/wger/nutrition/fixtures/test-nutrition-data.json@@ -148,6 +148,26 @@"order": 1}},+ {+ "pk": 1,+ "model": "nutrition.mealitem",+ "fields": {+ "ingredient": 1,+ "amount_gramm": 200,+ "meal": 1,+ "order": 1+ }+ },+ {+ "pk": 2,+ "model": "nutrition.mealitem",+ "fields": {+ "ingredient": 1,+ "amount_gramm": 200,+ "meal": 1,+ "order": 1+ }+ },{"pk": 3,"model": "nutrition.mealitem",@@ -238,6 +258,16 @@"order": 1}},+ {+ "pk": 12,+ "model": "nutrition.mealitem",+ "fields": {+ "ingredient": 4,+ "amount_gramm": 200,+ "meal": 10,+ "order": 1+ }+ },{"pk": 13,"model": "nutrition.mealitem",diff --git a/wger/nutrition/tests/__init__.py b/wger/nutrition/tests/__init__.pyindex fed748843..803174a78 100644--- a/wger/nutrition/tests/__init__.py+++ b/wger/nutrition/tests/__init__.py@@ -5,5 +5,6 @@ from wger.nutrition.tests.pdf import *from wger.nutrition.tests.ingredient import *from wger.nutrition.tests.ingredient_overview import *from wger.nutrition.tests.meal import *+from wger.nutrition.tests.meal_item import *from wger.nutrition.tests.weight_unit import *from wger.nutrition.tests.weight_unit_ingredient import *diff --git a/wger/nutrition/tests/meal_item.py b/wger/nutrition/tests/meal_item.pynew file mode 100644index 000000000..9fd235f0a--- /dev/null+++ b/wger/nutrition/tests/meal_item.py@@ -0,0 +1,80 @@+# 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 datetime++from django.core.urlresolvers import reverse++from wger.nutrition.models import MealItem+from wger.nutrition.models import MEALITEM_WEIGHT_UNIT+from wger.nutrition.models import MEALITEM_WEIGHT_GRAM++from wger.manager.tests.testcase import WorkoutManagerDeleteTestCase+from wger.manager.tests.testcase import WorkoutManagerEditTestCase+from wger.manager.tests.testcase import WorkoutManagerAddTestCase+++class EditMealItemUnitTestCase(WorkoutManagerEditTestCase):+ '''+ Tests editing a meal, set the amount using a unit+ '''++ object_class = MealItem+ url = reverse('wger.nutrition.views.ingredient.edit_meal_item',+ kwargs={'id': 2, 'meal_id': 3, 'item_id': 4})+ pk = 4+ data = {'amount_gramm': 1,+ 'ingredient': 1,+ 'weight_unit': 1}+++class EditMealItemWeightTestCase(WorkoutManagerEditTestCase):+ '''+ Tests editing a meal, set the amount using weight+ '''++ object_class = MealItem+ url = reverse('wger.nutrition.views.ingredient.edit_meal_item',+ kwargs={'id': 2, 'meal_id': 3, 'item_id': 4})+ pk = 4+ data = {'amount_gramm': 100,+ 'ingredient': 1}+++class AddMealItemTestCase(WorkoutManagerAddTestCase):+ '''+ Tests adding a meal, set the amount using a unit+ '''++ object_class = MealItem+ url = reverse('wger.nutrition.views.ingredient.edit_meal_item',+ kwargs={'id': 2, 'meal_id': 3, 'item_id': None})+ pk = 22+ data = {'amount_gramm': 1,+ 'ingredient': 1,+ 'weight_unit': 1}+++class AddMealItemTestCase(WorkoutManagerAddTestCase):+ '''+ Tests adding a meal, set the amount using weight+ '''++ object_class = MealItem+ url = reverse('wger.nutrition.views.ingredient.edit_meal_item',+ kwargs={'id': 2, 'meal_id': 3, 'item_id': None})+ pk = 22+ data = {'amount_gramm': 100,+ 'ingredient': 1}