Commit 4ff469bb authored by olavhdi's avatar olavhdi
Browse files

dependency rollback

parent 34605243
Pipeline #128082 passed with stage
in 32 seconds
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -2,7 +2,6 @@
Tests for the workouts application.
"""
import datetime
from recordclass import recordclass
from rest_framework import permissions
import pytz
from django.test import TestCase
......@@ -14,33 +13,35 @@ from workouts.models import Workout
from users.models import User
def mock_request():
class MockRequest:
"""
Mocks a mutable request
Imitates a (mutable) request
"""
mock = recordclass('MockRequest', ['method', 'data', 'user'])
return mock("", "", None)
def __init__(self):
self.method = ""
self.data = ""
self.user = None
def mock_workout():
class MockWorkout:
"""
Mocks a workout
Imitates a workout
"""
try:
user = User.objects.get(pk='1')
except User.DoesNotExist:
user = User.objects.create()
workout_data = {
"name": "Test Workout",
"date": datetime.datetime(2021, 2, 19, 9, 33, 0, 0, pytz.UTC),
"notes": "notes",
"visibility": "PU",
"owner": user
}
workout = Workout.objects.create(**workout_data)
workout.owner.coach = User()
mock = recordclass('MockWorkout', ['workout'])
return mock(workout)
def __init__(self):
try:
user = User.objects.get(pk='1')
except User.DoesNotExist:
user = User.objects.create()
workout_data = {
"name": "Test Workout",
"date": datetime.datetime(2021, 2, 19, 9, 33, 0, 0, pytz.UTC),
"notes": "notes",
"visibility": "PU",
"owner": user
}
self.workout = Workout.objects.create(**workout_data)
self.workout.owner.coach = User()
class IsOwnerTestCase(TestCase):
......@@ -49,8 +50,8 @@ class IsOwnerTestCase(TestCase):
"""
def setUp(self):
self.is_owner = IsOwner()
self.request = mock_request()
self.workout = mock_workout()
self.request = MockRequest()
self.workout = MockWorkout()
self.request.user = User()
def test_has_object_permission(self):
......@@ -72,14 +73,14 @@ class IsOwnerOfWorkoutTestCase(TestCase):
"""
def setUp(self):
self.is_owner_of_workout = IsOwnerOfWorkout()
self.request = mock_request()
self.workout = mock_workout()
self.request = MockRequest()
self.workout = MockWorkout()
def test_has_permission_method(self):
"""
GET permission
"""
request = mock_request()
request = MockRequest()
request.method = "GET"
self.assertIs(self.is_owner_of_workout.has_permission(request, None), True)
......@@ -87,7 +88,7 @@ class IsOwnerOfWorkoutTestCase(TestCase):
"""
POST workout permission
"""
request = mock_request()
request = MockRequest()
request.method = "POST"
request.data = {"workout": ""}
self.assertIs(self.is_owner_of_workout.has_permission(request, None), False)
......@@ -96,7 +97,7 @@ class IsOwnerOfWorkoutTestCase(TestCase):
"""
POST workout permission via REST API
"""
request = mock_request()
request = MockRequest()
request.method = "POST"
request.user = self.workout.workout.owner
request.data = {
......@@ -125,9 +126,9 @@ class IsCoachAndVisibleToCoachTestCase(TestCase):
"""
def setUp(self):
self.is_coach_and_visible_to_coach = IsCoachAndVisibleToCoach()
self.request = mock_request()
self.request = MockRequest()
self.request.user = User()
self.workout = mock_workout()
self.workout = MockWorkout()
def test_has_object_permission(self):
"""
......@@ -153,9 +154,9 @@ class IsCoachOfWorkoutAndVisibleToCoachTestCase(TestCase):
"""
def setUp(self):
self.is_coach_of_workout_and_visible_to_coach = IsCoachOfWorkoutAndVisibleToCoach()
self.request = mock_request()
self.request = MockRequest()
self.request.user = User()
self.workout = mock_workout()
self.workout = MockWorkout()
def test_has_object_permission(self):
"""
......@@ -180,7 +181,7 @@ class IsPublicTestCase(TestCase):
Test case public permissions
"""
def setUp(self):
self.workout = mock_workout()
self.workout = MockWorkout()
self.is_public = IsPublic()
def test_has_object_permission(self):
......@@ -206,7 +207,7 @@ class IsWorkoutPublicTestCase(TestCase):
Workout is publicly available
"""
def setUp(self):
self.workout = mock_workout()
self.workout = MockWorkout()
self.is_workout_public = IsWorkoutPublic()
def test_has_object_permission(self):
......@@ -233,7 +234,7 @@ class IsReadOnlyTestCase(TestCase):
"""
def setUp(self):
self.is_read_only = IsReadOnly()
self.request = mock_request()
self.request = MockRequest()
self.request.method = permissions.SAFE_METHODS.__getitem__(1)
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