def testUpdateUserSubmissionChangesStandings(self): """Test that updating the submission date in a round changes the standings.""" entry = self.entries[1] # Use second place entry. json_standings = get_standings_for_user(entry.profile.user, group="floor", round_name=self.current_round) decoded_standings = json.loads(json_standings) user_index = decoded_standings["myindex"] self.assertEqual(user_index, 1) entry.last_awarded_submission = datetime.datetime.today() entry.save() json_standings = get_standings_for_user(entry.profile.user, group="floor", round_name=self.current_round) decoded_standings = json.loads(json_standings) user_index = decoded_standings["myindex"] self.assertEqual(user_index, 0)
def get_mobile_standings(user): """ Gets a mobile version of the standings. In the mobile version, we are only using information for the current round. """ current_round = get_current_round() # Retrieve standings. Note that the get_standings_for_user method returns a JSON string. if current_round: floor_standings = json.loads(get_standings_for_user(user, "floor", current_round)) overall_standings = json.loads(get_standings_for_user(user, "all", current_round)) else: # Retrieve the overall standings. floor_standings = json.loads(get_standings_for_user(user, "floor", None)) overall_standings = json.loads(get_standings_for_user(user, "all", None)) # Generate strings for use in the mobile website. info = floor_standings["info"] index = floor_standings["myindex"] rank = info[index]["rank"] if current_round: floor_string = "You are #%d in points for %s for %s." % (rank, user.get_profile().floor, current_round) else: floor_string = "You are #%d in points for %s in the competition." % (rank, user.get_profile().floor) if index > 0: diff = info[index - 1]["points"] - info[index]["points"] if diff < 2: floor_string += " Get 1 more point to move to #%d." % (rank - 1,) else: floor_string += " Get %d more points to move to #%d." % (diff, rank - 1) info = overall_standings["info"] index = overall_standings["myindex"] rank = info[index]["rank"] if current_round: overall_string = "You are #%d in overall points for %s." % (rank, current_round) else: overall_string = "You are #%d in overall points in the competition." % rank if index > 0: diff = info[index - 1]["points"] - info[index]["points"] if diff < 2: overall_string += " Get 1 more point to move to #%d." % (rank - 1,) else: overall_string += " Get %d more points to move to #%d." % (diff, rank - 1) return {"floor": floor_string, "overall": overall_string}
def testUpdateUserPointsChangesStandings(self): """Test that updating the points in a round changes the standings.""" entry = self.entries[1] # Use second place entry. json_standings = get_standings_for_user(entry.profile.user, group="floor", round_name=self.current_round) decoded_standings = json.loads(json_standings) user_index = decoded_standings["myindex"] self.assertEqual(user_index, 1) point_diff = decoded_standings["info"][0]["points"] - decoded_standings["info"][user_index]["points"] entry.points += point_diff + 1 # Should push user to number 1. entry.save() json_standings = get_standings_for_user(entry.profile.user, group="floor", round_name=self.current_round) decoded_standings = json.loads(json_standings) user_index = decoded_standings["myindex"] self.assertEqual(user_index, 0)
def testUserStandingsSecondToLastPlace(self): """Test that standings of the second to the last user is correct.""" json_standings = get_standings_for_user(self.profiles[self.count - 2], "floor") decoded_standings = json.loads(json_standings) self.assertTrue(decoded_standings["myindex"] == 2) self.assertTrue(len(decoded_standings["info"]) == 4)
def testRoundOverallStandings(self): """Tests the overall standings for all users in a round.""" # Use first entry. entry = self.entries[0] json_standings = get_standings_for_user(entry.profile, group="all", round_name=self.current_round) decoded_standings = json.loads(json_standings) # Verify that the returned structure is correct. self.assertTrue(decoded_standings.has_key("title")) self.assertTrue(decoded_standings.has_key("info")) self.assertTrue(decoded_standings.has_key("myindex")) self.assertTrue(decoded_standings.has_key("type")) self.assertTrue(len(decoded_standings) == 4) # Verify that the contents are correct. self.assertTrue(decoded_standings["myindex"] == 0) self.assertTrue(len(decoded_standings["info"]) == 3) self.assertTrue(decoded_standings["info"][0]["rank"] == 1) self.assertTrue(decoded_standings["info"][2]["rank"] == self.count) first = decoded_standings["info"][0] second = decoded_standings["info"][1] self.assertTrue(first["points"] >= second["points"])
def testUserStandingsSecondPlace(self): """Test that standings of the second place user is correct.""" json_standings = get_standings_for_user(self.profiles[1], "floor") decoded_standings = json.loads(json_standings) self.assertTrue(decoded_standings["myindex"] == 1) self.assertTrue(len(decoded_standings["info"]) == 4) self.assertTrue(decoded_standings["info"][1]["rank"] == 2)
def testUserStandingsLastPlace(self): """Test that standings of the last place user is correct.""" json_standings = get_standings_for_user(self.profiles[self.count - 1], "floor") decoded_standings = json.loads(json_standings) self.assertTrue(decoded_standings["myindex"] == 2) self.assertTrue(len(decoded_standings["info"]) == 3) self.assertTrue(decoded_standings["info"][2]["rank"] == self.count)
def testUserStandingsThirdPlace(self): """Test that standings of the third place user is correct. This will also verify that any user in the middle is correct.""" json_standings = get_standings_for_user(self.profiles[2], "floor") decoded_standings = json.loads(json_standings) self.assertTrue(decoded_standings["myindex"] == 2) self.assertTrue(len(decoded_standings["info"]) == 5) self.assertTrue(decoded_standings["info"][2]["rank"] == 3)
def testUserAddPointsChangeStandings(self): """Test that adding points moves the user up.""" # Test using the second place user. profile = self.profiles[1] json_standings = get_standings_for_user(profile, group="floor") decoded_standings = json.loads(json_standings) user_index = decoded_standings["myindex"] point_diff = decoded_standings["info"][0]["points"] - decoded_standings["info"][user_index]["points"] profile.points += point_diff + 1 profile.save() json_standings = get_standings_for_user(profile, group="floor") decoded_standings = json.loads(json_standings) # Verify that user is now first. self.assertTrue(decoded_standings["myindex"] == 0) self.assertTrue(len(decoded_standings["info"]) == 3)
def testUserChangeSubmitDateChangeStandings(self): """Test that tied users with different submission dates are ordered correctly.""" # Test using the second place user. profile = self.profiles[1] json_standings = get_standings_for_user(profile, group="floor") decoded_standings = json.loads(json_standings) point_diff = decoded_standings["info"][0]["points"] - decoded_standings["info"][1]["points"] profile.points += point_diff # Tie for points profile.last_awarded_submission = datetime.datetime.today() profile.save() json_standings = get_standings_for_user(profile, group="floor") decoded_standings = json.loads(json_standings) # Verify that user is now first. self.assertTrue(decoded_standings["myindex"] == 0) self.assertTrue(len(decoded_standings["info"]) == 3)
def testUserAddPointsChangeStandings(self): """Test that adding points moves the user up.""" # Test using the second place user. profile = self.profiles[1] json_standings = get_standings_for_user(profile, group="floor") decoded_standings = json.loads(json_standings) user_index = decoded_standings["myindex"] point_diff = decoded_standings["info"][0][ "points"] - decoded_standings["info"][user_index]["points"] profile.points += point_diff + 1 profile.save() json_standings = get_standings_for_user(profile, group="floor") decoded_standings = json.loads(json_standings) # Verify that user is now first. self.assertTrue(decoded_standings["myindex"] == 0) self.assertTrue(len(decoded_standings["info"]) == 3)
def testUserChangeSubmitDateChangeStandings(self): """Test that tied users with different submission dates are ordered correctly.""" # Test using the second place user. profile = self.profiles[1] json_standings = get_standings_for_user(profile, group="floor") decoded_standings = json.loads(json_standings) point_diff = decoded_standings["info"][0][ "points"] - decoded_standings["info"][1]["points"] profile.points += point_diff # Tie for points profile.last_awarded_submission = datetime.datetime.today() profile.save() json_standings = get_standings_for_user(profile, group="floor") decoded_standings = json.loads(json_standings) # Verify that user is now first. self.assertTrue(decoded_standings["myindex"] == 0) self.assertTrue(len(decoded_standings["info"]) == 3)
def testUpdateUserPointsChangesStandings(self): """Test that updating the points in a round changes the standings.""" entry = self.entries[1] # Use second place entry. json_standings = get_standings_for_user(entry.profile.user, group="floor", round_name=self.current_round) decoded_standings = json.loads(json_standings) user_index = decoded_standings["myindex"] self.assertEqual(user_index, 1) point_diff = decoded_standings["info"][0][ "points"] - decoded_standings["info"][user_index]["points"] entry.points += point_diff + 1 #Should push user to number 1. entry.save() json_standings = get_standings_for_user(entry.profile.user, group="floor", round_name=self.current_round) decoded_standings = json.loads(json_standings) user_index = decoded_standings["myindex"] self.assertEqual(user_index, 0)
def testStandingsAllUsers(self): """Tests the overall standings for all users.""" profile = self.profiles[0] json_standings = get_standings_for_user(profile, group="all") decoded_standings = json.loads(json_standings) # Verify that the returned structure is correct. self.assertTrue(decoded_standings.has_key("title")) self.assertTrue(decoded_standings.has_key("info")) self.assertTrue(decoded_standings.has_key("myindex")) self.assertTrue(decoded_standings.has_key("type")) self.assertTrue(len(decoded_standings) == 4) # Verify that the contents are correct. self.assertTrue(decoded_standings["myindex"] == 0) self.assertTrue(len(decoded_standings["info"]) == 3) self.assertTrue(decoded_standings["info"][0]["rank"] == 1) self.assertTrue(decoded_standings["info"][2]["rank"] == self.count) first = decoded_standings["info"][0] second = decoded_standings["info"][1] self.assertTrue(first["points"] >= second["points"])
def testUserStandingsFirstPlace(self): """Test that the standings of the first place user is correct.""" json_standings = get_standings_for_user(self.profiles[0], "floor") decoded_standings = json.loads(json_standings) # Verify that the returned structure is correct. self.assertTrue(decoded_standings.has_key("title")) self.assertTrue(decoded_standings.has_key("info")) self.assertTrue(decoded_standings.has_key("myindex")) self.assertTrue(decoded_standings.has_key("type")) self.assertTrue(len(decoded_standings) == 4) # Verify that the contents are correct. self.assertTrue(decoded_standings["myindex"] == 0) self.assertTrue(len(decoded_standings["info"]) == 3) self.assertTrue(decoded_standings["info"][0]["rank"] == 1) self.assertTrue(decoded_standings["info"][2]["rank"] == self.count) first = decoded_standings["info"][0] second = decoded_standings["info"][1] self.assertTrue(first["points"] >= second["points"])