Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Fix incorrect URL, add simple tests for the nutritional plan

Roland Geider9b04bacca5f4
diff --git a/wger/nutrition/templates/plan/view.html b/wger/nutrition/templates/plan/view.html
index 909301f12..34ead5362 100644
--- a/wger/nutrition/templates/plan/view.html
+++ b/wger/nutrition/templates/plan/view.html
@@ -115,8 +115,8 @@ $(document).ready(function() {
{% empty %}
<div class="box warning ingredient-box-warning">
{% trans "No items for this meal." %}
- <a href="{% url 'wger.nutrition.views.ingredient.edit_meal_item' plan.id meal.id item.id %}"
- title="{% trans 'Edit' %}"
+ <a href="{% url 'mealitem-add' meal.id %}"
+ title="{% trans 'Add one now' %}"
class="modal-dialog edit-meal">
{% trans "Add one now."%}
</a>
diff --git a/wger/nutrition/tests/meal.py b/wger/nutrition/tests/meal.py
index ae75b4316..bc7fc1713 100644
--- a/wger/nutrition/tests/meal.py
+++ b/wger/nutrition/tests/meal.py
@@ -18,7 +18,9 @@ import datetime
from django.core.urlresolvers import reverse
from wger.nutrition.models import Meal
+from wger.nutrition.models import NutritionPlan
+from wger.manager.tests.testcase import WorkoutManagerTestCase
from wger.manager.tests.testcase import WorkoutManagerDeleteTestCase
from wger.manager.tests.testcase import WorkoutManagerEditTestCase
from wger.manager.tests.testcase import WorkoutManagerAddTestCase
@@ -46,3 +48,79 @@ class AddMealTestCase(WorkoutManagerAddTestCase):
data = {'time': datetime.time(9, 2)}
user_success = 'test'
user_fail = 'admin'
+
+
+class PlanOverviewTestCase(WorkoutManagerTestCase):
+ '''
+ Tests the nutrition plan overview
+ '''
+
+ def get_plan_overview(self, logged_in=False):
+ '''
+ Helper function to test the nutrition plan overview
+ '''
+
+ response = self.client.get(reverse('wger.nutrition.views.plan.overview'))
+
+ # Page exists
+ if logged_in:
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(len(response.context['plans']), 3)
+ else:
+ self.assertEqual(response.status_code, 302)
+
+ def test_dashboard_anonymous(self):
+ '''
+ Test the nutrition plan as anonymous user
+ '''
+
+ self.get_plan_overview()
+
+ def test_dashboard_logged_in(self):
+ '''
+ Test the nutrition plan as a logged in user
+ '''
+ self.user_login()
+ self.get_plan_overview(logged_in=True)
+
+
+class PlanDetailTestCase(WorkoutManagerTestCase):
+ '''
+ Tests the nutrition plan detail view
+ '''
+
+ def get_plan_detail_page(self, fail=False):
+ '''
+ Helper function to test the plan detail view
+ '''
+
+ response = self.client.get(reverse('wger.nutrition.views.plan.view', kwargs={'id': 1}))
+
+ # Page exists
+ if fail:
+ self.assertIn(response.status_code, (302, 404))
+ else:
+ self.assertEqual(response.status_code, 200)
+ plan = NutritionPlan.objects.get(pk=1)
+ self.assertEqual(response.context['plan'], plan)
+
+ def test_dashboard_anonymous(self):
+ '''
+ Test the nutrition plan as anonymous user
+ '''
+
+ self.get_plan_detail_page(fail=True)
+
+ def test_dashboard_owner(self):
+ '''
+ Test the nutrition plan as the owner user
+ '''
+ self.user_login('test')
+ self.get_plan_detail_page(fail=False)
+
+ def test_dashboard_other(self):
+ '''
+ Test the nutrition plan as a differnt user
+ '''
+ self.user_login('admin')
+ self.get_plan_detail_page(fail=True)