def make_puzzles_complete_request(self, puzzles): """ Make a puzzles complete request, given an array of puzzles. E.g. [ {"PuzzleID": 13, "Set": 1, "SubSet": 2}, {"PuzzleID": 53524, "Set": 1, "SubSet": 1} ] """ puzzles_str = json.dumps(puzzles) verify = { "Verify": verify_code(self.user.email, puzzles_str), "VerifyMethod": "FoldItVerify" } data = { 'SetPuzzlesCompleteVerify': json.dumps(verify), 'SetPuzzlesComplete': puzzles_str } request = self.make_request(data) response = foldit_ops(request) self.assertEqual(response.status_code, 200) return response
def make_puzzle_score_request(self, puzzle_ids, best_scores, user=None): """ Given lists of puzzle_ids and best_scores (must have same length), make a SetPlayerPuzzleScores request and return the response. """ if not(type(best_scores) == list): best_scores = [best_scores] if not(type(puzzle_ids) == list): puzzle_ids = [puzzle_ids] user = self.user if not user else user def score_dict(puzzle_id, best_score): return {"PuzzleID": puzzle_id, "ScoreType": "score", "BestScore": best_score, # current scores don't actually matter "CurrentScore": best_score + 0.01, "ScoreVersion": 23} scores = [score_dict(pid, bs) for pid, bs in zip(puzzle_ids, best_scores)] scores_str = json.dumps(scores) verify = {"Verify": verify_code(user.email, scores_str), "VerifyMethod": "FoldItVerify"} data = {'SetPlayerPuzzleScoresVerify': json.dumps(verify), 'SetPlayerPuzzleScores': scores_str} request = self.make_request(data, user) response = foldit_ops(request) self.assertEqual(response.status_code, 200) return response
def test_SetPlayerPuzzleScores_error(self): scores = [{"PuzzleID": 994391, "ScoreType": "score", "BestScore": 0.078034, "CurrentScore": 0.080035, "ScoreVersion": 23}] validation_str = json.dumps(scores) verify = {"Verify": verify_code(self.user.email, validation_str), "VerifyMethod": "FoldItVerify"} # change the real string -- should get an error scores[0]['ScoreVersion'] = 22 scores_str = json.dumps(scores) data = {'SetPlayerPuzzleScoresVerify': json.dumps(verify), 'SetPlayerPuzzleScores': scores_str} request = self.make_request(data) response = foldit_ops(request) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content) self.assertEqual(response.content, json.dumps([{ "OperationID": "SetPlayerPuzzleScores", "Success": "false", "ErrorString": "Verification failed", "ErrorCode": "VerifyFailed"}]))
def test_SetPlayerPuzzlesComplete_error(self): puzzles = [ {"PuzzleID": 13, "Set": 1, "SubSet": 2}, {"PuzzleID": 53524, "Set": 1, "SubSet": 1} ] puzzles_str = json.dumps(puzzles) verify = {"Verify": verify_code(self.user.email, puzzles_str + "x"), "VerifyMethod":"FoldItVerify"} data = {'SetPuzzlesCompleteVerify': json.dumps(verify), 'SetPuzzlesComplete': puzzles_str} request = self.make_request(data) response = foldit_ops(request) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content) self.assertEqual(response.content, json.dumps([{ "OperationID": "SetPuzzlesComplete", "Success": "false", "ErrorString": "Verification failed", "ErrorCode": "VerifyFailed"}]))