def setUp(self): """ Sets up a test team prize for the rest of the tests. This prize is not saved, as the round field is not yet set. """ self.prize = test_utils.setup_prize(award_to="team_group", competition_type="points") self.current_round = "Round 1" test_utils.set_competition_round() # Create test groups, teams, and users. self.groups = [Group(name="Test Group %d" % i) for i in range(0, 2)] _ = [d.save() for d in self.groups] self.teams = [ Team(name=str(i), group=self.groups[i % 2]) for i in range(0, 4) ] _ = [f.save() for f in self.teams] self.users = [ User.objects.create_user("test%d" % i, "*****@*****.**") for i in range(0, 4) ] # Assign users to teams. for index, user in enumerate(self.users): user.get_profile().team = self.teams[index % 4] user.get_profile().save()
def testTeamRankForCurrentRound(self): """Test that we can retrieve the rank for the user in the current round.""" test_utils.set_competition_round() group = Group(name="Test group") group.save() team = Team(name="A", group=group) team.save() user = User(username="******", password="******") user.save() profile = user.get_profile() top_user = Profile.objects.all()[0] profile.add_points(top_user.points() + 1, datetime.datetime.today(), "Test") profile.team = team profile.save() self.assertEqual(profile.current_round_team_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.team = team profile2.save() self.assertEqual(profile.current_round_team_rank(), 2, "Check that the user is now number 2.")
def testOverallRankForCurrentRound(self): """Test that we can retrieve the rank for the user in the current round.""" test_utils.set_competition_round() user = User(username="******", password="******") user.save() profile = user.profile top_user = player_mgr.points_leader() profile.add_points(top_user.points() + 1, datetime.datetime.today(), "Test") profile.save() self.assertEqual(profile.current_round_overall_rank(), 1, "Check that the user is number 1.") user2 = User(username="******", password="******") user2.save() profile2 = user2.profile profile2.add_points(profile.points() + 1, datetime.datetime.today(), "Test") profile2.save() self.assertEqual(profile.current_round_overall_rank(), 2, "Check that the user is now number 2.")
def setUp(self): challenge_mgr.init() self.user = User(username="******", password="******") self.user.save() self.quest = test_utils.create_quest(completion_conditions=False) test_utils.set_competition_round()
def setUp(self): """Sets up the test environment.""" self.user = test_utils.setup_user("user", "changeme") self.draft = Draft(name="test", slug="test") test_utils.set_competition_round() self.team = self.user.profile.team self.predicates = [ "completed_action('intro-video')", "submitted_all_of_type(action_type='commitment')", "allocated_raffle_ticket()", "badge_awarded('daily-visitor')", "completed_some_of_level(level_priority=1, count=2)", "submitted_some_of_resource(resource='energy', count=2)", "submitted_all_of_level(1)", "approved_all_of_resource(resource='energy')", "approved_some_of_resource(resource='water', count=3)", "set_profile_pic()", "referring_count(4)", "daily_visit_count(10)", "unlock_on_date('13-07-16')", "unlock_on_event(event_slug='kick-off', days=-3, lock_after_days=5)", "approved_some_of_level(level_priority=3, count=3)", "submitted_level(3)", "completed_some_of('event', 3)", "daily_energy_goal_count(5)", "submitted_action('like-cup')", "approved_all_of_type('commitment')", "approved_all_of_level(4)", "posted_to_wall()", "submitted_some_of_level(3, 4)", "submitted_some_of_type('commitment', 2)", "submitted_some_full_spectrum(3)", "change_theme()", "changed_theme()", "approved_some_full_spectrum(4)", "reached_round('Round 2')", "social_bonus_count(30)", "team_member_point_percent(30, 25)", "approved_some(5)", "completed_level(3)", "approved_action('like-cup')", "has_points(10)", "submitted_all_of_resource('water')", "submitted_some(34)", "game_enabled('foobar')", "is_admin()", "approved_some_of_type('activity', 5)" ]
def testTeamRankForCurrentRound(self): """Test that we can retrieve the rank for the user in the current round.""" test_utils.set_competition_round() group = Group(name="Test group") group.save() team = Team(name="A", group=group) team.save() user = User(username="******", password="******") user.save() profile = user.profile top_user = Profile.objects.all()[0] profile.add_points(top_user.points() + 1, datetime.datetime.today(), "Test") profile.team = team profile.save() self.assertEqual(profile.current_round_team_rank(), 1, "Check that the user is number 1.") user2 = User(username="******", password="******") user2.save() profile2 = user2.profile profile2.add_points(profile.points() + 1, datetime.datetime.today(), "Test") profile2.team = team profile2.save() self.assertEqual(profile.current_round_team_rank(), 2, "Check that the user is now 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 setUp(self): """Set up a team and log in.""" # challenge_mgr.init() test_utils.set_competition_round() self.user = test_utils.setup_user(username="******", password="******") 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 "setUp prize count %d" % Prize.objects.count() challenge_mgr.register_page_widget("win", "prizes") from apps.managers.cache_mgr import cache_mgr cache_mgr.clear() profile = self.user.get_profile() profile.add_points(10, datetime.datetime.today(), "test") profile.save() self.client.login(username="******", password="******")
def testOverallRankForCurrentRound(self): """Test that we can retrieve the rank for the user in the current round.""" test_utils.set_competition_round() user = User(username="******", password="******") user.save() profile = user.get_profile() top_user = player_mgr.points_leader() profile.add_points(top_user.points() + 1, datetime.datetime.today(), "Test") profile.save() self.assertEqual(profile.current_round_overall_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.current_round_overall_rank(), 2, "Check that the user is now number 2.")
def setUp(self): """ test case setup """ self.users = [User.objects.create_user("test%d" % i, "*****@*****.**") for i in range(0, 3)] self.current_round = "Round 1" test_utils.set_competition_round()
def setUp(self): """Initialize a user and log them in.""" self.user = test_utils.setup_user(username="******", password="******") self.team = self.user.get_profile().team test_utils.set_competition_round() challenge_mgr.register_page_widget("energy", "resource_scoreboard.energy") self.client.login(username="******", password="******")
def setUp(self): """Generate test. Set the competition settings to the current date for testing.""" self.user = User(username="******", password="******") self.user.save() self.current_round = "Round 1" test_utils.set_competition_round() self.user.profile.add_points(10, datetime.datetime.today(), "test")
def testIndex(self): """Check that we can load the index page.""" test_utils.set_competition_round() response = self.client.get(reverse("win_index")) self.failUnlessEqual(response.status_code, 200) for prize in Prize.objects.all(): self.assertContains(response, prize.title, msg_prefix="Prize not found on prize page")
def setUp(self): """ Sets up a test team overall prize for the rest of the tests. This prize is not saved, as the round field is not yet set. """ self.prize = test_utils.setup_prize(award_to="team_overall", competition_type="points") self.current_round = "Round 1" test_utils.set_competition_round() test_utils.create_teams(self)
def setUp(self): """setup""" self.user = test_utils.setup_user(username="******", password="******") test_utils.set_competition_round() challenge_mgr.register_page_widget("profile", "my_info") from apps.managers.cache_mgr import cache_mgr cache_mgr.clear() self.client.login(username="******", password="******")
def testIndex(self): """Check that we can load the index.""" test_utils.set_competition_round() User.objects.create_user("user", "*****@*****.**", password="******") self.client.login(username="******", password="******") challenge_mgr.register_page_widget("home", "home") response = self.client.get(reverse("home_index")) self.failUnlessEqual(response.status_code, 200)
def testIndex(self): """Check that we can load the index page.""" test_utils.set_competition_round() response = self.client.get(reverse("win_index")) self.failUnlessEqual(response.status_code, 200) print "testIndex prize count %d" % Prize.objects.count() for prize in Prize.objects.all(): self.assertContains(response, prize.title, msg_prefix="Prize not found on prize page")
def setUp(self): """ setup """ challenge_mgr.init() self.user = test_utils.setup_user(username="******", password="******") test_utils.set_competition_round() challenge_mgr.register_page_widget("learn", "participation") cache_mgr.clear() self.client.login(username="******", password="******")
def setUp(self): """ test case setup """ self.users = [ User.objects.create_user("test%d" % i, "*****@*****.**") for i in range(0, 3) ] self.current_round = "Round 1" test_utils.set_competition_round()
def setUp(self): """Generate test user and activity. Set the competition settings to the current date for testing.""" challenge_mgr.init() self.user = User.objects.create_user('user', '*****@*****.**') self.user.save() self.activity = test_utils.create_activity() self.event = test_utils.create_event() self.current_round = "Round 1" test_utils.set_competition_round()
def setUp(self): """Initialize a user and log them in.""" self.user = test_utils.setup_user(username="******", password="******") self.team = self.user.profile.team test_utils.set_competition_round() challenge_mgr.register_page_widget("energy", "resource_scoreboard.energy") game, _ = GameInfo.objects.get_or_create(name="Energy Game") game.enabled = True game.save() self.client.login(username="******", password="******")
def setUp(self): """setup.""" test_utils.set_competition_round() self.user = User.objects.create_user("user", "*****@*****.**", password="******") # create the term help-topic HelpTopic.objects.create(title="", slug="terms-and-conditions", category="faq", contents="") # create the setup activity Activity.objects.create(slug=SETUP_WIZARD_ACTIVITY, name="", title="", duration=5) challenge_mgr.register_page_widget("home", "home") self.client.login(username="******", password="******")
def setUp(self): """setup.""" test_utils.set_competition_round() self.user = User.objects.create_user("user", "*****@*****.**", password="******") # create the term help-topic HelpTopic.objects.create(title="", slug="terms-and-conditions", category="faq", contents="") # create the setup activity Activity.objects.create(slug=SETUP_WIZARD_ACTIVITY, name="", title="", expected_duration=5) challenge_mgr.register_page_widget("home", "home") self.client.login(username="******", password="******")
def setUp(self): """Initialize a user and log them in.""" self.user = test_utils.setup_user(username="******", password="******") self.team = self.user.get_profile().team test_utils.set_competition_round() challenge_mgr.register_page_widget("energy", "resource_scoreboard.energy") game, _ = GameInfo.objects.get_or_create(name="Energy Game") game.enabled = True game.save() self.client.login(username="******", password="******")
def setUp(self): """Sets up the environment for running the tests.""" self.user = test_utils.setup_user(username="******", password="******") from apps.managers.cache_mgr import cache_mgr cache_mgr.clear() self.client.login(username="******", password="******") test_utils.set_competition_round() self.activity = test_utils.create_activity(slug=None, unlock_condition=None) self.activity.save() self.commitment = test_utils.create_commitment(slug=None, unlock_condition=None) self.commitment.save() self.event = test_utils.create_event(slug=None, unlock_condition=None) self.event.save()
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. """ self.prize = test_utils.setup_prize(award_to="individual_overall", competition_type="points") self.current_round = "Round 1" test_utils.set_competition_round() # Create test users. self.users = [User.objects.create_user("test%d" % i, "*****@*****.**") for i in range(0, 3)]
def testCurrentRoundPoints(self): """Tests that we can retrieve the points for the user in the current round.""" test_utils.set_competition_round() user = User(username="******", password="******") user.save() profile = user.profile points = profile.points() profile.add_points(10, datetime.datetime.today(), "Test") profile.save() self.assertEqual(profile.current_round_points(), points + 10, "Check that the user has 10 more points in the current round.")
def setUp(self): """setup""" test_utils.set_competition_round() group = Group.objects.create(name="Test Group") group.save() self.team = Team.objects.create( group=group, name="A" ) self.user = User.objects.create_user("user", "*****@*****.**") profile = self.user.get_profile() profile.team = self.team profile.save()
def setUp(self): """Sets up the test environment.""" self.user = test_utils.setup_user("user", "changeme") self.draft = Draft(name="test", slug="test") test_utils.set_competition_round() self.team = self.user.profile.team self.predicates = [ "completed_action('intro-video')", "submitted_all_of_type(action_type='commitment')", "allocated_raffle_ticket()", "badge_awarded('daily-visitor')", "completed_some_of_level(level_priority=1, count=2)", "submitted_some_of_resource(resource='energy', count=2)", "submitted_all_of_level(1)", "approved_all_of_resource(resource='energy')", "approved_some_of_resource(resource='water', count=3)", "set_profile_pic()", "referring_count(4)", "daily_visit_count(10)", "unlock_on_date('13-07-16')", "unlock_on_event(event_slug='kick-off', days=-3, lock_after_days=5)", "approved_some_of_level(level_priority=3, count=3)", "submitted_level(3)", "completed_some_of('event', 3)", "daily_energy_goal_count(5)", "submitted_action('like-cup')", "approved_all_of_type('commitment')", "approved_all_of_level(4)", "posted_to_wall()", "submitted_some_of_level(3, 4)", "submitted_some_of_type('commitment', 2)", "submitted_some_full_spectrum(3)", "change_theme()", "changed_theme()", "approved_some_full_spectrum(4)", "reached_round('Round 2')", "social_bonus_count(30)", "team_member_point_percent(30, 25)", "approved_some(5)", "completed_level(3)", "approved_action('like-cup')", "has_points(10)", "submitted_all_of_resource('water')", "submitted_some(34)", "game_enabled('foobar')", "is_admin()", "approved_some_of_type('activity', 5)", ]
def testCurrentRoundPoints(self): """Tests that we can retrieve the points for the user in the current round.""" test_utils.set_competition_round() user = User(username="******", password="******") user.save() profile = user.get_profile() points = profile.points() profile.add_points(10, datetime.datetime.today(), "Test") profile.save() self.assertEqual( profile.current_round_points(), points + 10, "Check that the user has 10 more points in the current round.")
def testRoundInfo(self): """Tests that round info is available for the page to process.""" challenge_mgr.init() test_utils.set_competition_round() current_round = challenge_mgr.get_round_name() User.objects.create_user("user", "*****@*****.**", password="******") self.client.login(username="******", password="******") challenge_mgr.register_page_widget("home", "home") response = self.client.get(reverse("home_index")) # Response context should have round info corresponding to the past days. self.assertEqual(response.context["CURRENT_ROUND_INFO"]["name"], current_round, "Expected %s but got %s" % ( current_round, response.context["CURRENT_ROUND_INFO"]["name"]))
def setUp(self): """Create test user and commitment. Set the competition settings to the current date for testing.""" self.user = User(username="******", password="******") self.user.save() self.commitment = Commitment( title="Test commitment", name="Test", slug="test", description="A commitment!", point_value=10, type="commitment", ) self.commitment.save() self.current_round = "Round 1" test_utils.set_competition_round()
def testRoundInfo(self): """Tests that round info is available for the page to process.""" challenge_mgr.init() test_utils.set_competition_round() current_round = challenge_mgr.get_round_name() User.objects.create_user("user", "*****@*****.**", password="******") self.client.login(username="******", password="******") challenge_mgr.register_page_widget("home", "home") response = self.client.get(reverse("home_index")) # Response context should have round info corresponding to the past days. self.assertEqual( response.context["CURRENT_ROUND_INFO"]["name"], current_round, "Expected %s but got %s" % (current_round, response.context["CURRENT_ROUND_INFO"]["name"]))
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. """ self.prize = test_utils.setup_prize(award_to="individual_overall", competition_type="points") self.current_round = "Round 1" test_utils.set_competition_round() # Create test users. self.users = [ User.objects.create_user("test%d" % i, "*****@*****.**") for i in range(0, 3) ]
def setUp(self): self.groups = [Group(name="Test Group %d" % i) for i in range(0, 2)] _ = [d.save() for d in self.groups] self.teams = [Team(name=str(i), group=self.groups[i % 2]) for i in range(0, 4)] _ = [f.save() for f in self.teams] self.users = [User.objects.create_user("test%d" % i, "*****@*****.**") for i in range(0, 4)] # Assign users to teams. for index, user in enumerate(self.users): user.profile.team = self.teams[index % 4] user.profile.save() self.current_round = "Round 1" test_utils.set_competition_round()
def setUp(self): self.group = Group(name="Test Group") self.group.save() self.teams = [Team(name=str(i), group=self.group) for i in range(0, 2)] _ = [f.save() for f in self.teams] self.users = [ User.objects.create_user("test%d" % i, "*****@*****.**") for i in range(0, 4) ] # Assign users to teams. for index, user in enumerate(self.users): user.get_profile().team = self.teams[index % 2] user.get_profile().save() self.current_round = "Round 1" test_utils.set_competition_round()
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. """ test_utils.set_competition_round() # Create a test user self.user = User.objects.create_user("user", "*****@*****.**", password="******") image_path = os.path.join(settings.PROJECT_ROOT, "fixtures", "test_images", "test.jpg") image = ImageFile(open(image_path, "r")) self.prize = RafflePrize( title="Super prize!", description="A test prize", image=image, round=RoundSetting.objects.get(name="Round 1"), value=5, )
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 testCurrentRound(self): """Tests that the current round retrieval is correct.""" current_round = "Round 1" test_utils.set_competition_round() current = challenge_mgr.get_round_name() self.assertEqual(current, current_round, "Test that the current round is returned.") start = datetime.datetime.today() + datetime.timedelta(days=1) end = start + datetime.timedelta(days=7) rounds = RoundSetting.objects.get(name="Round 1") rounds.start = start rounds.end = end rounds.save() challenge_mgr.init() current_round = challenge_mgr.get_round_name() self.assertTrue(current_round is None, "Test that there is no current round.")
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 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 setUp(self): """ Sets up a test team prize for the rest of the tests. This prize is not saved, as the round field is not yet set. """ self.prize = test_utils.setup_prize(award_to="team_group", competition_type="points") self.current_round = "Round 1" test_utils.set_competition_round() # Create test groups, teams, and users. self.groups = [Group(name="Test Group %d" % i) for i in range(0, 2)] _ = [d.save() for d in self.groups] self.teams = [Team(name=str(i), group=self.groups[i % 2]) for i in range(0, 4)] _ = [f.save() for f in self.teams] self.users = [User.objects.create_user("test%d" % i, "*****@*****.**") for i in range(0, 4)] # Assign users to teams. for index, user in enumerate(self.users): user.profile.team = self.teams[index % 4] user.profile.save()
def testLeadersInRound1(self): """Test that the leaders are displayed correctly in round 1.""" test_utils.set_competition_round() from apps.managers.cache_mgr import cache_mgr cache_mgr.clear() profile = self.user.get_profile() profile.name = "Test User" profile.add_points(10, datetime.datetime.today(), "test") team = profile.team profile.save() response = self.client.get(reverse("win_index")) 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", ) self.assertContains( response, "Current leader: TBD", count=4, msg_prefix="Round 2 prizes should not have a leader yet." ) # 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 testScoreboard(self): """Test that the scoreboard loads current round information.""" test_utils.set_competition_round() # Give the user points in the round and then check the queryset used in the page. profile = self.user.get_profile() profile.add_points(10, datetime.datetime.today(), "test") profile.save() response = self.client.get(reverse("learn_index")) self.assertEqual(response.context["view_objects"]["scoreboard"][ "round_standings"]["Round 1"]["team_standings"][0]["profile__team__name"], profile.team.name, "The user's team should be leading.") self.assertEqual(response.context["view_objects"]["scoreboard"][ "round_standings"]["Round 1"]["profile_standings"][0]["profile__name"], profile.name, "The user's should be leading the overall standings.") self.assertEqual(response.context["view_objects"]["scoreboard"][ "round_standings"]["Round 1"]["user_team_standings"][0], profile, "The user should be leading in their own team.") self.assertEqual(response.context["view_objects"]["scoreboard"][ "round_standings"]["Round 1"]["team_standings"][0]["points"], 10, "The user's team should have 10 points this round.") self.assertEqual(response.context["view_objects"]["scoreboard"][ "round_standings"]["Round 1"]["profile_standings"][0]["points"], 10, "The user should have 10 points this round.") self.assertEqual(response.context["view_objects"]["scoreboard"][ "round_standings"]["Round 1"]["user_team_standings"][0].current_round_points(), 10, "The user should have 10 points this round.")
def setUp(self): """ test case setup """ test_utils.set_competition_round()
def setUp(self): """Sets up the test infrastructure.""" test_utils.set_competition_round()