def testTeamRankWithSubmissionDate(self): """Tests that the team_rank method accurately computes the rank when users have the same number of points,""" user = User(username="******", password="******") user.save() group = Group(name="Test group") group.save() team = Team(name="A", group=group) team.save() profile = user.get_profile() profile.team = team top_user = player_mgr.points_leader() profile.add_points( top_user.points() + 1, datetime.datetime.today() - datetime.timedelta(minutes=1), "Test") profile.save() self.assertEqual(profile.team_rank(), 1, "Check that the user is number 1.") user2 = User(username="******", password="******") user2.save() profile2 = user2.get_profile() profile2.add_points(profile.points(), datetime.datetime.today(), "Test") profile2.save() profile2.team = team profile2.save() self.assertEqual(profile.team_rank(), 2, "Check that the user is now rank 2.")
def testTeamRankForCurrentRound(self): """Test that we can retrieve the rank for the user in the current round.""" test_utils.set_competition_round() group = Group(name="Test group") group.save() team = Team(name="A", group=group) team.save() user = User(username="******", password="******") user.save() profile = user.get_profile() top_user = Profile.objects.all()[0] profile.add_points(top_user.points() + 1, datetime.datetime.today(), "Test") profile.team = team profile.save() self.assertEqual(profile.current_round_team_rank(), 1, "Check that the user is number 1.") user2 = User(username="******", password="******") user2.save() profile2 = user2.get_profile() profile2.add_points(profile.points() + 1, datetime.datetime.today(), "Test") profile2.team = team profile2.save() self.assertEqual(profile.current_round_team_rank(), 2, "Check that the user is now number 2.")
def testTeamRankWithSubmissionDate(self): """Tests that the team_rank method accurately computes the rank when users have the same number of points,""" user = User(username="******", password="******") user.save() group = Group(name="Test group") group.save() team = Team(name="A", group=group) team.save() profile = user.profile profile.team = team top_user = player_mgr.points_leader() profile.add_points(top_user.points() + 1, datetime.datetime.today() - datetime.timedelta(minutes=1), "Test") profile.save() self.assertEqual(profile.team_rank(), 1, "Check that the user is number 1.") user2 = User(username="******", password="******") user2.save() profile2 = user2.profile profile2.add_points(profile.points(), datetime.datetime.today(), "Test") profile2.save() profile2.team = team profile2.save() self.assertEqual(profile.team_rank(), 2, "Check that the user is now rank 2.")
def testRoundRankWithoutEntry(self): """Tests that the overall rank calculation is correct even if a user has not done anything yet.""" group = Group(name="Test group") group.save() team = Team(name="A", group=group) team.save() # Rank will be the number of users who have points plus one. overall_rank = 1 team_rank = 1 self.assertEqual( score_mgr.player_rank(self.user.get_profile(), self.current_round), overall_rank, "Check user is last overall for the current round.") self.assertEqual( score_mgr.player_rank_in_team(self.user.get_profile(), self.current_round), team_rank, "Check user is last in their team for the current " "round.") user2 = User(username="******", password="******") user2.save() profile2 = user2.get_profile() profile2.add_points(10, datetime.datetime.today(), "test") self.assertEqual( score_mgr.player_rank(self.user.get_profile(), self.current_round), overall_rank + 1, "Check that the user's overall rank has moved down.") self.assertEqual( score_mgr.player_rank_in_team(self.user.get_profile(), self.current_round), team_rank + 1, "Check that the user's team rank has moved down.")
def testTeamRankForCurrentRound(self): """Test that we can retrieve the rank for the user in the current round.""" test_utils.set_competition_round() group = Group(name="Test group") group.save() team = Team(name="A", group=group) team.save() user = User(username="******", password="******") user.save() profile = user.profile top_user = Profile.objects.all()[0] profile.add_points(top_user.points() + 1, datetime.datetime.today(), "Test") profile.team = team profile.save() self.assertEqual(profile.current_round_team_rank(), 1, "Check that the user is number 1.") user2 = User(username="******", password="******") user2.save() profile2 = user2.profile profile2.add_points(profile.points() + 1, datetime.datetime.today(), "Test") profile2.team = team profile2.save() self.assertEqual(profile.current_round_team_rank(), 2, "Check that the user is now number 2.")
def setUp(self): """ Sets up a test team prize for the rest of the tests. This prize is not saved, as the round field is not yet set. """ self.prize = test_utils.setup_prize(award_to="team_group", competition_type="points") self.current_round = "Round 1" test_utils.set_competition_round() # Create test groups, teams, and users. self.groups = [Group(name="Test Group %d" % i) for i in range(0, 2)] _ = [d.save() for d in self.groups] self.teams = [ Team(name=str(i), group=self.groups[i % 2]) for i in range(0, 4) ] _ = [f.save() for f in self.teams] self.users = [ User.objects.create_user("test%d" % i, "*****@*****.**") for i in range(0, 4) ] # Assign users to teams. for index, user in enumerate(self.users): user.get_profile().team = self.teams[index % 4] user.get_profile().save()
def testUserTeamRoundRankWithPoints(self): """Tests that the team rank calculation for a round is correct based on points.""" # Setup dorm group = Group(name="Test group") group.save() team = Team(name="A", group=group) team.save() profile = self.user.get_profile() profile.team = team profile.save() # Set up entry top_entry = ScoreboardEntry.objects.filter( round_name=self.current_round).order_by("-points")[0] entry, _ = ScoreboardEntry.objects.get_or_create( profile=self.user.get_profile(), round_name=self.current_round, ) entry.points = top_entry.points + 1 entry.last_awarded_submission = datetime.datetime.today() entry.save() self.assertEqual( score_mgr.player_rank_in_team(self.user.get_profile(), self.current_round), 1, "Check user is ranked #1 for the current round.") user2 = User(username="******", password="******") user2.save() profile2 = user2.get_profile() profile2.team = team profile2.save() entry2, _ = ScoreboardEntry.objects.get_or_create( profile=profile2, round_name=self.current_round, ) entry2.points = entry.points + 1 entry2.last_awarded_submission = entry.last_awarded_submission entry2.save() self.assertEqual( score_mgr.player_rank_in_team(self.user.get_profile(), self.current_round), 2, "Check user is now second.")
def testUserTeamRoundRankWithPoints(self): """Tests that the team rank calculation for a round is correct based on points.""" # Setup dorm group = Group(name="Test group") group.save() team = Team(name="A", group=group) team.save() profile = self.user.profile profile.team = team profile.save() # Set up entry top_entry = ScoreboardEntry.objects.filter( round_name=self.current_round).order_by("-points")[0] entry, _ = ScoreboardEntry.objects.get_or_create( profile=self.user.profile, round_name=self.current_round, ) entry.points = top_entry.points + 1 entry.last_awarded_submission = datetime.datetime.today() entry.save() self.assertEqual(score_mgr.player_rank_in_team(self.user.profile, self.current_round), 1, "Check user is ranked #1 for the current round.") user2 = User(username="******", password="******") user2.save() profile2 = user2.profile profile2.team = team profile2.save() entry2, _ = ScoreboardEntry.objects.get_or_create( profile=profile2, round_name=self.current_round, ) entry2.points = entry.points + 1 entry2.last_awarded_submission = entry.last_awarded_submission entry2.save() self.assertEqual(score_mgr.player_rank_in_team(self.user.profile, self.current_round), 2, "Check user is now second.")
def testTeamRankWithPoints(self): """Tests that the team_rank method accurately computes the rank based on points.""" user = User(username="******", password="******") user.save() group = Group(name="Test group") group.save() team = Team(name="A", group=group) team.save() profile = user.get_profile() profile.team = team # Check that the user is ranked last if they haven't done anything. rank = 1 self.assertEqual(profile.team_rank(), rank, "Check that the user is ranked last.") # Make the user number 1 overall. top_user = Profile.objects.all()[0] profile.add_points(top_user.points() + 1, datetime.datetime.today(), "Test") profile.save() self.assertEqual(profile.team_rank(), 1, "Check that the user is number 1.") user2 = User(username="******", password="******") user2.save() profile2 = user2.get_profile() profile2.add_points(profile.points() + 1, datetime.datetime.today(), "Test") profile2.save() self.assertEqual( profile.team_rank(), 1, "Check that the user is still number 1 if the new " "profile is not on the same team.") profile2.team = team profile2.save() self.assertEqual(profile.team_rank(), 2, "Check that the user is now rank 2.")
def testTeamRankWithPoints(self): """Tests that the team_rank method accurately computes the rank based on points.""" user = User(username="******", password="******") user.save() group = Group(name="Test group") group.save() team = Team(name="A", group=group) team.save() profile = user.profile profile.team = team # Check that the user is ranked last if they haven't done anything. rank = 1 self.assertEqual(profile.team_rank(), rank, "Check that the user is ranked last.") # Make the user number 1 overall. top_user = Profile.objects.all()[0] profile.add_points(top_user.points() + 1, datetime.datetime.today(), "Test") profile.save() self.assertEqual(profile.team_rank(), 1, "Check that the user is number 1.") user2 = User(username="******", password="******") user2.save() profile2 = user2.profile profile2.add_points(profile.points() + 1, datetime.datetime.today(), "Test") profile2.save() self.assertEqual(profile.team_rank(), 1, "Check that the user is still number 1 if the new " "profile is not on the same team.") profile2.team = team profile2.save() self.assertEqual(profile.team_rank(), 2, "Check that the user is now rank 2.")
def setUp(self): self.group = Group(name="Test Group") self.group.save() self.teams = [Team(name=str(i), group=self.group) for i in range(0, 2)] _ = [f.save() for f in self.teams] self.users = [ User.objects.create_user("test%d" % i, "*****@*****.**") for i in range(0, 4) ] # Assign users to teams. for index, user in enumerate(self.users): user.get_profile().team = self.teams[index % 2] user.get_profile().save() self.current_round = "Round 1" test_utils.set_competition_round()
def create_teams(testcase): """Create test groups, teams, and users.""" testcase.groups = [Group(name="Test Group %d" % i) for i in range(0, 2)] _ = [d.save() for d in testcase.groups] testcase.group = Group(name="Test Group") testcase.group.save() testcase.teams = [ Team(name=str(i), group=testcase.group) for i in range(0, 2) ] _ = [f.save() for f in testcase.teams] testcase.users = [ User.objects.create_user("test%d" % i, "*****@*****.**") for i in range(0, 4) ] # Assign users to teams. for index, user in enumerate(testcase.users): user.get_profile().team = testcase.teams[index % 2] user.get_profile().save()
def testRoundRankWithoutEntry(self): """Tests that the overall rank calculation is correct even if a user has not done anything yet.""" group = Group(name="Test group") group.save() team = Team(name="A", group=group) team.save() # Rank will be the number of users who have points plus one. overall_rank = 1 team_rank = 1 self.assertEqual(score_mgr.player_rank(self.user.profile, self.current_round), overall_rank, "Check user is last overall for the current round.") self.assertEqual(score_mgr.player_rank_in_team(self.user.profile, self.current_round), team_rank, "Check user is last in their team for the current " "round.") user2 = User(username="******", password="******") user2.save() profile2 = user2.profile profile2.add_points(10, datetime.datetime.today(), "test") self.assertEqual(score_mgr.player_rank(self.user.profile, self.current_round), overall_rank + 1, "Check that the user's overall rank has moved down.") self.assertEqual(score_mgr.player_rank_in_team(self.user.profile, self.current_round), team_rank + 1, "Check that the user's team rank has moved down.")
def setUp(self): self.group = Group(name="Test Group") self.group.save() self.teams = [Team(name=str(i), group=self.group) for i in range(0, 2)] _ = [f.save() for f in self.teams] self.users = [User.objects.create_user("test%d" % i, "*****@*****.**") for i in range(0, 4)] # Assign users to teams. for index, user in enumerate(self.users): user.profile.team = self.teams[index % 2] user.profile.save() self.current_round = "Round 1" test_utils.set_competition_round()
class TeamLeadersTestCase(TransactionTestCase): """test team leader""" def setUp(self): self.group = Group(name="Test Group") self.group.save() self.teams = [Team(name=str(i), group=self.group) for i in range(0, 2)] _ = [f.save() for f in self.teams] self.users = [ User.objects.create_user("test%d" % i, "*****@*****.**") for i in range(0, 4) ] # Assign users to teams. for index, user in enumerate(self.users): user.get_profile().team = self.teams[index % 2] user.get_profile().save() self.current_round = "Round 1" test_utils.set_competition_round() def testTeamPointsInRound(self): """Tests calculating the team points leaders in a round.""" profile = self.users[0].get_profile() profile.add_points( 10, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile.save() self.assertEqual( team_mgr.team_points_leader(round_name=self.current_round), profile.team, "The user's team is not leading in the prize.") # Test that a user in a different team but same dorm changes the # leader for the original user. profile2 = self.users[2].get_profile() profile2.add_points( profile.points() + 1, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile2.save() self.assertEqual( team_mgr.team_points_leader(round_name=self.current_round), profile2.team, "The user's team should have changed.") # Test that a tie is handled properly. profile.add_points(1, datetime.datetime.today(), "test") profile.save() self.assertEqual( team_mgr.team_points_leader(round_name=self.current_round), profile.team, "The leader of the team should have changed back.") def testIndividualPointsInRound(self): """Tests calculating the individual points leaders in a round.""" profile = self.users[0].get_profile() profile.add_points( 10, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile.save() self.assertEqual( profile.team.points_leaders(round_name=self.current_round)[0], profile, "The user should be in the lead in his own team.") # Test that a user in a different team but same dorm does not change # the leader for the original team. profile1 = self.users[1].get_profile() profile1.add_points( 15, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile1.save() self.assertEqual( profile.team.points_leaders(round_name=self.current_round)[0], profile, "The leader for the user's team should not have" " changed.") self.assertEqual( profile1.team.points_leaders(round_name=self.current_round)[0], profile1, "User 1 should be leading in their own team.") # Test another user going ahead in the user's team. profile2 = self.users[2].get_profile() profile2.add_points( 15, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile2.save() self.assertEqual( profile.team.points_leaders(round_name=self.current_round)[0], profile2, "User 2 should be in the lead in the user's team.") # Test that a tie is handled properly. profile.add_points(5, datetime.datetime.today(), "test") profile.save() self.assertEqual( profile.team.points_leaders(round_name=self.current_round)[0], profile, "The leader of the team should have changed back.") def testTeamPointsOverall(self): """Tests calculating the team points leaders in a round.""" profile = self.users[0].get_profile() profile.add_points( 10, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile.save() self.assertEqual(profile.team.points_leaders()[0], profile, "The user should be in the lead in his own team.") # Test that a user in a different team but same dorm does not change # the leader for the original team. profile1 = self.users[1].get_profile() profile1.add_points( 15, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile1.save() self.assertEqual( profile.team.points_leaders()[0], profile, "The leader for the user's team should not have " "changed.") self.assertEqual(profile1.team.points_leaders()[0], profile1, "User 1 should be leading in their own team.") # Test another user going ahead in the user's team. profile2 = self.users[2].get_profile() profile2.add_points( 15, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile2.save() self.assertEqual(profile.team.points_leaders()[0], profile2, "User 2 should be in the lead in the user's team.") # Test that a tie is handled properly. profile.add_points(5, datetime.datetime.today(), "test") profile.save() self.assertEqual(profile.team.points_leaders()[0], profile, "The leader of the team should have changed back.")
class TeamsUnitTestCase(TransactionTestCase): """team tests""" def setUp(self): self.group = Group(name="Test group") self.group.save() self.test_team = Team(name="A", group=self.group) self.test_team.save() def testOverallPoints(self): """Check that retrieving the points for the team is correct.""" # Create a test user. user = User(username="******", password="******") user.save() user_points = 10 user.get_profile().team = self.test_team self.assertEqual(self.test_team.points(), 0, "Check that the team does not have any points yet.") user.get_profile().add_points(user_points, datetime.datetime.today(), "test") user.get_profile().save() self.assertEqual( self.test_team.points(), user_points, "Check that the number of points are equal for " "one user.") # Create another test user and check again. user = User(username="******", password="******") user.save() user.get_profile().team = self.test_team user.get_profile().add_points(user_points, datetime.datetime.today(), "test") user.get_profile().save() self.assertEqual( self.test_team.points(), 2 * user_points, "Check that the number of points are equal for two users.") def testPointsInRound(self): """Tests that we can accurately compute the amount of points in a round.""" test_utils.set_competition_round() user = User(username="******", password="******") user.save() profile = user.get_profile() profile.team = self.test_team profile.save() self.assertEqual(self.test_team.current_round_points(), 0, "Check that the team does not have any points yet.") profile.add_points(10, datetime.datetime.today(), "test") profile.save() self.assertEqual( self.test_team.current_round_points(), 10, "Check that the number of points are correct in " "this round.") def testOverallRankWithPoints(self): """Check that calculating the rank is correct based on point value.""" # Create a test user. user = User(username="******", password="******") user.save() user_points = 10 user.get_profile().team = self.test_team # Test the team is ranked last if they haven't done anything yet. team_rank = 1 self.assertEqual(self.test_team.rank(), team_rank, "Check the team is ranked last.") user.get_profile().add_points(user_points, datetime.datetime.today(), "test") user.get_profile().save() self.assertEqual(self.test_team.rank(), 1, "Check the team is now ranked number 1.") # Create a test user on a different team. test_team2 = Team(name="B", group=self.group) test_team2.save() user2 = User(username="******", password="******") user2.save() user2.get_profile().team = test_team2 user2.get_profile().add_points(user_points + 1, datetime.datetime.today(), "test") user2.get_profile().save() self.assertEqual(self.test_team.rank(), 2, "Check that the team is now ranked number 2.") def testRoundRank(self): """Check that the rank calculation is correct for the current round.""" # Save the round information and set up a test round. test_utils.set_competition_round() # Create a test user. user = User(username="******", password="******") user.save() user_points = 10 user.get_profile().team = self.test_team user.get_profile().save() self.assertEqual( self.test_team.current_round_rank(), 1, "Check the calculation works even if there's " "no submission.") user.get_profile().add_points(user_points, datetime.datetime.today(), "test") user.get_profile().save() self.assertEqual(self.test_team.current_round_rank(), 1, "Check the team is now ranked number 1.") test_team2 = Team(name="B", group=self.group) test_team2.save() user2 = User(username="******", password="******") user2.save() user2.get_profile().team = test_team2 user2.get_profile().add_points(user_points + 1, datetime.datetime.today(), "test") user2.get_profile().save() self.assertEqual(self.test_team.current_round_rank(), 2, "Check the team is now ranked number 2.") def testOverallRankWithSubmissionDate(self): """Check that rank calculation is correct in the case of ties.""" # Create a test user. user = User(username="******", password="******") user.save() user_points = 10 user.get_profile().team = self.test_team user.get_profile().add_points(user_points, datetime.datetime.today(), "test") user.get_profile().save() # Create a test user on a different team. test_team2 = Team(name="B", group=self.group) test_team2.save() user = User(username="******", password="******") user.save() user.get_profile().team = test_team2 user.get_profile().add_points( user_points, datetime.datetime.today() + datetime.timedelta(days=1), "test") user.get_profile().save() self.assertEqual(self.test_team.rank(), 2, "Check that the team is ranked second.")
def setUp(self): self.group = Group(name="Test group") self.group.save() self.test_team = Team(name="A", group=self.group) self.test_team.save()
class TeamLeadersTestCase(TransactionTestCase): """test team leader""" def setUp(self): self.group = Group(name="Test Group") self.group.save() self.teams = [Team(name=str(i), group=self.group) for i in range(0, 2)] _ = [f.save() for f in self.teams] self.users = [User.objects.create_user("test%d" % i, "*****@*****.**") for i in range(0, 4)] # Assign users to teams. for index, user in enumerate(self.users): user.profile.team = self.teams[index % 2] user.profile.save() self.current_round = "Round 1" test_utils.set_competition_round() def testTeamPointsInRound(self): """Tests calculating the team points leaders in a round.""" profile = self.users[0].profile profile.add_points(10, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile.save() self.assertEqual(team_mgr.team_points_leader(round_name=self.current_round), profile.team, "The user's team is not leading in the prize.") # Test that a user in a different team but same dorm changes the # leader for the original user. profile2 = self.users[2].profile profile2.add_points(profile.points() + 1, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile2.save() self.assertEqual(team_mgr.team_points_leader(round_name=self.current_round), profile2.team, "The user's team should have changed.") # Test that a tie is handled properly. profile.add_points(1, datetime.datetime.today(), "test") profile.save() self.assertEqual(team_mgr.team_points_leader(round_name=self.current_round), profile.team, "The leader of the team should have changed back.") def testIndividualPointsInRound(self): """Tests calculating the individual points leaders in a round.""" profile = self.users[0].profile profile.add_points(10, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile.save() self.assertEqual(profile.team.points_leaders(round_name=self.current_round)[0], profile, "The user should be in the lead in his own team.") # Test that a user in a different team but same dorm does not change # the leader for the original team. profile1 = self.users[1].profile profile1.add_points(15, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile1.save() self.assertEqual(profile.team.points_leaders(round_name=self.current_round)[0], profile, "The leader for the user's team should not have" " changed.") self.assertEqual(profile1.team.points_leaders(round_name=self.current_round)[0], profile1, "User 1 should be leading in their own team.") # Test another user going ahead in the user's team. profile2 = self.users[2].profile profile2.add_points(15, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile2.save() self.assertEqual(profile.team.points_leaders(round_name=self.current_round)[0], profile2, "User 2 should be in the lead in the user's team.") # Test that a tie is handled properly. profile.add_points(5, datetime.datetime.today(), "test") profile.save() self.assertEqual(profile.team.points_leaders(round_name=self.current_round)[0], profile, "The leader of the team should have changed back.") def testTeamPointsOverall(self): """Tests calculating the team points leaders in a round.""" profile = self.users[0].profile profile.add_points(10, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile.save() self.assertEqual(profile.team.points_leaders()[0], profile, "The user should be in the lead in his own team.") # Test that a user in a different team but same dorm does not change # the leader for the original team. profile1 = self.users[1].profile profile1.add_points(15, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile1.save() self.assertEqual(profile.team.points_leaders()[0], profile, "The leader for the user's team should not have " "changed.") self.assertEqual(profile1.team.points_leaders()[0], profile1, "User 1 should be leading in their own team.") # Test another user going ahead in the user's team. profile2 = self.users[2].profile profile2.add_points(15, datetime.datetime.today() - datetime.timedelta(minutes=1), "test") profile2.save() self.assertEqual(profile.team.points_leaders()[0], profile2, "User 2 should be in the lead in the user's team.") # Test that a tie is handled properly. profile.add_points(5, datetime.datetime.today(), "test") profile.save() self.assertEqual(profile.team.points_leaders()[0], profile, "The leader of the team should have changed back.")
class TeamsUnitTestCase(TransactionTestCase): """team tests""" def setUp(self): self.group = Group(name="Test group") self.group.save() self.test_team = Team(name="A", group=self.group) self.test_team.save() def testOverallPoints(self): """Check that retrieving the points for the team is correct.""" # Create a test user. user = User(username="******", password="******") user.save() user_points = 10 user.profile.team = self.test_team self.assertEqual(self.test_team.points(), 0, "Check that the team does not have any points yet.") user.profile.add_points(user_points, datetime.datetime.today(), "test") user.profile.save() self.assertEqual(self.test_team.points(), user_points, "Check that the number of points are equal for " "one user.") # Create another test user and check again. user = User(username="******", password="******") user.save() user.profile.team = self.test_team user.profile.add_points(user_points, datetime.datetime.today(), "test") user.profile.save() self.assertEqual(self.test_team.points(), 2 * user_points, "Check that the number of points are equal for two users.") def testPointsInRound(self): """Tests that we can accurately compute the amount of points in a round.""" test_utils.set_competition_round() user = User(username="******", password="******") user.save() profile = user.profile profile.team = self.test_team profile.save() self.assertEqual(self.test_team.current_round_points(), 0, "Check that the team does not have any points yet.") profile.add_points(10, datetime.datetime.today(), "test") profile.save() self.assertEqual(self.test_team.current_round_points(), 10, "Check that the number of points are correct in " "this round.") def testOverallRankWithPoints(self): """Check that calculating the rank is correct based on point value.""" # Create a test user. user = User(username="******", password="******") user.save() user_points = 10 user.profile.team = self.test_team # Test the team is ranked last if they haven't done anything yet. team_rank = 1 self.assertEqual(self.test_team.rank(), team_rank, "Check the team is ranked last.") user.profile.add_points(user_points, datetime.datetime.today(), "test") user.profile.save() self.assertEqual(self.test_team.rank(), 1, "Check the team is now ranked number 1.") # Create a test user on a different team. test_team2 = Team(name="B", group=self.group) test_team2.save() user2 = User(username="******", password="******") user2.save() user2.profile.team = test_team2 user2.profile.add_points(user_points + 1, datetime.datetime.today(), "test") user2.profile.save() self.assertEqual(self.test_team.rank(), 2, "Check that the team is now ranked number 2.") def testRoundRank(self): """Check that the rank calculation is correct for the current round.""" # Save the round information and set up a test round. test_utils.set_competition_round() # Create a test user. user = User(username="******", password="******") user.save() user_points = 10 user.profile.team = self.test_team user.profile.save() self.assertEqual(self.test_team.current_round_rank(), 1, "Check the calculation works even if there's " "no submission.") user.profile.add_points(user_points, datetime.datetime.today(), "test") user.profile.save() self.assertEqual(self.test_team.current_round_rank(), 1, "Check the team is now ranked number 1.") test_team2 = Team(name="B", group=self.group) test_team2.save() user2 = User(username="******", password="******") user2.save() user2.profile.team = test_team2 user2.profile.add_points(user_points + 1, datetime.datetime.today(), "test") user2.profile.save() self.assertEqual(self.test_team.current_round_rank(), 2, "Check the team is now ranked number 2.") def testOverallRankWithSubmissionDate(self): """Check that rank calculation is correct in the case of ties.""" # Create a test user. user = User(username="******", password="******") user.save() user_points = 10 user.profile.team = self.test_team user.profile.add_points(user_points, datetime.datetime.today(), "test") user.profile.save() # Create a test user on a different team. test_team2 = Team(name="B", group=self.group) test_team2.save() user = User(username="******", password="******") user.save() user.profile.team = test_team2 user.profile.add_points(user_points, datetime.datetime.today() + datetime.timedelta(days=1), "test") user.profile.save() self.assertEqual(self.test_team.rank(), 2, "Check that the team is ranked second.")