Self hosted FLOSS fitness/workout, nutrition and weight tracker
Update test suite
Roland Geiderafa6a812c70f
diff --git a/wger/exercises/tests/categories.py b/wger/exercises/tests/categories.pyindex 6a4e9780f..0033ec8b6 100644--- a/wger/exercises/tests/categories.py+++ b/wger/exercises/tests/categories.py@@ -17,69 +17,25 @@ from django.core.urlresolvers import reversefrom wger.exercises.models import ExerciseCategoryfrom wger.manager.tests.testcase import WorkoutManagerTestCase+from wger.manager.tests.testcase import WorkoutManagerDeleteTestCase-class ExerciseCategoryTestCase(WorkoutManagerTestCase):+class DeleteExerciseCategoryTestCase(WorkoutManagerDeleteTestCase):'''- Exercise category test case+ Exercise category delete test case'''- def delete_category(self, fail=False):- '''- Helper function to test deleting categories- '''-- response = self.client.get(reverse('exercisecategory-delete',- kwargs={'pk': 4}))- # Can the user access the page- if fail:- self.assertEqual(response.status_code, 302)- else:- self.assertEqual(response.status_code, 200)-- # Delete the category- count_before = ExerciseCategory.objects.count()- response = self.client.post(reverse('exercisecategory-delete',- kwargs={'pk': 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)-- def test_delete_category_anonymous(self):- '''- Test deleting a category by an anonymous user- '''+ delete_class = ExerciseCategory+ delete_url = 'exercisecategory-delete'+ pk = 4+ user_success = 'admin'+ user_fail = 'test'- 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()+class EditExerciseCategoryTestCase(WorkoutManagerTestCase):+ '''+ Exercise category test case+ '''def edit_category(self, fail=False):'''@@ -148,6 +104,12 @@ class ExerciseCategoryTestCase(WorkoutManagerTestCase):self.user_login()self.edit_category()++class AddExerciseCategoryTestCase(WorkoutManagerTestCase):+ '''+ Exercise category test case+ '''+def add_category(self, fail=False):'''Helper function to test adding categories@@ -188,7 +150,7 @@ class ExerciseCategoryTestCase(WorkoutManagerTestCase):Test adding a category by an anonymous user'''- self.edit_category(fail=True)+ self.add_category(fail=True)def test_add_category_authorized(self):'''diff --git a/wger/exercises/tests/exercise.py b/wger/exercises/tests/exercise.pyindex 4f82924f0..4bd74c42c 100644--- a/wger/exercises/tests/exercise.py+++ b/wger/exercises/tests/exercise.py@@ -19,6 +19,7 @@ from django.core.urlresolvers import reversefrom wger.exercises.models import Exercisefrom wger.manager.tests.testcase import WorkoutManagerTestCase+from wger.manager.tests.testcase import WorkoutManagerDeleteTestCaseclass ExerciseIndexTestCase(WorkoutManagerTestCase):@@ -184,66 +185,6 @@ class ExercisesTestCase(WorkoutManagerTestCase):self.assertTrue(response.context['form'].errors['muscles'])self.user_logout()- def delete_exercise(self, fail=True):- '''- Helper function to test deleting exercises- '''-- # The exercise exists- response = self.client.get(reverse('wger.exercises.views.exercise_view', kwargs={'id': 3}))- self.assertEqual(response.status_code, 200)-- # Delete the exercise- count_before = Exercise.objects.count()-- # GET request, doesn't delete anything- response = self.client.get(reverse('exercise-delete', kwargs={'pk': 3}))- count_after = Exercise.objects.count()- self.assertEqual(count_before, count_after, 'Exercise was deleted')-- # Check the deletion- if fail:- self.assertEqual(response.status_code, 302)- else:- self.assertEqual(response.status_code, 200)-- # POST request, does delete the exercise- response = self.client.post(reverse('exercise-delete', kwargs={'pk': 3}))- count_after = Exercise.objects.count()-- self.assertEqual(response.status_code, 302)-- # Check the deletion- if fail:- self.assertEqual(count_before, count_after, 'Exercise was deleted')- else:- self.assertTrue(count_before > count_after, 'Exercise was not deleted')-- def test_delete_exercise_anonymous(self, fail=True):- '''- Test deleting an exercise by an anonymous user- '''-- self.delete_exercise()-- def test_delete_exercise_unauthorized(self, fail=True):- '''- Test deleting an exercise by an unauthorized user- '''-- self.user_login('test')- self.delete_exercise()- self.user_logout()-- def test_delete_exercise_authorized(self):- '''- Test deleting an exercise by an authorized user- '''-- self.user_login()- self.delete_exercise(fail=False)- self.user_logout()-def search_exercise(self, fail=True):'''Helper function to test searching for exercises@@ -289,3 +230,15 @@ class ExercisesTestCase(WorkoutManagerTestCase):self.user_login()self.search_exercise(fail=False)self.user_logout()+++class DeleteExercisesTestCase(WorkoutManagerDeleteTestCase):+ '''+ Exercise test case+ '''++ delete_class = Exercise+ delete_url = 'exercise-delete'+ pk = 2+ user_success = 'admin'+ user_fail = 'test'diff --git a/wger/manager/tests/testcase.py b/wger/manager/tests/testcase.pyindex eaf37f774..c1acd1bf0 100644--- a/wger/manager/tests/testcase.py+++ b/wger/manager/tests/testcase.py@@ -59,13 +59,16 @@ class WorkoutManagerTestCase(TestCase):class WorkoutManagerDeleteTestCase(WorkoutManagerTestCase):'''- Tests deleting an object as the owner, a different user and a logged out- one.+ Tests deleting an object an authorized user, a different one and a logged out+ one. This assumes the delete action is only triggered with a POST request and+ GET will only show a confirmation dialog.'''delete_class = ''delete_url = ''- pk = ''+ pk = None+ user_success = 'admin'+ user_fail = 'test'def delete_object(self, fail=False):'''@@ -108,18 +111,18 @@ class WorkoutManagerDeleteTestCase(WorkoutManagerTestCase):self.delete_object(fail=True)- def test_delete_object_owner(self):+ def test_delete_object_authorized(self):'''- Tests deleting the object as the owner user+ Tests deleting the object as an authorized user'''- self.user_login('test')+ self.user_login(self.user_success)self.delete_object(fail=False)def test_delete_object_other(self):'''- Tests deleting the object as a logged in user not owning the data+ Tests deleting the object as an unauthorized, logged in user'''- self.user_login('admin')+ self.user_login(self.user_fail)self.delete_object(fail=True)diff --git a/wger/nutrition/tests/ingredient.py b/wger/nutrition/tests/ingredient.pyindex 9b2dd33af..2635bca31 100644--- a/wger/nutrition/tests/ingredient.py+++ b/wger/nutrition/tests/ingredient.py@@ -19,66 +19,17 @@ from django.core.urlresolvers import reversefrom wger.nutrition.models import Ingredientfrom wger.manager.tests.testcase import WorkoutManagerTestCase+from wger.manager.tests.testcase import WorkoutManagerDeleteTestCase-class DeleteIngredientTestCase(WorkoutManagerTestCase):+class DeleteIngredientTestCase(WorkoutManagerDeleteTestCase):'''Tests deleting an ingredient'''- def delete_ingredient(self, fail=False):- '''- Helper function to test deleting an ingredient- '''+ delete_class = Ingredient+ delete_url = 'ingredient-delete'+ pk = 1+ user_success = 'admin'+ user_fail = 'test'- # Fetch the edit page- count_before = Ingredient.objects.count()- response = self.client.get(reverse('ingredient-delete', kwargs={'pk': 1}))- count_after = Ingredient.objects.count()-- self.assertEqual(count_before, count_after)-- if fail:- self.assertIn(response.status_code, (302, 403))- self.assertTemplateUsed('login.html')-- else:- self.assertEqual(response.status_code, 200)-- # Try to delete the ingredient- count_before = Ingredient.objects.count()- response = self.client.post(reverse('ingredient-delete', kwargs={'pk': 1}))- count_after = Ingredient.objects.count()-- if fail:- self.assertIn(response.status_code, (302, 403))- self.assertTemplateUsed('login.html')- self.assertEqual(count_before, count_after)-- else:- self.assertRaises(Ingredient.DoesNotExist, Ingredient.objects.get, pk=1)- self.assertEqual(response.status_code, 302)- self.assertEqual(count_before - 1, count_after)-- def test_delete_ingredient_anonymous(self):- '''- Test deleting an ingredient as an anonymous users- '''-- self. delete_ingredient(fail=True)-- def test_delete_ingredient_authorized(self):- '''- Test deleting an ingredient as an authorized user- '''-- self.user_login('admin')- self.delete_ingredient(fail=False)-- def test_delete_ingredient_other(self):- '''- Test deleting an ingredient as an unauthorized, logged in user- '''-- self.user_login('test')- self.delete_ingredient(fail=True)