def testScoreChange_fail6(self): # Trying failed update due to no json sent factory = APIRequestFactory() request = factory.post('/score/submit/', content_type='application/json') view = ScoreView.as_view() response = view(request) assert response.status_code == 400 print("ScoreSubmit Case 7 Successful")
def testScoreChange_fail5(self): # Trying failed update due to empty json factory = APIRequestFactory() score_change = { } request = factory.post('/score/submit/', json.dumps(score_change), content_type='application/json') view = ScoreView.as_view() response = view(request) assert response.status_code == 400 print("ScoreSubmit Case 6 Successful")
def testScoreChange_fail4(self): # Trying failed update due to json without timestamp factory = APIRequestFactory() score_change = { "score_worth":100, "user_id":"05050f82-b8b9-470c-a2d7-31311c18a679" } request = factory.post('/score/submit/', json.dumps(score_change), content_type='application/json') view = ScoreView.as_view() response = view(request) assert response.status_code == 400 print("ScoreSubmit Case 5 Successful")
def testScoreChange_fail3(self): # Trying failed update due to json without user_id factory = APIRequestFactory() score_change = { "score_worth":100, "timestamp":1231412351 } request = factory.post('/score/submit/', json.dumps(score_change), content_type='application/json') view = ScoreView.as_view() response = view(request) assert response.status_code == 400 print("ScoreSubmit Case 4 Successful")
def testScoreChange_fail1(self): # Trying failed update due to non-existing user_id factory = APIRequestFactory() score_change = { "score_worth":100, "user_id":"ffffffff-ffff-ffff-ffff-ffffffffffff", "timestamp":1231412351 } request = factory.post('/score/submit/', json.dumps(score_change), content_type='application/json') view = ScoreView.as_view() response = view(request) assert response.status_code == 400 assert response.data == {"error":"User with given user_id does not exists."} print("ScoreSubmit Case 2 Successful")
def testScoreChange(self): # Trying successful update factory = APIRequestFactory() score_change = { "score_worth":4000, "user_id":"9c767715-3b9a-42c1-9510-976ae599e64b", "timestamp":1231412351 } request = factory.post('/score/submit/', json.dumps(score_change), content_type='application/json') view = ScoreView.as_view() response = view(request) assert response.status_code == 200 assert response.data == {"result":"1"} user1 = { "display_name":"Mahir", "rank":1, "points":4995, "user_id":"9c767715-3b9a-42c1-9510-976ae599e64b" } request = factory.get(f'/user/profile/{user1["user_id"]}') view = UserListNewView.as_view() response = view(request, user1['user_id']) assert response.status_code == 200 assert response.data == user1 user2 = { "display_name":"Karl", "rank":2, "points":1950, "user_id":"05050f82-b8b9-470c-a2d7-31311c18a679" } request = factory.get(f'/user/profile/{user2["user_id"]}') view = UserListNewView.as_view() response = view(request, user2['user_id']) assert response.status_code == 200 assert response.data == user2 print("ScoreSubmit Case 1 Successful")