Exemple #1
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.")
Exemple #2
0
  def testUserOverallRoundRankWithPoints(self):
    """Tests that the overall rank calculation for a user in a round is correct based on points."""
    profile = self.user.get_profile()
    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_overall_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()
    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_overall_rank(self.user, self.current_round), 2, 
                    "Check user is now second.")
Exemple #3
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.")