Skip to content
Snippets Groups Projects
Commit 893a6e42 authored by Tobias Ørstad's avatar Tobias Ørstad
Browse files

Update comment test

parent e84e2988
No related branches found
No related tags found
2 merge requests!31Complete exercise 3,!24Backendcommentssmells
Pipeline #126966 passed
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment