Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add tests for workout log
Roland Geider85db6442a19d
diff --git a/manager/tests/__init__.py b/manager/tests/__init__.pyindex c1f8bb01c..c6d5f09e5 100644--- a/manager/tests/__init__.py+++ b/manager/tests/__init__.py@@ -1,3 +1,4 @@from manager.tests.index import *from manager.tests.workout import *+from manager.tests.weight_log import *from manager.tests.log import *diff --git a/manager/tests/weight_log.py b/manager/tests/weight_log.pynew file mode 100644index 000000000..cc9c9788a--- /dev/null+++ b/manager/tests/weight_log.py@@ -0,0 +1,97 @@+# 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++import logging++from django.test import TestCase+from django.core.urlresolvers import reverse++from manager.models import WorkoutLog++from manager.tests.testcase import WorkoutManagerTestCase++logger = logging.getLogger('workout_manager.custom')+++class WeightLogTestCase(WorkoutManagerTestCase):+ '''+ Tests the weight log functionalit+ '''++ def add_weight_log(self, fail=True):+ '''+ Helper function to test adding weight log entries+ '''++ # Fetch the overview page+ response = self.client.get(reverse('workout-log', kwargs={'pk': 1}))++ if fail:+ # Logged out users get a 302 redirect to login page+ # Users not owning the workout, a 403, forbidden+ self.assertTrue(response.status_code in (302, 403))+ else:+ self.assertEqual(response.status_code, 200)+ self.assertEqual(response.context['active_tab'], 'workout')+ self.assertEqual(response.context['workout'].id, 1)++ # Add new log entries+ count_before = WorkoutLog.objects.count()+ response = self.client.post(reverse('day-log', kwargs={'pk': 1}),+ {'date': '2012-01-01',+ 'form-0-reps': 10,+ 'form-0-weight': 10,+ 'form-TOTAL_FORMS': 3,+ 'form-INITIAL_FORMS': 0,+ 'form-MAX-NUM_FORMS': 3+ })++ count_after = WorkoutLog.objects.count()++ if fail:+ # Logged out users get a 302 redirect to login page+ # Users not owning the workout, a 403, forbidden+ self.assertTrue(response.status_code in (302, 403))++ self.assertEqual(count_before, count_after)+ else:+ self.assertEqual(response.status_code, 302)+ self.assertGreater(count_after, count_before)+++ def test_add_weight_log_anonymous(self):+ '''+ Tests adding weight log entries as an anonymous user+ '''++ self.add_weight_log(fail=True)+++ def test_add_weight_log_logged_in(self):+ '''+ Tests adding weight log entries as a logged in user+ '''++ self.user_login('admin')+ self.add_weight_log(fail=False)+++ def test_add_weight_log_other(self):+ '''+ Tests adding weight log entries as a logged user not owning the data+ '''++ self.user_login('test')+ self.add_weight_log(fail=True)+