Exemplo n.º 1
0
 def testInVotingPeriod(self):
   """Tests that the in voting method works."""
   start = datetime.date.today() - datetime.timedelta(days=2)
   voting_end = start + datetime.timedelta(days=3)
   end = start + datetime.timedelta(days=7)
   goal = EnergyGoal(
         start_date=start,
         voting_end_date=voting_end,
         end_date=end,
   )
   goal.save()
   
   self.assertTrue(goal.in_voting_period(), "Check that the goal is currently in the voting period.")
   goal.voting_end_date = datetime.date.today() - datetime.timedelta(days=1)
   goal.save()
   
   self.assertFalse(goal.in_voting_period(), "Check that the goal is now not in the voting period.")
Exemplo n.º 2
0
 def testGenerateFloorGoals(self):
   """Tests the generation of floor goals."""
   generate_floor_goals()
   for floor in Floor.objects.all():
     self.assertEqual(floor.floorenergygoal_set.count(), 0, "Test that nothing happens if there is no goal.")
     
   start = datetime.date.today() - datetime.timedelta(days=2)
   voting_end = datetime.date.today() + datetime.timedelta(days=1)
   end = start + datetime.timedelta(days=7)
   goal = EnergyGoal(
         start_date=start,
         voting_end_date=voting_end,
         end_date=end,
   )
   goal.save()
   
   # Test that this goal does not generate any floor goals because the voting period is not up.
   generate_floor_goals()
   for floor in Floor.objects.all():
     self.assertEqual(floor.floorenergygoal_set.count(), 0, "Test that no goals are created before the voting end date.")
   
   goal.voting_end_date = datetime.date.today()
   goal.save()
   
   # Create a test vote for a user.
   user = User.objects.get(username="******")
   vote = EnergyGoalVote(user=user, goal=goal, percent_reduction=10)
   vote.save()
   
   # Generate floor goals.
   generate_floor_goals()
   for floor in Floor.objects.all():
     floor_goal = FloorEnergyGoal.objects.get(floor=floor, goal=goal)
     
     # Our test user's floor should have a 10 percent reduction goal.
     if floor == user.get_profile().floor:
       self.assertEqual(floor_goal.percent_reduction, 10, "Check that test user's vote counts.")
     else:
       self.assertEqual(floor_goal.percent_reduction, 0, "Check that default goal is 0.")