Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add simple test for the ingredient overview

Roland Geider4470323d328e
diff --git a/wger/nutrition/tests/__init__.py b/wger/nutrition/tests/__init__.py
index 1e0cf7240..b39e86d0e 100644
--- a/wger/nutrition/tests/__init__.py
+++ b/wger/nutrition/tests/__init__.py
@@ -1,3 +1,4 @@
from wger.nutrition.tests.ingredient import *
from wger.nutrition.tests.plan import *
from wger.nutrition.tests.meal import *
+from wger.nutrition.tests.ingredient_overview import *
diff --git a/wger/nutrition/tests/ingredient_overview.py b/wger/nutrition/tests/ingredient_overview.py
new file mode 100644
index 000000000..f1b4046f2
--- /dev/null
+++ b/wger/nutrition/tests/ingredient_overview.py
@@ -0,0 +1,60 @@
+# 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/>.
+
+from django.core.urlresolvers import reverse
+
+from wger.nutrition.models import Ingredient
+from wger.manager.tests.testcase import WorkoutManagerTestCase
+from wger.workout_manager.constants import PAGINATION_OBJECTS_PER_PAGE
+
+
+class OverviewPlanTestCase(WorkoutManagerTestCase):
+ '''
+ Tests the ingredient overview
+ '''
+
+ def test_overview(self):
+
+ # Add more ingredients so we can test the pagination
+ self.user_login('admin')
+ data = {
+ "name": "Test ingredient",
+ "language": 2,
+ "sodium": 10.549,
+ "energy": 176,
+ "fat": 8.19,
+ "carbohydrates_sugar": 0.0,
+ "fat_saturated": 3.244,
+ "fibres": 0.0,
+ "protein": 25.63,
+ "carbohydrates": 0.0
+ }
+ for i in range(0, 50):
+ self.client.post(reverse('ingredient-add'), data)
+
+ # Page exists
+ self.user_logout()
+ response = self.client.get(reverse('wger.nutrition.views.ingredient_overview'))
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(len(response.context['ingredients']), PAGINATION_OBJECTS_PER_PAGE)
+
+ response = self.client.get(reverse('wger.nutrition.views.ingredient_overview') + '?page=2')
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(len(response.context['ingredients']), PAGINATION_OBJECTS_PER_PAGE)
+
+ rest_ingredients = Ingredient.objects.count() - 2 * PAGINATION_OBJECTS_PER_PAGE
+ response = self.client.get(reverse('wger.nutrition.views.ingredient_overview') + '?page=3')
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(len(response.context['ingredients']), rest_ingredients)