Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add some tests to the workout application
Roland Geider38a896c2a239
diff --git a/exercises/tests/categories.py b/exercises/tests/categories.pyindex 47d338e4f..4b115998e 100644--- a/exercises/tests/categories.py+++ b/exercises/tests/categories.py@@ -26,7 +26,7 @@ from django.core.urlresolvers import reversefrom exercises.models import Exercisefrom exercises.models import ExerciseCategory-from exercises.tests.testcase import WorkoutManagerTestCase+from manager.tests.testcase import WorkoutManagerTestCaseclass ExerciseCategoryTestCase(WorkoutManagerTestCase):"""Exercise category test case"""diff --git a/exercises/tests/exercise.py b/exercises/tests/exercise.pyindex 0ddb38524..c7b571af5 100644--- a/exercises/tests/exercise.py+++ b/exercises/tests/exercise.py@@ -26,7 +26,7 @@ from django.core.urlresolvers import reversefrom exercises.models import Exercisefrom exercises.models import ExerciseCategory-from exercises.tests.testcase import WorkoutManagerTestCase+from manager.tests.testcase import WorkoutManagerTestCaseclass ExerciseIndexTestCase(WorkoutManagerTestCase):@@ -289,4 +289,4 @@ class ExercisesTestCase(WorkoutManagerTestCase):self.user_login()self.delete_exercise(fail=False)- self.user_logout()\ No newline at end of file+ self.user_logout()diff --git a/manager/tests/__init__.py b/manager/tests/__init__.pynew file mode 100644index 000000000..aa6ac64ca--- /dev/null+++ b/manager/tests/__init__.py@@ -0,0 +1,2 @@+from manager.tests.index import *+from manager.tests.workout import *diff --git a/manager/tests/index.py b/manager/tests/index.pynew file mode 100644index 000000000..e1630e2c7--- /dev/null+++ b/manager/tests/index.py@@ -0,0 +1,69 @@+# 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+++"""+This file demonstrates writing tests using the unittest module. These will pass+when you run "manage.py test".++Replace this with more appropriate tests for your application.+"""++from django.test import TestCase+from django.core.urlresolvers import reverse++from manager.tests.testcase import WorkoutManagerTestCase++class DashboardTestCase(WorkoutManagerTestCase):+ """Dashboard (landing page) test case"""+++ def dashboard(self, logged_in = False):+ """Helper function to test the dashboard"""++ response = self.client.get(reverse('manager.views.index'))++ if logged_in:++ # Page exists+ self.assertEqual(response.status_code, 200)++ # Correct tab is selected+ self.assertEqual(response.context['active_tab'], 'user')++ # There is nothing else to send to the template+ self.assertEqual(response.context['weight'], False)+ self.assertEqual(response.context['current_workout'], False)+ self.assertEqual(response.context['plan'], False)++ else:+ # Anonymous users are redirected to the login page+ self.assertEqual(response.status_code, 302)+++ def test_dashboard_anonymous(self):+ '''Test index page as anonymous user'''++ self.user_logout()+ self.dashboard()+ self.user_logout()+++ def test_dashboard_logged_in(self):+ '''Test index page a logged in user'''++ self.user_login()+ self.dashboard(logged_in = True)+ self.user_logout()+diff --git a/exercises/tests/testcase.py b/manager/tests/testcase.pysimilarity index 100%rename from exercises/tests/testcase.pyrename to manager/tests/testcase.pydiff --git a/manager/tests/workout.py b/manager/tests/workout.pynew file mode 100644index 000000000..3c7f176c6--- /dev/null+++ b/manager/tests/workout.py@@ -0,0 +1,90 @@+# 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++from django.test import TestCase+from django.core.urlresolvers import reverse++from manager.models import TrainingSchedule++from manager.tests.testcase import WorkoutManagerTestCase++++class AddWorkoutTestCase(WorkoutManagerTestCase):+ """Tests adding a Workout"""++ def create_workout(self, logged_in = False):+ """Helper function to test creating workouts"""++ # Create a workout+ count_before = TrainingSchedule.objects.count()+ response = self.client.get(reverse('manager.views.add'))+ count_after = TrainingSchedule.objects.count()++ if logged_in:+ self.assertTrue(count_after > count_before)+ else:+ self.assertEqual(count_before, count_after)+ self.assertTrue(count_after == 0)+++ def test_create_workout_anonymous(self):+ '''Test creating a workout as anonymous user'''++ self.user_logout()+ self.create_workout()+ self.user_logout()+++ def test_create_workout_logged_in(self):+ '''Test creating a workout a logged in user'''+ self.user_login()+ self.create_workout(logged_in = True)+ self.user_logout()++class WorkoutOverviewTestCase(WorkoutManagerTestCase):+ """Tests the workout overview"""++ def get_wotkout_overview(self, logged_in = False):+ """Helper function to test the workout overview"""++ response = self.client.post(reverse('manager.views.overview'))++ # Page exists+ if logged_in:+ self.assertEqual(response.status_code, 200)+ self.assertEqual(response.context['active_tab'], 'workout')+ else:+ self.assertEqual(response.status_code, 302)+ return++ # No data sent to the template+ self.assertFalse(response.context['workouts'])++++ def test_dashboard_anonymous(self):+ '''Test creating a workout as anonymous user'''+ self.user_logout()+ self.get_wotkout_overview()+ self.user_logout()+++ def test_dashboard_logged_in(self):+ '''Test creating a workout a logged in user'''+ self.user_login()+ self.get_wotkout_overview(logged_in = True)+ self.user_logout()++