Exemple #1
0
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.")
Exemple #2
0
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.")