Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add simple test for diary calculator
Roland Geider3f8f86c62148
diff --git a/wger/manager/tests/testcase.py b/wger/manager/tests/testcase.pyindex 044688fe6..98e38b869 100644--- a/wger/manager/tests/testcase.py+++ b/wger/manager/tests/testcase.py@@ -109,6 +109,7 @@ class BaseTestCase(object):'test-weight-units','test-ingredients','test-nutrition-data',+ 'test-nutrition-diary','test-workout-data','test-workout-session','test-schedules')diff --git a/wger/nutrition/fixtures/test-nutrition-diary.json b/wger/nutrition/fixtures/test-nutrition-diary.jsonnew file mode 100644index 000000000..274b01e56--- /dev/null+++ b/wger/nutrition/fixtures/test-nutrition-diary.json@@ -0,0 +1,62 @@+[+ {+ "fields": {+ "plan": 1,+ "datetime": "2016-05-15T12:01:00Z",+ "ingredient": 5,+ "comment": "",+ "amount": "2",+ "weight_unit": 1+ },+ "pk": 1,+ "model": "nutrition.logitem"+ },+ {+ "fields": {+ "plan": 1,+ "datetime": "2016-05-15T12:01:15Z",+ "ingredient": 4,+ "comment": "",+ "amount": "100",+ "weight_unit": null+ },+ "pk": 2,+ "model": "nutrition.logitem"+ },+ {+ "fields": {+ "plan": 1,+ "datetime": "2016-05-15T12:01:00Z",+ "ingredient": 1,+ "comment": "",+ "amount": "75",+ "weight_unit": null+ },+ "pk": 3,+ "model": "nutrition.logitem"+ },+ {+ "fields": {+ "plan": 1,+ "datetime": "2016-05-14T17:11:33Z",+ "ingredient": 1,+ "comment": "",+ "amount": "75",+ "weight_unit": null+ },+ "pk": 4,+ "model": "nutrition.logitem"+ },+ {+ "fields": {+ "plan": 2,+ "datetime": "2016-05-14T17:11:33Z",+ "ingredient": 1,+ "comment": "",+ "amount": "75",+ "weight_unit": null+ },+ "pk": 4,+ "model": "nutrition.logitem"+ }+]\ No newline at end of filediff --git a/wger/nutrition/tests/test_nutrition_diary.py b/wger/nutrition/tests/test_nutrition_diary.pynew file mode 100644index 000000000..bf2f3ef9c--- /dev/null+++ b/wger/nutrition/tests/test_nutrition_diary.py@@ -0,0 +1,54 @@+# This file is part of wger Workout Manager.+#+# wger 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.+#+# wger 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 datetime+from decimal import Decimal++from wger.nutrition.models import NutritionPlan+from wger.manager.tests.testcase import WorkoutManagerTestCase++logger = logging.getLogger(__name__)+++class NutritionDiaryTestCase(WorkoutManagerTestCase):+ '''+ Tests the different nutrition diary functions+ '''++ def test_calculations(self):+ plan = NutritionPlan.objects.get(pk=1)++ # No entries for date+ self.assertEqual(plan.get_logged_values(datetime.date(2016, 1, 12)),+ {'energy': 0,+ 'protein': 0,+ 'carbohydrates': 0,+ 'carbohydrates_sugar': 0,+ 'fat': 0,+ 'fat_saturated': 0,+ 'fibres': 0,+ 'sodium': 0})++ # Entries found+ self.assertEqual(plan.get_logged_values(datetime.date(2016, 5, 15)),+ {'energy': Decimal('653.80'),+ 'protein': Decimal('19.22'),+ 'carbohydrates': Decimal('109.99'),+ 'carbohydrates_sugar': Decimal('107.72'),+ 'fat': Decimal('9.32'),+ 'fat_saturated': Decimal('2.43'),+ 'fibres': Decimal('0.00'),+ 'sodium': Decimal('5.09')})