From 8d9cd11356386ca2ad15988a99f356454edfef83 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vegard=20Sporst=C3=B8l?= <vegarms@stud.ntnu.no>
Date: Sat, 6 Mar 2021 17:46:29 +0100
Subject: [PATCH] more work on tests

---
 backend/secfit/workouts/tests.py | 35 +++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/backend/secfit/workouts/tests.py b/backend/secfit/workouts/tests.py
index 181ad42..2424070 100644
--- a/backend/secfit/workouts/tests.py
+++ b/backend/secfit/workouts/tests.py
@@ -20,9 +20,9 @@ class NewWorkoutTestCase(TestCase):
         self.client = Client()
 
         # Create user
-        self.athlete = User.objects.create(username="user")
-        self.athlete.set_password('user')
-        self.athlete.save()
+        self.user = User.objects.create(username="user")
+        self.user.set_password('user')
+        self.user.save()
 
         # Authenticate user
         response = self.client.post('/api/token/', {'username': 'user', 'password': 'user'})
@@ -30,14 +30,11 @@ class NewWorkoutTestCase(TestCase):
         self.client.defaults['HTTP_AUTHORIZATION'] = 'Bearer ' + content['access']
 
     def test_newWorkoutRegistration(self):
-        """
-        data = {"name": "test", "date": "2021-03-06T12:11:30", 
-                "notes": "note", "visibility": "PU",
-                "owner": self.user}
+        response = self.client.post('/api/workouts/', {'name': 'test', 'date': '2021-03-06T18:00:00Z', 
+                                                       'notes': 'note', 'owner': self.user,
+                                                       'visibility': 'PU'})
+        self.assertEqual(response.status_code, 201)
 
-        response = self.client.post("/api/workouts/", data)
-        self.assertEqual(response.status_code, 201) #should work
-        """
 
 
 ### Test boundary values of new workout ###
@@ -50,6 +47,7 @@ class BoundaryValuesOfNewWorkout(TestCase):
         "test boundary values of new workout"
 
 
+
 ### Test FR5 - Visibility of details, files and comments for Athletes, Coaches and other users###
 
 class AthleteAccessTestCase(TestCase):
@@ -190,6 +188,7 @@ class UserAccessTestCase(TestCase):
         self.assertEqual(response.status_code, 403)
 
 
+
 ### Test create workout for athlete as coach ###
 
 class CreateWorkoutForAthleteTestCase(TestCase):
@@ -210,17 +209,29 @@ class CreateWorkoutForAthleteTestCase(TestCase):
         ""
 
 
+
 ### Test categorize exercise ###
 
 class CategorizeExerciseTestCase(TestCase):
     def setUp(self):
+        self.client = Client()
+
+        # Create user
         self.user = User.objects.create(username="user")
-        self.factory = RequestFactory()
+        self.user.set_password('user')
+        self.user.save()
+
+        # Authenticate user
+        response = self.client.post('/api/token/', {'username': 'user', 'password': 'user'})
+        content = json.loads(response.content)
+        self.client.defaults['HTTP_AUTHORIZATION'] = 'Bearer ' + content['access']
 
     def test_createCategorizedEcercise(self):
         data = {"name": "Test", "description": "Test", 
                 "category": "Endurance", "unit": "kg"}
-
+        
+        response = self.client.post("/api/exercises/", data)
+        self.assertEqual(response.status_code, 201)
     
 
 
-- 
GitLab