def setUp(self): """Set up rounds, team, and a user.""" # Set up rounds. test_utils.set_three_rounds() # Set up user self.user = test_utils.setup_user(username="******", password="******") challenge_mgr.register_page_widget("win", "raffle") self.client.login(username="******", password="******")
def testLeadersInRound2(self): """Test that the leaders are displayed correctly in round 2.""" print "testLeadersInRound2.1 prize count %d" % Prize.objects.count() test_utils.set_three_rounds() print "testLeadersInRound2.2 prize count %d" % Prize.objects.count() test_utils.setup_round_prize("Round 1", "team_overall", "energy") test_utils.setup_round_prize("Round 2", "team_overall", "energy") test_utils.setup_round_prize("Round 1", "team_overall", "points") test_utils.setup_round_prize("Round 2", "team_overall", "points") test_utils.setup_round_prize("Round 1", "individual_overall", "points") test_utils.setup_round_prize("Round 2", "individual_overall", "points") test_utils.setup_round_prize("Round 1", "individual_team", "points") test_utils.setup_round_prize("Round 2", "individual_team", "points") print "testLeadersInRound2.3 prize count %d" % Prize.objects.count() profile = self.user.profile profile.add_points(10, datetime.datetime.today(), "test") profile.name = "Test User" team = profile.team profile.save() from apps.managers.cache_mgr import cache_mgr cache_mgr.clear() print "testLeadersInRound2.4 prize count %d" % Prize.objects.count() response = self.client.get(reverse("win_index")) self.assertContains( response, "Winner: ", count=3, msg_prefix="There should be winners for three prizes.") self.assertContains( response, "Current leader: " + str(profile), count=2, msg_prefix="Individual prizes should have user as the leader.") self.assertContains( response, "Current leader: " + str(team), count=1, msg_prefix="Team points prizes should have team as the leader") # Test XSS vulnerability. profile.name = '<div id="xss-script"></div>' profile.save() response = self.client.get(reverse("win_index")) self.assertNotContains(response, profile.name, msg_prefix="<div> tag should be escaped.")
def testLeadersInRound2(self): """Test that the leaders are displayed correctly in round 2.""" print "testLeadersInRound2.1 prize count %d" % Prize.objects.count() test_utils.set_three_rounds() print "testLeadersInRound2.2 prize count %d" % Prize.objects.count() test_utils.setup_round_prize("Round 1", "team_overall", "energy") test_utils.setup_round_prize("Round 2", "team_overall", "energy") test_utils.setup_round_prize("Round 1", "team_overall", "points") test_utils.setup_round_prize("Round 2", "team_overall", "points") test_utils.setup_round_prize("Round 1", "individual_overall", "points") test_utils.setup_round_prize("Round 2", "individual_overall", "points") test_utils.setup_round_prize("Round 1", "individual_team", "points") test_utils.setup_round_prize("Round 2", "individual_team", "points") print "testLeadersInRound2.3 prize count %d" % Prize.objects.count() profile = self.user.get_profile() profile.add_points(10, datetime.datetime.today(), "test") profile.name = "Test User" team = profile.team profile.save() from apps.managers.cache_mgr import cache_mgr cache_mgr.clear() print "testLeadersInRound2.4 prize count %d" % Prize.objects.count() response = self.client.get(reverse("win_index")) self.assertContains(response, "Winner: ", count=3, msg_prefix="There should be winners for three prizes.") self.assertContains(response, "Current leader: " + str(profile), count=2, msg_prefix="Individual prizes should have user as the leader.") self.assertContains(response, "Current leader: " + str(team), count=1, msg_prefix="Team points prizes should have team as the leader") # Test XSS vulnerability. profile.name = '<div id="xss-script"></div>' profile.save() response = self.client.get(reverse("win_index")) self.assertNotContains(response, profile.name, msg_prefix="<div> tag should be escaped.")
def setUp(self): """Setup the test environment.""" test_utils.set_three_rounds()