Commit 0cffec9e authored by Andreasjj's avatar Andreasjj
Browse files

added comments

parent f1f0d8e8
Pipeline #113309 passed with stages
in 2 minutes and 7 seconds
......@@ -11,6 +11,7 @@ from workouts.models import Workout, Exercise, ExerciseInstance, WorkoutFile, Re
# ******************** START Permissions ********************
class PermissionTestCase(TestCase):
def setUp(self):
# Create class global objects that can be used in multilpe tests
self.requester = MagicMock()
self.request = MagicMock(user = self.requester)
self.view = MagicMock()
......@@ -26,26 +27,26 @@ class PermissionTestCase(TestCase):
permission = IsOwner()
# The workoutfile owned by the requester
workoutFile = MagicMock(workout = self.workout, owner = self.requester)
# Check that
# Test that the pemission function works as expected
self.assertTrue(permission.has_object_permission(self.request, self.view, workoutFile))
# Check that
self.assertFalse(permission.has_object_permission(self.request, self.view, self.workoutFile))
def test_IsOwnerOfWorkout(self):
# Permission class to test
permission = IsOwnerOfWorkout()
#
# Create object with owner of workout is the requester
owned_workout = MagicMock(owner = self.requester)
owned_obj = MagicMock(workout = owned_workout)
# Create object with owner of workout not requester
not_owned_objc = MagicMock(workout = self.workout)
#
# Test that the pemission function works as expected
self.assertTrue(permission.has_object_permission(self.request, self.view, owned_obj))
self.assertFalse(permission.has_object_permission(self.request, self.view, not_owned_objc))
def test_test_IsOwnerOfWorkout_has_permission(self):
# Permission class to test
permission = IsOwnerOfWorkout()
#
# The database users and workout objects needed for the has_permission test
test_owner = User.objects.create(
username = "test",
email = "test@test.com",
......@@ -60,7 +61,7 @@ class PermissionTestCase(TestCase):
notes = "test",
owner = test_owner
)
# Requests
# Requests objects for different scenarios
post_request_owner = MagicMock(
user = test_owner,
method = "POST",
......@@ -92,37 +93,38 @@ class PermissionTestCase(TestCase):
def test_IsCoachAndVisibleToCoach(self):
# Permission class to test
permission = IsCoachAndVisibleToCoach()
#
# Create an object with the coach as the requester
owner = MagicMock(coach = self.requester)
obj = MagicMock(owner = owner)
# Create an object with the coach as a user not the requester
new_coach = MagicMock()
not_requester_owner = MagicMock(coach = new_coach)
not_requester_obj = MagicMock(owner = not_requester_owner)
#
# Test that the pemission function works as expected
self.assertTrue(permission.has_object_permission(self.request, self.view, obj))
self.assertFalse(permission.has_object_permission(self.request, self.view, not_requester_obj))
def test_IsCoachOfWorkoutAndVisibleToCoach(self):
# Permission class to test
permission = IsCoachOfWorkoutAndVisibleToCoach()
#
# Create an object where the owner of the workout has a coach which is the requester
owner = MagicMock(coach = self.requester)
workout = MagicMock(owner = owner)
obj = MagicMock(workout = workout)
# Create an object with a workout, with an owner, who has a coach that is not the requester
new_coach = MagicMock()
not_requester_owner = MagicMock(coach = new_coach)
not_requester_workout = MagicMock(owner = not_requester_owner)
not_requester_obj = MagicMock(workout = not_requester_workout)
#
# Test that the pemission function works as expected
self.assertTrue(permission.has_object_permission(self.request, self.view, obj))
self.assertFalse(permission.has_object_permission(self.request, self.view, not_requester_obj))
def test_IsPublic(self):
# Permission class to test
permission = IsPublic()
#
# Test that the pemission function works as expected
self.assertTrue(permission.has_object_permission(self.request, self.view, self.public_workout))
self.assertFalse(permission.has_object_permission(self.request, self.view, self.private_workout))
self.assertFalse(permission.has_object_permission(self.request, self.view, self.coach_workout))
......@@ -130,11 +132,11 @@ class PermissionTestCase(TestCase):
def test_IsWorkoutPublic(self):
# Permission class to test
permission = IsWorkoutPublic()
#
# Create objects where their workout is public, private, and coach
obj_public = MagicMock(workout = self.public_workout)
obj_private = MagicMock(workout = self.private_workout)
obj_coach = MagicMock(workout = self.coach_workout)
#
# Test that the pemission function works as expected
self.assertTrue(permission.has_object_permission(self.request, self.view, obj_public))
self.assertFalse(permission.has_object_permission(self.request, self.view, obj_private))
self.assertFalse(permission.has_object_permission(self.request, self.view, obj_coach))
......@@ -159,8 +161,4 @@ class PermissionTestCase(TestCase):
self.assertFalse(permission.has_object_permission(PUT_request, self.view, self.workout))
self.assertFalse(permission.has_object_permission(PATCH_request, self.view, self.workout))
self.assertFalse(permission.has_object_permission(INVALID_request, self.view, self.workout))
# ********************* END Permissions *********************
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment