Self hosted FLOSS fitness/workout, nutrition and weight tracker
Merge branch 'feature/ro-access'
Roland Geiderffabd2718ec2
diff --cc wger/core/templates/navigation.htmlindex 27a75b65e,6710ecebc..e107aa40a--- a/wger/core/templates/navigation.html+++ b/wger/core/templates/navigation.html@@@ -50,10 -60,9 +60,9 @@@<li><a href="{% url 'exercise:exercise:add' %}">{% trans "Add new exercise" %}</a><li>{% endif %}- {% cache cache_timeout user-admin-exercises user.id language.id %}{% if perms.exercises %}<li class="divider"></li>- <li class="nav-header">{% trans "Administration" %}</li>+ <li class="dropdown-header">{% trans "Administration" %}</li><li><a href="{% url 'exercise:exercise:pending' %}">{% trans "Exercises pending review" %}</a></li><li><a href="{% url 'exercise:equipment:list' %}">{% trans "Equipment" %}</a></li>{% endif %}@@@ -91,10 -102,9 +102,9 @@@<li><a href="{% url 'nutrition:ingredient:list' %}">{% trans "Ingredient overview" %}</a></li><li><a href="{% url 'nutrition:bmi:view' %}" rel="nofollow">{% trans "BMI calculator" %}</a></li><li><a href="{% url 'nutrition:calories:view' %}" rel="nofollow">{% trans "Daily calories calculator" %}</a></li>- {% cache cache_timeout user-admin-ingredients user.id language.id %}{% if perms.exercises %}<li class="divider"></li>- <li class="nav-header">{% trans "Administration" %}</li>+ <li class="dropdown-header">{% trans "Administration" %}</li><li><a href="{% url 'nutrition:weight_unit:list' %}">{% trans "Ingredient weight units" %}</a></li><li><a href="{% url 'nutrition:ingredient:pending' %}">{% trans "Ingredients pending review" %}</a></li>{% endif %}diff --cc wger/exercises/tests/test_equipment.pyindex 31a93b728,71702e916..c610ac25e--- a/wger/exercises/tests/test_equipment.py+++ b/wger/exercises/tests/test_equipment.py@@@ -29,18 -29,26 +29,38 @@@ from wger.utils.cache import get_templafrom wger.utils.constants import PAGINATION_OBJECTS_PER_PAGE+class EquipmentRepresentationTestCase(WorkoutManagerTestCase):+ '''+ Test the representation of a model+ '''++ def test_representation(self):+ '''+ Test that the representation of an object is correct+ '''+ self.assertEqual("{0}".format(Equipment.objects.get(pk=1)), 'Dumbbells')+++ class EquipmentShareButtonTestCase(WorkoutManagerTestCase):+ '''+ Test that the share button is correctly displayed and hidden+ '''++ def test_share_button(self):+ url = reverse('exercise:equipment:overview')++ response = self.client.get(url)+ self.assertTrue(response.context['show_shariff'])++ self.user_login('admin')+ response = self.client.get(url)+ self.assertTrue(response.context['show_shariff'])++ self.user_login('test')+ response = self.client.get(url)+ self.assertTrue(response.context['show_shariff'])++class AddEquipmentTestCase(WorkoutManagerAddTestCase):'''Tests adding a new equipmentdiff --cc wger/exercises/tests/test_exercise.pyindex 333192deb,1247f2781..94c8de54b--- a/wger/exercises/tests/test_exercise.py+++ b/wger/exercises/tests/test_exercise.py@@@ -29,18 -29,27 +29,39 @@@ from wger.utils.cache import get_templafrom wger.utils.cache import cache_mapper+class ExerciseRepresentationTestCase(WorkoutManagerTestCase):+ '''+ Test the representation of a model+ '''++ def test_representation(self):+ '''+ Test that the representation of an object is correct+ '''+ self.assertEqual("{0}".format(Exercise.objects.get(pk=1)), 'An exercise')+++ class ExerciseShareButtonTestCase(WorkoutManagerTestCase):+ '''+ Test that the share button is correctly displayed and hidden+ '''++ def test_share_button(self):+ exercise = Exercise.objects.get(pk=1)+ url = exercise.get_absolute_url()++ response = self.client.get(url)+ self.assertTrue(response.context['show_shariff'])++ self.user_login('admin')+ response = self.client.get(url)+ self.assertTrue(response.context['show_shariff'])++ self.user_login('test')+ response = self.client.get(url)+ self.assertTrue(response.context['show_shariff'])++class ExerciseIndexTestCase(WorkoutManagerTestCase):def exercise_index(self, logged_in=True, demo=False, admin=False):diff --cc wger/exercises/tests/test_muscles.pyindex 4cff61d4e,5043436f7..09750a2d5--- a/wger/exercises/tests/test_muscles.py+++ b/wger/exercises/tests/test_muscles.py@@@ -26,18 -26,26 +26,38 @@@ from wger.manager.tests.testcase imporfrom wger.utils.cache import get_template_cache_name+class MuscleRepresentationTestCase(WorkoutManagerTestCase):+ '''+ Test the representation of a model+ '''++ def test_representation(self):+ '''+ Test that the representation of an object is correct+ '''+ self.assertEqual("{0}".format(Muscle.objects.get(pk=1)), 'Anterior testoid')+++ class MusclesShareButtonTestCase(WorkoutManagerTestCase):+ '''+ Test that the share button is correctly displayed and hidden+ '''++ def test_share_button(self):+ url = reverse('exercise:muscle:overview')++ response = self.client.get(url)+ self.assertTrue(response.context['show_shariff'])++ self.user_login('admin')+ response = self.client.get(url)+ self.assertTrue(response.context['show_shariff'])++ self.user_login('test')+ response = self.client.get(url)+ self.assertTrue(response.context['show_shariff'])++class AddMuscleTestCase(WorkoutManagerAddTestCase):'''Tests adding a musclediff --cc wger/manager/models.pyindex 03f714b42,d627d0ac3..8405a6260--- a/wger/manager/models.py+++ b/wger/manager/models.py@@@ -67,9 -65,9 +67,9 @@@ class Workout(models.Model)'''Returns the canonical URL to view a workout'''- return reverse('manager:workout:view', kwargs={'id': self.id})+ return reverse('manager:workout:view', kwargs={'pk': self.id})- def __unicode__(self):+ def __str__(self):'''Return a more human-readable representation'''diff --cc wger/nutrition/tests/test_plan.pyindex d562d7a31,825aec232..20296513b--- a/wger/nutrition/tests/test_plan.py+++ b/wger/nutrition/tests/test_plan.py@@@ -22,23 -22,69 +22,86 @@@ from wger.manager.tests.testcase imporfrom wger.manager.tests.testcase import WorkoutManagerTestCase+class PlanRepresentationTestCase(WorkoutManagerTestCase):+ '''+ Test the representation of a model+ '''++ def test_representation(self):+ '''+ Test that the representation of an object is correct+ '''+ p = NutritionPlan.objects.get(pk=5)+ self.assertEqual("{0}".format(p), 'Description 1')++ p.description = ''+ p.save()+ self.assertEqual("{0}".format(p), 'Nutrition plan')+++ class PlanShareButtonTestCase(WorkoutManagerTestCase):+ '''+ Test that the share button is correctly displayed and hidden+ '''++ def test_share_button(self):+ plan = NutritionPlan.objects.get(pk=5)+ url = plan.get_absolute_url()++ response = self.client.get(url)+ self.assertFalse(response.context['show_shariff'])++ self.user_login('admin')+ response = self.client.get(url)+ self.assertTrue(response.context['show_shariff'])++ self.user_login('test')+ response = self.client.get(url)+ self.assertFalse(response.context['show_shariff'])+++ class PlanAccessTestCase(WorkoutManagerTestCase):+ '''+ Test accessing the workout page+ '''++ def test_access_shared(self):+ '''+ Test accessing the URL of a shared workout+ '''+ plan = NutritionPlan.objects.get(pk=5)++ self.user_login('admin')+ response = self.client.get(plan.get_absolute_url())+ self.assertEqual(response.status_code, 200)++ self.user_login('test')+ response = self.client.get(plan.get_absolute_url())+ self.assertEqual(response.status_code, 200)++ self.user_logout()+ response = self.client.get(plan.get_absolute_url())+ self.assertEqual(response.status_code, 200)++ def test_access_not_shared(self):+ '''+ Test accessing the URL of a private workout+ '''+ plan = NutritionPlan.objects.get(pk=4)++ self.user_login('admin')+ response = self.client.get(plan.get_absolute_url())+ self.assertEqual(response.status_code, 403)++ self.user_login('test')+ response = self.client.get(plan.get_absolute_url())+ self.assertEqual(response.status_code, 200)++ self.user_logout()+ response = self.client.get(plan.get_absolute_url())+ self.assertEqual(response.status_code, 403)++class DeletePlanTestCase(WorkoutManagerDeleteTestCase):'''Tests deleting a nutritional plandiff --cc wger/utils/fields.pyindex 1e8ae557b,e75ef7b18..8f4a03cf3--- a/wger/utils/fields.py+++ b/wger/utils/fields.py@@@ -59,5 -60,10 +59,3 @@@ class Html5DateField(models.DateField)defaults = {'form_class': Html5FormDateField}defaults.update(kwargs)return super(Html5DateField, self).formfield(**defaults)-----#-# Add instrospection rules so south can still work with these fields-#-add_introspection_rules([], ["^wger\.utils\.fields\.Html5TimeField"])-add_introspection_rules([], ["^wger\.utils\.fields\.Html5DateField"])diff --cc wger/weight/tests/test_entry.pyindex 265358215,aad9c1eca..b27de9701--- a/wger/weight/tests/test_entry.py+++ b/wger/weight/tests/test_entry.py@@@ -24,18 -25,48 +25,60 @@@ from wger.manager.tests.testcase imporfrom wger.manager.tests.testcase import WorkoutManagerAddTestCase+class MealRepresentationTestCase(WorkoutManagerTestCase):+ '''+ Test the representation of a model+ '''++ def test_representation(self):+ '''+ Test that the representation of an object is correct+ '''+ self.assertEqual("{0}".format(WeightEntry.objects.get(pk=1)), '2012-10-01: 77.00 kg')+++ class WeightEntryAccessTestCase(WorkoutManagerTestCase):+ '''+ Test accessing the weight overview page+ '''++ def test_access_shared(self):+ '''+ Test accessing the URL of a shared weight overview+ '''+ url = reverse('weight:overview', kwargs={'username': 'admin'})++ self.user_login('admin')+ response = self.client.get(url)+ self.assertEqual(response.status_code, 200)++ self.user_login('test')+ response = self.client.get(url)+ self.assertEqual(response.status_code, 200)++ self.user_logout()+ response = self.client.get(url)+ self.assertEqual(response.status_code, 200)++ def test_access_not_shared(self):+ '''+ Test accessing the URL of an unshared weight overview+ '''+ url = reverse('weight:overview', kwargs={'username': 'test'})++ self.user_login('admin')+ response = self.client.get(url)+ self.assertEqual(response.status_code, 404)++ self.user_login('test')+ response = self.client.get(url)+ self.assertEqual(response.status_code, 200)++ self.user_logout()+ response = self.client.get(url)+ self.assertEqual(response.status_code, 404)++class AddWeightEntryTestCase(WorkoutManagerAddTestCase):'''Tests adding a weight entry