From 893a6e42f96d2485b715a2e7ed8a5eb59fc46810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20=C3=98rstad?= <tobiasio@ntnu.no> Date: Mon, 12 Apr 2021 12:24:54 +0200 Subject: [PATCH] Update comment test --- backend/secfit/comments/tests.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/backend/secfit/comments/tests.py b/backend/secfit/comments/tests.py index 35ba93a..367af61 100644 --- a/backend/secfit/comments/tests.py +++ b/backend/secfit/comments/tests.py @@ -12,18 +12,27 @@ class CommentsTestCase(TestCase): self.user_1 = User.objects.get(id="1") self.client = APIClient() self.client.force_authenticate(user=self.user_1) + User.objects.create(id="2",username="Bill2",password="secret", email="hei1") + self.user_2 = User.objects.get(id="2") + self.client2 = APIClient() + self.client2.force_authenticate(user=self.user_2) self.commentURL = "http://testserver/api/comments/" self.workout1URL = "http://testserver/api/workouts/1/" - def testPUComment(self): + def testPostComment(self): Workout.objects.create(id="1",name="workout",date=timezone.now(),owner=self.user_1, visibility="PU") post = self.client.post(self.commentURL,({"workout":self.workout1URL,"content":"asd"}),format='json') self.assertEquals(post.status_code,201) def testGetComments(self): Workout.objects.create(id="1",name="workout",date=timezone.now(),owner=self.user_1, visibility="PU") + Workout.objects.create(id="2",name="workout",date=timezone.now(),owner=self.user_2, visibility="PR") post = self.client.post(self.commentURL,({"workout":self.workout1URL,"content":"asd"}),format='json') self.assertEquals(post.status_code,201) - get = self.client.get("http://testserver/api/comments/") - datadict = dict(get.data) - self.assertEquals(len(datadict["results"]), 1) \ No newline at end of file + self.client2.post(self.commentURL,({"workout":"http://testserver/api/workouts/2/","content":"assdsdd"}),format='json') + user1get = self.client.get("http://testserver/api/comments/") + datadict = dict(user1get.data) + self.assertEquals(len(datadict["results"]), 1) + user2get = self.client2.get("http://testserver/api/comments/") + datadict2 = dict(user2get.data) + self.assertEquals(len(datadict2["results"]), 2) \ No newline at end of file -- GitLab