Commit 2cdb711f authored by olavhdi's avatar olavhdi
Browse files

workouts PEP-8 and Django Code Styles #29

parent f1b901c2
Pipeline #126366 failed with stage
in 37 seconds
......@@ -2,6 +2,7 @@
Mixins for the workouts application
"""
class CreateListModelMixin:
"""Mixin that allows to create multiple objects from lists.
Taken from https://stackoverflow.com/a/48885641
......
......@@ -71,7 +71,7 @@ class Workout(models.Model):
class Exercise(models.Model):
"""Django model for an exercise type that users can create.
Each exercise instance must have an exercise type, e.g., Pushups, Crunches, or Lunges.
Each exercise instance must have an exercise type, e.g., Push-ups, Crunches, or Lunges.
Attributes:
name: Name of the exercise type
......
......@@ -3,6 +3,7 @@
import json
from rest_framework import parsers
# Thanks to https://stackoverflow.com/a/50514630
class MultipartJsonParser(parsers.MultiPartParser):
"""Parser for serializing multipart data containing both files and JSON.
......
......@@ -45,7 +45,7 @@ def mock_workout():
class IsOwnerTestCase(TestCase):
"""
Checks ownership permissions
Ownership permissions
"""
def setUp(self):
self.is_owner = IsOwner()
......@@ -55,20 +55,20 @@ class IsOwnerTestCase(TestCase):
def test_has_object_permission(self):
"""
Validates object permission
Object permission
"""
self.assertFalse(self.is_owner.has_object_permission(
self.assertIs(self.is_owner.has_object_permission(
self.request, None, self.workout.workout
))
), False)
self.request.user = self.workout.workout.owner
self.assertTrue(self.is_owner.has_object_permission(
self.assertIs(self.is_owner.has_object_permission(
self.request, None, self.workout.workout
))
), True)
class IsOwnerOfWorkoutTestCase(TestCase):
"""
Validates owner of workout permissions
Owner of workout permissions
"""
def setUp(self):
self.is_owner_of_workout = IsOwnerOfWorkout()
......@@ -77,11 +77,11 @@ class IsOwnerOfWorkoutTestCase(TestCase):
def test_has_permission_method(self):
"""
Get permission
GET permission
"""
request = mock_request()
request.method = "GET"
self.assertTrue(self.is_owner_of_workout.has_permission(request, None))
self.assertIs(self.is_owner_of_workout.has_permission(request, None), True)
def test_has_permission_workout(self):
"""
......@@ -90,7 +90,7 @@ class IsOwnerOfWorkoutTestCase(TestCase):
request = mock_request()
request.method = "POST"
request.data = {"workout": ""}
self.assertFalse(self.is_owner_of_workout.has_permission(request, None))
self.assertIs(self.is_owner_of_workout.has_permission(request, None), False)
def test_has_permission_user(self):
"""
......@@ -102,21 +102,21 @@ class IsOwnerOfWorkoutTestCase(TestCase):
request.data = {
"workout": "http://localhost:8000/api/workouts/1/"
}
self.assertTrue(self.is_owner_of_workout.has_permission(
self.assertIs(self.is_owner_of_workout.has_permission(
request, None
))
), True)
def test_has_object_permission(self):
"""
Ownership permissions
"""
self.assertFalse(self.is_owner_of_workout.has_object_permission(
self.assertIs(self.is_owner_of_workout.has_object_permission(
self.request, None, self.workout
))
), False)
self.request.user = self.workout.workout.owner
self.assertTrue(self.is_owner_of_workout.has_object_permission(
self.assertIs(self.is_owner_of_workout.has_object_permission(
self.request, None, self.workout
))
), True)
class IsCoachAndVisibleToCoachTestCase(TestCase):
......@@ -131,25 +131,25 @@ class IsCoachAndVisibleToCoachTestCase(TestCase):
def test_has_object_permission(self):
"""
Validates object permissions
Coach has object permissions
"""
self.assertFalse(self.is_coach_and_visible_to_coach.has_object_permission(
self.assertIs(self.is_coach_and_visible_to_coach.has_object_permission(
self.request,
None,
self.workout.workout
))
), False)
self.workout.workout.owner.coach = self.request.user
self.assertTrue(self.is_coach_and_visible_to_coach.has_object_permission(
self.assertIs(self.is_coach_and_visible_to_coach.has_object_permission(
self.request,
None,
self.workout.workout
))
), True)
class IsCoachOfWorkoutAndVisibleToCoachTestCase(TestCase):
"""
Validates coach relation and permissions for a specific workout
Coach permissions for a specific workout
"""
def setUp(self):
self.is_coach_of_workout_and_visible_to_coach = IsCoachOfWorkoutAndVisibleToCoach()
......@@ -159,25 +159,25 @@ class IsCoachOfWorkoutAndVisibleToCoachTestCase(TestCase):
def test_has_object_permission(self):
"""
Validates coach permissions
Coach permissions
"""
self.assertFalse(self.is_coach_of_workout_and_visible_to_coach.has_object_permission(
self.assertIs(self.is_coach_of_workout_and_visible_to_coach.has_object_permission(
self.request,
None,
self.workout
))
), False)
self.workout.workout.owner.coach = self.request.user
self.assertTrue(self.is_coach_of_workout_and_visible_to_coach.has_object_permission(
self.assertIs(self.is_coach_of_workout_and_visible_to_coach.has_object_permission(
self.request,
None,
self.workout
))
), True)
class IsPublicTestCase(TestCase):
"""
Validates test case public permissions
Test case public permissions
"""
def setUp(self):
self.workout = mock_workout()
......@@ -185,25 +185,25 @@ class IsPublicTestCase(TestCase):
def test_has_object_permission(self):
"""
Validates workout permissions
Workout permissions
"""
self.assertTrue(self.is_public.has_object_permission(
self.assertIs(self.is_public.has_object_permission(
None,
None,
self.workout.workout
))
), True)
self.workout.workout.visibility = "CO"
self.assertFalse(self.is_public.has_object_permission(
self.assertIs(self.is_public.has_object_permission(
None,
None,
self.workout.workout
))
), False)
class IsWorkoutPublicTestCase(TestCase):
"""
Checks that a workout is publicly available
Workout is publicly available
"""
def setUp(self):
self.workout = mock_workout()
......@@ -211,25 +211,25 @@ class IsWorkoutPublicTestCase(TestCase):
def test_has_object_permission(self):
"""
Validates workout permissions
Workout permissions
"""
self.assertTrue(self.is_workout_public.has_object_permission(
self.assertIs(self.is_workout_public.has_object_permission(
None,
None,
self.workout
))
), True)
self.workout.workout.visibility = "N"
self.assertFalse(self.is_workout_public.has_object_permission(
self.assertIs(self.is_workout_public.has_object_permission(
None,
None,
self.workout
))
), False)
class IsReadOnlyTestCase(TestCase):
"""
Checks that objects have the correct read only permission
Read only permission
"""
def setUp(self):
self.is_read_only = IsReadOnly()
......@@ -238,9 +238,9 @@ class IsReadOnlyTestCase(TestCase):
def test_has_object_permission(self):
"""
Validates that the test has the correct object permissions
Object permissions
"""
self.assertTrue(self.is_read_only.has_object_permission(self.request, None, None))
self.assertIs(self.is_read_only.has_object_permission(self.request, None, None), True)
self.request.method = None
self.assertFalse(self.is_read_only.has_object_permission(self.request, None, None))
self.assertIs(self.is_read_only.has_object_permission(self.request, None, None), False)
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