Example #1
0
    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.")
Example #2
0
    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.")
Example #3
0
    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.")
Example #4
0
    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.")
Example #5
0
 def team_rank(self):
     """Returns the rank of the user in their own team."""
     return score_mgr.player_rank_in_team(self)
Example #6
0
 def current_round_team_rank(self):
     """Returns the rank of the user for the current round in their own team."""
     current_round = challenge_mgr.get_round_name()
     return score_mgr.player_rank_in_team(self, round_name=current_round)
Example #7
0
 def team_rank(self):
     """Returns the rank of the user in their own team."""
     return score_mgr.player_rank_in_team(self)
Example #8
0
 def current_round_team_rank(self):
     """Returns the rank of the user for the current round in their own team."""
     current_round = challenge_mgr.get_round_name()
     return score_mgr.player_rank_in_team(self, round_name=current_round)