Exemplo n.º 1
0
    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()
Exemplo n.º 2
0
    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.")
Exemplo n.º 3
0
    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.")
Exemplo n.º 4
0
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()
Exemplo n.º 5
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.")
Exemplo n.º 6
0
    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.")
Exemplo n.º 7
0
    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()
Exemplo n.º 8
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.")
Exemplo n.º 9
0
 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()