Commit f1b901c2 authored by olavhdi's avatar olavhdi
Browse files

Workouts more PYLINT #28

parent abbc6572
Pipeline #126360 failed with stage
in 13 seconds
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
Mixins for the workouts application Mixins for the workouts application
""" """
class CreateListModelMixin: class CreateListModelMixin:
"""Mixin that allows to create multiple objects from lists. """Mixin that allows to create multiple objects from lists.
Taken from https://stackoverflow.com/a/48885641 Taken from https://stackoverflow.com/a/48885641
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
Tests for the workouts application. Tests for the workouts application.
""" """
import datetime import datetime
from recordclass import recordclass
from rest_framework import permissions from rest_framework import permissions
import pytz import pytz
from django.test import TestCase from django.test import TestCase
...@@ -13,36 +14,33 @@ from workouts.models import Workout ...@@ -13,36 +14,33 @@ from workouts.models import Workout
from users.models import User from users.models import User
# Create your tests here. def mock_request():
class MockRequest:
""" """
Mocks a request Mocks a mutable request
""" """
def __init__(self): mock = recordclass('MockRequest', ['method', 'data', 'user'])
self.method = "" return mock("", "", None)
self.data = ""
self.user = None
class MockWorkout: def mock_workout():
""" """
Mocks a workout for testing Mocks a workout
""" """
def __init__(self): try:
try: user = User.objects.get(pk='1')
user = User.objects.get(pk='1') except User.DoesNotExist:
except User.DoesNotExist: user = User.objects.create()
user = User.objects.create() workout_data = {
"name": "Test Workout",
workout_data = { "date": datetime.datetime(2021, 2, 19, 9, 33, 0, 0, pytz.UTC),
"name": "Test Workout", "notes": "notes",
"date": datetime.datetime(2021, 2, 19, 9, 33, 0, 0, pytz.UTC), "visibility": "PU",
"notes": "notes", "owner": user
"visibility": "PU", }
"owner": user workout = Workout.objects.create(**workout_data)
} workout.owner.coach = User()
self.workout = Workout.objects.create(**workout_data) mock = recordclass('MockWorkout', ['workout'])
self.workout.owner.coach = User() return mock(workout)
class IsOwnerTestCase(TestCase): class IsOwnerTestCase(TestCase):
...@@ -51,8 +49,8 @@ class IsOwnerTestCase(TestCase): ...@@ -51,8 +49,8 @@ class IsOwnerTestCase(TestCase):
""" """
def setUp(self): def setUp(self):
self.is_owner = IsOwner() self.is_owner = IsOwner()
self.request = MockRequest() self.request = mock_request()
self.workout = MockWorkout() self.workout = mock_workout()
self.request.user = User() self.request.user = User()
def test_has_object_permission(self): def test_has_object_permission(self):
...@@ -74,14 +72,14 @@ class IsOwnerOfWorkoutTestCase(TestCase): ...@@ -74,14 +72,14 @@ class IsOwnerOfWorkoutTestCase(TestCase):
""" """
def setUp(self): def setUp(self):
self.is_owner_of_workout = IsOwnerOfWorkout() self.is_owner_of_workout = IsOwnerOfWorkout()
self.request = MockRequest() self.request = mock_request()
self.workout = MockWorkout() self.workout = mock_workout()
def test_has_permission_method(self): def test_has_permission_method(self):
""" """
Get permission Get permission
""" """
request = MockRequest() request = mock_request()
request.method = "GET" request.method = "GET"
self.assertTrue(self.is_owner_of_workout.has_permission(request, None)) self.assertTrue(self.is_owner_of_workout.has_permission(request, None))
...@@ -89,7 +87,7 @@ class IsOwnerOfWorkoutTestCase(TestCase): ...@@ -89,7 +87,7 @@ class IsOwnerOfWorkoutTestCase(TestCase):
""" """
POST workout permission POST workout permission
""" """
request = MockRequest() request = mock_request()
request.method = "POST" request.method = "POST"
request.data = {"workout": ""} request.data = {"workout": ""}
self.assertFalse(self.is_owner_of_workout.has_permission(request, None)) self.assertFalse(self.is_owner_of_workout.has_permission(request, None))
...@@ -98,7 +96,7 @@ class IsOwnerOfWorkoutTestCase(TestCase): ...@@ -98,7 +96,7 @@ class IsOwnerOfWorkoutTestCase(TestCase):
""" """
POST workout permission via REST API POST workout permission via REST API
""" """
request = MockRequest() request = mock_request()
request.method = "POST" request.method = "POST"
request.user = self.workout.workout.owner request.user = self.workout.workout.owner
request.data = { request.data = {
...@@ -127,9 +125,9 @@ class IsCoachAndVisibleToCoachTestCase(TestCase): ...@@ -127,9 +125,9 @@ class IsCoachAndVisibleToCoachTestCase(TestCase):
""" """
def setUp(self): def setUp(self):
self.is_coach_and_visible_to_coach = IsCoachAndVisibleToCoach() self.is_coach_and_visible_to_coach = IsCoachAndVisibleToCoach()
self.request = MockRequest() self.request = mock_request()
self.request.user = User() self.request.user = User()
self.workout = MockWorkout() self.workout = mock_workout()
def test_has_object_permission(self): def test_has_object_permission(self):
""" """
...@@ -155,9 +153,9 @@ class IsCoachOfWorkoutAndVisibleToCoachTestCase(TestCase): ...@@ -155,9 +153,9 @@ class IsCoachOfWorkoutAndVisibleToCoachTestCase(TestCase):
""" """
def setUp(self): def setUp(self):
self.is_coach_of_workout_and_visible_to_coach = IsCoachOfWorkoutAndVisibleToCoach() self.is_coach_of_workout_and_visible_to_coach = IsCoachOfWorkoutAndVisibleToCoach()
self.request = MockRequest() self.request = mock_request()
self.request.user = User() self.request.user = User()
self.workout = MockWorkout() self.workout = mock_workout()
def test_has_object_permission(self): def test_has_object_permission(self):
""" """
...@@ -182,7 +180,7 @@ class IsPublicTestCase(TestCase): ...@@ -182,7 +180,7 @@ class IsPublicTestCase(TestCase):
Validates test case public permissions Validates test case public permissions
""" """
def setUp(self): def setUp(self):
self.workout = MockWorkout() self.workout = mock_workout()
self.is_public = IsPublic() self.is_public = IsPublic()
def test_has_object_permission(self): def test_has_object_permission(self):
...@@ -208,7 +206,7 @@ class IsWorkoutPublicTestCase(TestCase): ...@@ -208,7 +206,7 @@ class IsWorkoutPublicTestCase(TestCase):
Checks that a workout is publicly available Checks that a workout is publicly available
""" """
def setUp(self): def setUp(self):
self.workout = MockWorkout() self.workout = mock_workout()
self.is_workout_public = IsWorkoutPublic() self.is_workout_public = IsWorkoutPublic()
def test_has_object_permission(self): def test_has_object_permission(self):
...@@ -235,7 +233,7 @@ class IsReadOnlyTestCase(TestCase): ...@@ -235,7 +233,7 @@ class IsReadOnlyTestCase(TestCase):
""" """
def setUp(self): def setUp(self):
self.is_read_only = IsReadOnly() self.is_read_only = IsReadOnly()
self.request = MockRequest() self.request = mock_request()
self.request.method = permissions.SAFE_METHODS.__getitem__(1) self.request.method = permissions.SAFE_METHODS.__getitem__(1)
def test_has_object_permission(self): def test_has_object_permission(self):
......
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