Self hosted FLOSS fitness/workout, nutrition and weight tracker
Separate the tests into individual files
Roland Geiderccabcb89a021
diff --git a/exercises/tests/__init__.py b/exercises/tests/__init__.pynew file mode 100644index 000000000..ca0569ef7--- /dev/null+++ b/exercises/tests/__init__.py@@ -0,0 +1,2 @@+from exercises.tests.categories import *+from exercises.tests.exercise import *\ No newline at end of filediff --git a/exercises/tests/categories.py b/exercises/tests/categories.pynew file mode 100644index 000000000..1c7a91567--- /dev/null+++ b/exercises/tests/categories.py@@ -0,0 +1,133 @@+# 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 exercises.models import Exercise+from exercises.models import ExerciseCategory++from exercises.tests.testcase import WorkoutManagerTestCase++class ExerciseCategoryTestCase(WorkoutManagerTestCase):+ """Exercise category test case"""++ def delete_category(self, fail = False):+ """Helper function to test deleting categories"""++ # Delete the category+ count_before = ExerciseCategory.objects.count()+ response = self.client.get(reverse('exercises.views.exercise_category_delete',+ kwargs={'id': 4}))+ count_after = ExerciseCategory.objects.count()++ # There is a redirect+ self.assertEqual(response.status_code, 302)++ # Check the deletion+ if fail:+ self.assertEqual(count_before,+ count_after,+ 'Category was deleted by unauthorzed user')+ else:+ self.assertTrue(count_before > count_after,+ 'Category was not deleted by authorized user')+++ def test_delete_category_unauthorized(self):+ """Test deleting a category by an unauthorized user"""++ self.user_login('test')+ self.delete_category(fail=True)+ self.user_logout()++ def test_delete_category_anonymous(self):+ """Test deleting a category by an anonymous user"""++ self.user_logout()+ self.delete_category(fail=True)+ self.user_logout()++ def test_delete_category_authorized(self):+ """Test deleting a category by an authorized user"""++ self.user_login()+ self.delete_category()+ self.user_logout()+++ def edit_category(self, fail = False):+ """Helper function to test editing categories"""++ category = ExerciseCategory.objects.get(pk = 3)+ old_name = category.name++ response = self.client.post(reverse('exercises.views.exercise_category_edit',+ kwargs={'id': 3}),+ {'name': 'A different name'})++ # There is a redirect+ self.assertEqual(response.status_code, 302)++ category = ExerciseCategory.objects.get(pk = 3)+ new_name = category.name+++ # Did it work+ if fail:+ self.assertEqual(old_name,+ new_name,+ 'Category was edited by unauthorzed user')+ else:+ self.assertTrue(old_name != new_name,+ 'Category wasnt deleted by unauthorzed user')+++ # No name+ if not fail:+ response = self.client.post(reverse('exercises.views.exercise_category_edit',+ kwargs={'id': 3}),+ {'name': ''})++ self.assertTrue(response.context['category_form'].errors['name'])++ def test_edit_category_unauthorized(self):+ """Test deleting a category by an unauthorized user"""++ self.user_login('test')+ self.edit_category(fail=True)+ self.user_logout()++ def test_edit_category_anonymous(self):+ """Test deleting a category by an anonymous user"""++ self.user_logout()+ self.edit_category(fail=True)+ self.user_logout()++ def test_edit_category_authorized(self):+ """Test deleting a category by an authorized user"""++ self.user_login()+ self.edit_category()+ self.user_logout()+diff --git a/exercises/tests.py b/exercises/tests/exercise.pysimilarity index 73%rename from exercises/tests.pyrename to exercises/tests/exercise.pyindex 99fce8255..f6f8cba86 100644--- a/exercises/tests.py+++ b/exercises/tests/exercise.py@@ -26,20 +26,9 @@ from django.core.urlresolvers import reversefrom exercises.models import Exercisefrom exercises.models import ExerciseCategory-class WorkoutManagerTestCase(TestCase):- fixtures = ['tests-user-data', 'test-exercises', ]-- def user_login(self, user='admin'):- """Login the user, by default as 'admin'- """- self.client.login(username=user, password='%(user)s%(user)s' % {'user': user})-- def user_logout(self):- """Visit the logout page- """- self.client.logout()+from exercises.tests.testcase import WorkoutManagerTestCase+-class ExerciseIndexTestCase(WorkoutManagerTestCase):def test_exercise_index(self):@@ -300,108 +289,4 @@ class ExercisesTestCase(WorkoutManagerTestCase):self.user_login()self.delete_exercise(fail=False)- self.user_logout()--class ExerciseCategoryTestCase(WorkoutManagerTestCase):- """Exercise category test case"""-- def delete_category(self, fail = False):- """Helper function to test deleting categories"""-- # Delete the category- count_before = ExerciseCategory.objects.count()- response = self.client.get(reverse('exercises.views.exercise_category_delete',- kwargs={'id': 4}))- count_after = ExerciseCategory.objects.count()-- # There is a redirect- self.assertEqual(response.status_code, 302)-- # Check the deletion- if fail:- self.assertEqual(count_before,- count_after,- 'Category was deleted by unauthorzed user')- else:- self.assertTrue(count_before > count_after,- 'Category was not deleted by authorized user')--- def test_delete_category_unauthorized(self):- """Test deleting a category by an unauthorized user"""-- self.user_login('test')- self.delete_category(fail=True)- self.user_logout()-- def test_delete_category_anonymous(self):- """Test deleting a category by an anonymous user"""-- self.user_logout()- self.delete_category(fail=True)- self.user_logout()-- def test_delete_category_authorized(self):- """Test deleting a category by an authorized user"""-- self.user_login()- self.delete_category()- self.user_logout()--- def edit_category(self, fail = False):- """Helper function to test editing categories"""-- category = ExerciseCategory.objects.get(pk = 3)- old_name = category.name-- response = self.client.post(reverse('exercises.views.exercise_category_edit',- kwargs={'id': 3}),- {'name': 'A different name'})-- # There is a redirect- self.assertEqual(response.status_code, 302)-- category = ExerciseCategory.objects.get(pk = 3)- new_name = category.name--- # Did it work- if fail:- self.assertEqual(old_name,- new_name,- 'Category was edited by unauthorzed user')- else:- self.assertTrue(old_name != new_name,- 'Category wasnt deleted by unauthorzed user')--- # No name- if not fail:- response = self.client.post(reverse('exercises.views.exercise_category_edit',- kwargs={'id': 3}),- {'name': ''})-- self.assertTrue(response.context['category_form'].errors['name'])-- def test_edit_category_unauthorized(self):- """Test deleting a category by an unauthorized user"""-- self.user_login('test')- self.edit_category(fail=True)- self.user_logout()-- def test_edit_category_anonymous(self):- """Test deleting a category by an anonymous user"""-- self.user_logout()- self.edit_category(fail=True)- self.user_logout()-- def test_edit_category_authorized(self):- """Test deleting a category by an authorized user"""-- self.user_login()- self.edit_category()- self.user_logout()-+ self.user_logout()\ No newline at end of file