Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add test to check deletng exercise categories
Roland Geider3f3a43298ea6
diff --git a/exercises/fixtures/test-exercises.json b/exercises/fixtures/test-exercises.jsonindex 7d90bdc36..181c9730b 100644--- a/exercises/fixtures/test-exercises.json+++ b/exercises/fixtures/test-exercises.json@@ -62,6 +62,14 @@"name": "Yet another category","language": 2}+ },+ {+ "pk": 4,+ "model": "exercises.exercisecategory",+ "fields": {+ "name": "I will be deleted",+ "language": 1+ }},{"pk": 1,diff --git a/exercises/tests.py b/exercises/tests.pyindex 89ab3d191..287855988 100644--- a/exercises/tests.py+++ b/exercises/tests.py@@ -24,6 +24,7 @@ from django.test import TestCasefrom django.core.urlresolvers import reversefrom exercises.models import Exercise+from exercises.models import ExerciseCategoryclass WorkoutManagerTestCase(TestCase):fixtures = ['tests-user-data', 'test-exercises', ]@@ -261,7 +262,7 @@ class ExercisesTestCase(WorkoutManagerTestCase):def delete_exercise(self, fail=True):- """Helper function to test deleling exercises"""+ """Helper function to test deleting exercises"""# The exercise existsresponse = self.client.get(reverse('exercises.views.exercise_view', kwargs={'id': 3}))@@ -301,4 +302,50 @@ 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()+diff --git a/exercises/urls.py b/exercises/urls.pyindex 974474690..336104cf8 100644--- a/exercises/urls.py+++ b/exercises/urls.py@@ -7,7 +7,11 @@ urlpatterns = patterns('exercises.views',url(r'^exercise/view/(?P<id>\d+)/edit/comment/(?P<comment_id>\d+)$', 'exercise_view'),url(r'^exercise/edit/(?P<id>\d*)$', 'exercise_edit'),url(r'^exercise/delete/(?P<id>\d*)$', 'exercise_delete'),++ # Commentsurl(r'^exercise/comment/delete/(?P<id>\d+)$', 'exercisecomment_delete'),++ # Categoriesurl(r'^exercise/category/edit/(?P<id>\d*)$', 'exercise_category_edit'),url(r'^exercise/category/delete/(?P<id>\d*)$', 'exercise_category_delete'),