From b576d8ca8f1d0d75bb1daea40e5655b5a24d4cc2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tobias=20=C3=98rstad?= <tobiasio@ntnu.no>
Date: Sun, 7 Mar 2021 15:43:29 +0100
Subject: [PATCH] Complete likes integration test

---
 backend/secfit/workouts/tests.py | 39 ++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/backend/secfit/workouts/tests.py b/backend/secfit/workouts/tests.py
index 63f8f46..b747da6 100644
--- a/backend/secfit/workouts/tests.py
+++ b/backend/secfit/workouts/tests.py
@@ -576,7 +576,6 @@ class LeaderboardIntegrationTestCase(TestCase):
         self.client2 = APIClient()
         self.client2.force_authenticate(user=self.user_2)
         self.client.post('http://testserver/api/exercises/', json.dumps({"name":"test","description":"test","unit":"kilos"}), content_type='application/json')
-        self.exercise_object = {"exercise":"http://testserver/api/exercises/1/","number":"3","sets":"5"}
         
 
     def test_user_is_on_leaderboard_no_workouts(self):
@@ -682,4 +681,40 @@ class LikesIntegrationTestCase(TestCase):
         self.client2 = APIClient()
         self.client2.force_authenticate(user=self.user_2)
         self.client.post('http://testserver/api/exercises/', json.dumps({"name":"test","description":"test","unit":"kilos"}), content_type='application/json')
-        self.exercise_object = {"exercise":"http://testserver/api/exercises/1/","number":"3","sets":"5"}
\ No newline at end of file
+        self.exercise_object = {"exercise":"http://testserver/api/exercises/1/","number":"3","sets":"5"}
+
+    def test_automatically_liked_own_post(self):
+        workout_request = json.loads('{"name": "bobs workout","date": "2021-03-20T13:29:00.000Z","notes": "jj","visibility":"PU","exercise_instances": [{"exercise":"http://testserver/api/exercises/1/","number":"3","sets":"5"}],"filename": []}')
+        id1 = self.client.post('http://testserver/api/workouts/', json.dumps(workout_request), content_type='application/json').data['id']
+        data = self.client.get('http://testserver/api/workoutLiking/'+str(id1)+'/').data
+        self.assertFalse(data[0])
+        self.assertEquals(data[1],1)
+
+    def test_cannot_like_post_again(self):
+        workout_request = json.loads('{"name": "bobs workout","date": "2021-03-20T13:29:00.000Z","notes": "jj","visibility":"PU","exercise_instances": [{"exercise":"http://testserver/api/exercises/1/","number":"3","sets":"5"}],"filename": []}')
+        id1 = self.client.post('http://testserver/api/workouts/', json.dumps(workout_request), content_type='application/json').data['id']
+        data = self.client.get('http://testserver/api/workoutLiking/'+str(id1)+'/').data
+        self.assertFalse(data[0])
+        self.assertEquals(data[1],1)
+        self.client.post('http://testserver/api/workoutLiking/'+str(id1)+'/')
+        data = self.client.get('http://testserver/api/workoutLiking/'+str(id1)+'/').data
+        self.assertFalse(data[0])
+        self.assertEquals(data[1],1)
+
+    def test_user_can_like_others_post(self):
+        workout_request = json.loads('{"name": "bobs workout","date": "2021-03-20T13:29:00.000Z","notes": "jj","visibility":"PU","exercise_instances": [{"exercise":"http://testserver/api/exercises/1/","number":"3","sets":"5"}],"filename": []}')
+        id1 = self.client.post('http://testserver/api/workouts/', json.dumps(workout_request), content_type='application/json').data['id']
+        data = self.client.get('http://testserver/api/workoutLiking/'+str(id1)+'/').data
+        self.assertFalse(data[0])
+        self.assertEquals(data[1],1)
+        data = self.client2.get('http://testserver/api/workoutLiking/'+str(id1)+'/').data
+        self.assertTrue(data[0])
+        self.assertEquals(data[1],1)
+        self.client2.post('http://testserver/api/workoutLiking/'+str(id1)+'/')
+        data = self.client2.get('http://testserver/api/workoutLiking/'+str(id1)+'/').data
+        self.assertFalse(data[0])
+        self.assertEquals(data[1],2)
+        self.client2.post('http://testserver/api/workoutLiking/'+str(id1)+'/')
+        data = self.client2.get('http://testserver/api/workoutLiking/'+str(id1)+'/').data
+        self.assertFalse(data[0])
+        self.assertEquals(data[1],2)
\ No newline at end of file
-- 
GitLab