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

Complete likes integration test

parent b8eb64dc
No related branches found
No related tags found
3 merge requests!18Dev,!15Dev,!14Integrationtests
Pipeline #114111 passed
...@@ -576,7 +576,6 @@ class LeaderboardIntegrationTestCase(TestCase): ...@@ -576,7 +576,6 @@ class LeaderboardIntegrationTestCase(TestCase):
self.client2 = APIClient() self.client2 = APIClient()
self.client2.force_authenticate(user=self.user_2) 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.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): def test_user_is_on_leaderboard_no_workouts(self):
...@@ -683,3 +682,39 @@ class LikesIntegrationTestCase(TestCase): ...@@ -683,3 +682,39 @@ class LikesIntegrationTestCase(TestCase):
self.client2.force_authenticate(user=self.user_2) 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.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"} 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment