예제 #1
0
파일: tests.py 프로젝트: ilwoof/makahiki
    def setUp(self):
        self.dorm = Dorm(name="Test Dorm")
        self.dorm.save()

        self.floors = [
            Floor(number=str(i), dorm=self.dorm) for i in range(0, 2)
        ]
        map(lambda f: f.save(), self.floors)

        self.users = [
            User.objects.create_user("test%d" % i, "*****@*****.**")
            for i in range(0, 4)
        ]

        # Assign users to floors.
        for index, user in enumerate(self.users):
            user.get_profile().floor = self.floors[index % 2]
            user.get_profile().save()

        self.saved_rounds = settings.COMPETITION_ROUNDS
        self.current_round = "Round 1"
        start = datetime.date.today()
        end = start + datetime.timedelta(days=7)

        settings.COMPETITION_ROUNDS = {
            "Round 1": {
                "start": start.strftime("%Y-%m-%d"),
                "end": end.strftime("%Y-%m-%d"),
            },
        }
예제 #2
0
  def testRoundRankWithoutEntry(self):
    """Tests that the overall rank calculation is correct even if a user has not done anything yet."""
    dorm = Dorm(name="Test dorm")
    dorm.save()
    floor = Floor(number="A", dorm=dorm)
    floor.save()
    
    profile = self.user.get_profile()
    # Rank will be the number of users who have points plus one.
    overall_rank = Profile.objects.filter(points__gt=0).count() + 1
    floor_rank = Profile.objects.filter(points__gt=0, floor=floor).count() + 1

    self.assertEqual(ScoreboardEntry.user_round_overall_rank(self.user, self.current_round), overall_rank, 
                    "Check user is last overallfor the current round.")
    self.assertEqual(ScoreboardEntry.user_round_floor_rank(self.user, self.current_round), floor_rank, 
                    "Check user is last in their floor for the current round.")
                    
    user2 = User(username="******", password="******")
    user2.save()

    profile2 = user2.get_profile()
    entry2, created = ScoreboardEntry.objects.get_or_create(
                        profile=profile2, 
                        round_name=self.current_round,
                      )
    entry2.points = 10
    entry2.last_awarded_submission = datetime.datetime.today()
    entry2.floor = floor
    entry2.save()

    self.assertEqual(ScoreboardEntry.user_round_overall_rank(self.user, self.current_round), overall_rank + 1, 
                    "Check that the user's overall rank has moved down.")
    self.assertEqual(ScoreboardEntry.user_round_floor_rank(self.user, self.current_round), floor_rank + 1, 
                    "Check that the user's floor rank has moved down.")
예제 #3
0
    def testFloorRankWithSubmissionDate(self):
        """Tests that the floor_rank method accurately computes the rank when users have the same number of points."""
        user = User(username="******", password="******")
        user.save()
        dorm = Dorm(name="Test dorm")
        dorm.save()
        floor = Floor(number="A", dorm=dorm)
        floor.save()

        profile = user.get_profile()
        profile.floor = floor
        top_user = Profile.objects.all().order_by("-points")[0]
        profile.add_points(
            top_user.points + 1,
            datetime.datetime.today() - datetime.timedelta(minutes=1), "Test")
        profile.save()

        self.assertEqual(profile.floor_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.floor = floor
        profile2.save()
        print profile.points
        print profile2.points
        self.assertEqual(profile.floor_rank(), 2,
                         "Check that the user is now rank 2.")
예제 #4
0
    def setUp(self):
        """
    Sets up a test individual prize for the rest of the tests.
    This prize is not saved, as the round field is not yet set.
    """
        image_path = os.path.join(settings.PROJECT_ROOT, "fixtures",
                                  "test_images", "test.jpg")
        image = ImageFile(open(image_path, "r"))
        self.prize = Prize(
            title="Super prize!",
            short_description="A test prize",
            long_description="A test prize",
            image=image,
            award_to="individual_floor",
            competition_type="points",
            value=5,
        )

        self.saved_rounds = settings.COMPETITION_ROUNDS
        self.current_round = "Round 1"
        start = datetime.date.today()
        end = start + datetime.timedelta(days=7)

        settings.COMPETITION_ROUNDS = {
            "Round 1": {
                "start": start.strftime("%Y-%m-%d"),
                "end": end.strftime("%Y-%m-%d"),
            },
        }

        # Create test dorms, floors, and users.
        self.dorm = Dorm(name="Test Dorm")
        self.dorm.save()

        self.floors = [
            Floor(number=str(i), dorm=self.dorm) for i in range(0, 2)
        ]
        map(lambda f: f.save(), self.floors)

        self.users = [
            User.objects.create_user("test%d" % i, "*****@*****.**")
            for i in range(0, 4)
        ]

        # Assign users to floors.
        for index, user in enumerate(self.users):
            user.get_profile().floor = self.floors[index % 2]
            user.get_profile().save()
예제 #5
0
    def testFloorRankForCurrentRound(self):
        """Test that we can retrieve the rank for the user in the current round."""
        saved_rounds = settings.COMPETITION_ROUNDS
        current_round = "Round 1"
        start = datetime.date.today()
        end = start + datetime.timedelta(days=7)

        settings.COMPETITION_ROUNDS = {
            "Round 1": {
                "start": start.strftime("%Y-%m-%d"),
                "end": end.strftime("%Y-%m-%d"),
            },
        }

        dorm = Dorm(name="Test dorm")
        dorm.save()
        floor = Floor(number="A", dorm=dorm)
        floor.save()

        user = User(username="******", password="******")
        user.save()

        profile = user.get_profile()
        top_user = Profile.objects.all().order_by("-points")[0]
        profile.add_points(top_user.points + 1, datetime.datetime.today(),
                           "Test")
        profile.floor = floor
        profile.save()

        self.assertEqual(profile.current_round_floor_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.floor = floor
        profile2.save()

        self.assertEqual(profile.current_round_floor_rank(), 2,
                         "Check that the user is now number 2.")

        # Restore saved rounds.
        settings.COMPETITION_ROUNDS = saved_rounds
예제 #6
0
    def testFloorRankWithPoints(self):
        """Tests that the floor_rank method accurately computes the rank based on points."""
        user = User(username="******", password="******")
        user.save()
        dorm = Dorm(name="Test dorm")
        dorm.save()
        floor = Floor(number="A", dorm=dorm)
        floor.save()

        profile = user.get_profile()
        profile.floor = floor

        # Check that the user is ranked last if they haven't done anything.
        rank = Profile.objects.filter(floor=floor,
                                      points__gt=profile.points).count() + 1
        self.assertEqual(profile.floor_rank(), rank,
                         "Check that the user is ranked last.")

        # Make the user number 1 overall.
        top_user = Profile.objects.all().order_by("-points")[0]
        profile.add_points(top_user.points + 1, datetime.datetime.today(),
                           "Test")
        profile.save()

        self.assertEqual(profile.floor_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.floor_rank(), 1,
            "Check that the user is still number 1 if the new profile is not on the same floor."
        )

        profile2.floor = floor
        profile2.save()

        self.assertEqual(profile.floor_rank(), 2,
                         "Check that the user is now rank 2.")
예제 #7
0
 def testUserFloorRoundRankWithPoints(self):
   """Tests that the floor rank calculation for a round is correct based on points."""
   # Setup dorm
   dorm = Dorm(name="Test dorm")
   dorm.save()
   floor = Floor(number="A", dorm=dorm)
   floor.save()
   
   profile = self.user.get_profile()
   profile.floor = floor
   profile.save()
   
   # Set up entry
   top_entry  = ScoreboardEntry.objects.filter(round_name=self.current_round).order_by("-points")[0]
   entry, created = 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(ScoreboardEntry.user_round_floor_rank(self.user, self.current_round), 1, 
                   "Check user is ranked #1 for the current round.")
   
   user2 = User(username="******", password="******")
   user2.save()
   profile2 = user2.get_profile()
   profile2.floor = floor
   profile2.save()
   
   entry2, created = 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(ScoreboardEntry.user_round_floor_rank(self.user, self.current_round), 2, 
                   "Check user is now second.")
예제 #8
0
파일: tests.py 프로젝트: ilwoof/makahiki
 def setUp(self):
     self.dorm = Dorm(name="Test dorm")
     self.dorm.save()
     self.test_floor = Floor(number="A", dorm=self.dorm)
     self.test_floor.save()