def setUp(self): self.user = test_utils.setup_user(username="******", password="******") challenge_mgr.register_page_widget("help", "help.rule") cache_mgr.clear() self.client.login(username="******", password="******")
def save(self, *args, **kwargs): event = super(LibraryEventAdminForm, self).save(*args, **kwargs) event.type = 'event' event.save() cache_mgr.clear() return event
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 testCancelQuest(self): """Test that a user can cancel their participation in a quest.""" quest = test_utils.create_quest(completion_conditions=False) cache_mgr.clear() response = self.client.post( reverse("quests_accept", args=(quest.quest_slug, )), follow=True, HTTP_REFERER=reverse("home_index"), ) self.assertTrue( quest in response.context["DEFAULT_VIEW_OBJECTS"]["quests"] ["user_quests"], "User should be participating in the test quest.") response = self.client.post( reverse("quests_cancel", args=(quest.quest_slug, )), follow=True, HTTP_REFERER=reverse("home_index"), ) self.assertRedirects(response, reverse("home_index")) self.assertTrue( quest not in response.context["DEFAULT_VIEW_OBJECTS"]["quests"] ["user_quests"], "Test quest should not be in user's quests.") self.assertTrue( quest in response.context["DEFAULT_VIEW_OBJECTS"]["quests"] ["available_quests"], "Test quest should be in available quests.")
def testQuestCompletion(self): """Test that a user gets a dialog box when they complete a quest.""" quest = test_utils.create_quest(completion_conditions=True) cache_mgr.clear() response = self.client.get(reverse("home_index")) self.assertEqual(len(response.context["DEFAULT_VIEW_OBJECTS"]["notifications"]["alerts"]), 0, "User should not have any completed quests.") response = self.client.post( reverse("quests_accept", args=(quest.quest_slug,)), follow=True, HTTP_REFERER=reverse("home_index"), ) self.assertRedirects(response, reverse("home_index")) response = self.client.get(reverse("home_index")) self.assertFalse(quest in response.context["DEFAULT_VIEW_OBJECTS"]["quests"]["user_quests"], "Quest should not be loaded as a user quest.") message = "Congratulations! You completed the '%s' quest." % quest.name self.assertContains(response, message, msg_prefix="Quest completion message should be shown.") self.assertContains(response, "notification-dialog", msg_prefix="Notification dialog should be shown.")
def save(self, *args, **kwargs): commitment = super(CommitmentAdminForm, self).save(*args, **kwargs) commitment.type = "commitment" commitment.save() cache_mgr.clear() return commitment
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 testQuestCompletion(self): """Test that a user gets a dialog box when they complete a quest.""" quest = test_utils.create_quest(completion_conditions=True) cache_mgr.clear() response = self.client.get(reverse("home_index")) self.assertEqual( len(response.context["DEFAULT_VIEW_OBJECTS"]["notifications"] ["alerts"]), 0, "User should not have any completed quests.") response = self.client.post( reverse("quests_accept", args=(quest.quest_slug, )), follow=True, HTTP_REFERER=reverse("home_index"), ) self.assertRedirects(response, reverse("home_index")) response = self.client.get(reverse("home_index")) self.assertFalse( quest in response.context["DEFAULT_VIEW_OBJECTS"]["quests"] ["user_quests"], "Quest should not be loaded as a user quest.") message = "Congratulations! You completed the '%s' quest." % quest.name self.assertContains( response, message, msg_prefix="Quest completion message should be shown.") self.assertContains(response, "notification-dialog", msg_prefix="Notification dialog should be shown.")
def save(self, *args, **kwargs): """save""" commitment = super(DesignerCommitmentAdminForm, self).save(*args, **kwargs) commitment.type = 'commitment' commitment.save() cache_mgr.clear() return commitment
def save(self, *args, **kwargs): """save""" event = super(DesignerEventAdminForm, self).save(*args, **kwargs) event.type = 'event' event.save() cache_mgr.clear() return event
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 setUp(self): """setup""" self.user = self.user = test_utils.setup_user(username="******", password="******") challenge_mgr.register_page_widget("learn", "smartgrid") from apps.managers.cache_mgr import cache_mgr cache_mgr.clear() self.client.login(username="******", password="******")
def save(self, *args, **kwargs): filler = super(FillerAdminForm, self).save(*args, **kwargs) filler.type = "filler" filler.unlock_condition = "False" filler.unlock_condition_text = "This cell is here only to fill out the grid. " \ "There is no action associated with it." filler.save() cache_mgr.clear() return filler
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 save(self, *args, **kwargs): event = super(EventAdminForm, self).save(*args, **kwargs) if event.is_excursion: event.type = "excursion" else: event.type = "event" event.save() cache_mgr.clear() return event
def setUp(self): self.user = test_utils.setup_user(username="******", password="******") self.team = self.user.get_profile().team challenge_mgr.register_page_widget("help", "help.faq") challenge_mgr.register_page_widget("home", "home") from apps.managers.cache_mgr import cache_mgr cache_mgr.clear() self.client.login(username="******", password="******")
def save(self, *args, **kwargs): activity = super(ActivityAdminForm, self).save(*args, **kwargs) activity.type = "activity" activity.save() cache_mgr.clear() # If the activity's confirmation type is text, make sure to save the questions. if self.cleaned_data.get("confirm_type") == "text": self.save_m2m() return activity
def save(self, *args, **kwargs): """Custom save method.""" super(Team, self).save(*args, **kwargs) # also create the resource goal settings from apps.widgets.resource_goal.models import EnergyGoalSetting, WaterGoalSetting if not EnergyGoalSetting.objects.filter(team=self): EnergyGoalSetting(team=self).save() if not WaterGoalSetting.objects.filter(team=self): WaterGoalSetting(team=self).save() cache_mgr.clear()
def setUp(self): self.user = test_utils.setup_user(username="******", password="******") self.team = self.user.get_profile().team challenge_mgr.register_page_widget("news", "popular_tasks") challenge_mgr.register_page_widget("news", "my_commitments") challenge_mgr.register_page_widget("news", "wallpost.system_wallpost") challenge_mgr.register_page_widget("news", "wallpost.user_wallpost") from apps.managers.cache_mgr import cache_mgr cache_mgr.clear() 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): self.user = test_utils.setup_user(username="******", password="******") self.team = self.user.profile.team challenge_mgr.register_page_widget("news", "popular_tasks") challenge_mgr.register_page_widget("news", "my_commitments") challenge_mgr.register_page_widget("news", "wallpost.system_wallpost") challenge_mgr.register_page_widget("news", "wallpost.user_wallpost") from apps.managers.cache_mgr import cache_mgr cache_mgr.clear() self.client.login(username="******", password="******")
def setUp(self): """ setup """ challenge_mgr.init() self.user = test_utils.setup_user(username="******", password="******") challenge_mgr.register_page_widget("learn", "smartgrid") challenge_mgr.register_page_widget("learn", "scoreboard") cache_mgr.clear() 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 testAcceptQuest(self): """Test that a user can accept a quest using a url.""" quest = test_utils.create_quest(completion_conditions=False) cache_mgr.clear() response = self.client.get(reverse("home_index")) self.assertContains(response, "Test quest", msg_prefix="Test quest should be available to the user.") response = self.client.post( reverse("quests_accept", args=(quest.quest_slug,)), follow=True, HTTP_REFERER=reverse("home_index"), ) self.assertRedirects(response, reverse("home_index")) quests = get_quests(self.user) self.assertEqual(len(quests["user_quests"]), 1, "User should have one quest.")
def save(self, *args, **kwargs): event = super(EventAdminForm, self).save(*args, **kwargs) if event.is_excursion: event.type = "excursion" else: event.type = "event" event.save() cache_mgr.clear() # Generate confirmation codes if needed. if self.cleaned_data.get("num_codes") > 0: ConfirmationCode.generate_codes_for_activity(event, self.cleaned_data.get("num_codes")) return event
def testCache(self): """Tests basic cache operations.""" self.assertTrue(cache_mgr.info() is not None, "Test that info() return something.") cache_mgr.set_cache('test_key', 'test_value') if settings.MAKAHIKI_USE_MEMCACHED: self.assertEqual(cache_mgr.get_cache('test_key'), 'test_value', "Test get the correct value from cache.") cache_mgr.delete('test_key') self.assertEqual(cache_mgr.get_cache('test_key'), None, "Test get the correct value from cache.") cache_mgr.clear() self.assertEqual(cache_mgr.get_cache('test_key'), None, "Test get the correct value from cache.")
def testOptOutOfQuest(self): """Test that a user can opt out of the quest.""" quest = test_utils.create_quest(completion_conditions=False) cache_mgr.clear() response = self.client.get(reverse("home_index")) self.assertContains(response, "Test quest", msg_prefix="Test quest should be available to the user.") response = self.client.post( reverse("quests_opt_out", args=(quest.quest_slug,)), follow=True, HTTP_REFERER=reverse("home_index"), ) self.assertRedirects(response, reverse("home_index")) self.assertNotContains(response, "Test quest", msg_prefix="Test quest should not be shown.") self.assertFalse("completed" in response.context["DEFAULT_VIEW_OBJECTS"]["quests"], "There should not be any completed quests.")
def testGetQuests(self): """Test that quests show up in the interface.""" quest = test_utils.create_quest(completion_conditions=False) quest.unlock_conditions = "False" quest.save() cache_mgr.clear() response = self.client.get(reverse("home_index")) self.failUnlessEqual(response.status_code, 200) self.assertNotContains(response, "Test quest", msg_prefix="Test quest should not be available to the user.") quest.unlock_conditions = "True" quest.save() cache_mgr.clear() response = self.client.get(reverse("home_index")) self.assertContains(response, "Test quest", msg_prefix="Test quest should be available to the user.")
def testEnergyScoreboard(self): """test Energy scoreboard.""" cache_mgr.clear() response = self.client.get(reverse("energy_index")) goals = response.context["view_objects"][ "resource_scoreboard__energy"]["round_resource_goal_ranks"][ "Round 1"] for goal in goals: self.assertEqual(goal["completions"], 0, "No team should have completed a goal.") energy_goal = EnergyGoal.objects.create( team=self.team, date=datetime.date.today(), goal_status="Over the goal", ) response = self.client.get(reverse("energy_index")) goals = response.context["view_objects"][ "resource_scoreboard__energy"]["round_resource_goal_ranks"][ "Round 1"] for goal in goals: self.assertEqual(goal["completions"], 0, "No team should have completed a goal.") energy_goal.goal_status = "Below the goal" energy_goal.save() cache_mgr.clear() response = self.client.get(reverse("energy_index")) goals = response.context["view_objects"][ "resource_scoreboard__energy"]["round_resource_goal_ranks"][ "Round 1"] for team in goals: if team["team__name"] == self.team.name: # print team.teamenergygoal_set.all() self.assertEqual( team["completions"], 1, "User's team should have completed 1 goal, but completed %d" % team["completions"]) else: self.assertEqual(team["completions"], 0, "No team should have completed a goal.")
def testAcceptQuest(self): """Test that a user can accept a quest using a url.""" quest = test_utils.create_quest(completion_conditions=False) cache_mgr.clear() response = self.client.get(reverse("home_index")) self.assertContains( response, "Test quest", msg_prefix="Test quest should be available to the user.") response = self.client.post( reverse("quests_accept", args=(quest.quest_slug, )), follow=True, HTTP_REFERER=reverse("home_index"), ) self.assertRedirects(response, reverse("home_index")) quests = get_quests(self.user) self.assertEqual(len(quests["user_quests"]), 1, "User should have one quest.")
def setUp(self): """Sets up the test evironment for the Designer views.""" self.user = test_utils.setup_superuser(username="******", password="******") challenge_mgr.register_page_widget("sgg_designer", "smartgrid_design") from apps.managers.cache_mgr import cache_mgr cache_mgr.clear() self.client.login(username="******", password="******") try: draft = smartgrid_mgr.get_designer_draft(self.draft_slug) except Http404: # shouldn't happen Default draft is defined in base_settings draft = Draft(name='Default', slug='default') draft.save() try: level = smartgrid_mgr.get_designer_level(draft, self.level_slug) except Http404: # ensure there is a DesignerLevel level = DesignerLevel(name="Level 1", slug=self.level_slug, priority=1, draft=draft) level.save()
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_two_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 testGetQuests(self): """Test that quests show up in the interface.""" quest = test_utils.create_quest(completion_conditions=False) quest.unlock_conditions = "False" quest.save() cache_mgr.clear() response = self.client.get(reverse("home_index")) self.failUnlessEqual(response.status_code, 200) self.assertNotContains( response, "Test quest", msg_prefix="Test quest should not be available to the user.") quest.unlock_conditions = "True" quest.save() cache_mgr.clear() response = self.client.get(reverse("home_index")) self.assertContains( response, "Test quest", msg_prefix="Test quest should be available to the user.")
def testOptOutOfQuest(self): """Test that a user can opt out of the quest.""" quest = test_utils.create_quest(completion_conditions=False) cache_mgr.clear() response = self.client.get(reverse("home_index")) self.assertContains( response, "Test quest", msg_prefix="Test quest should be available to the user.") response = self.client.post( reverse("quests_opt_out", args=(quest.quest_slug, )), follow=True, HTTP_REFERER=reverse("home_index"), ) self.assertRedirects(response, reverse("home_index")) self.assertNotContains(response, "Test quest", msg_prefix="Test quest should not be shown.") self.assertFalse( "completed" in response.context["DEFAULT_VIEW_OBJECTS"]["quests"], "There should not be any completed quests.")
def testCancelQuest(self): """Test that a user can cancel their participation in a quest.""" quest = test_utils.create_quest(completion_conditions=False) cache_mgr.clear() response = self.client.post( reverse("quests_accept", args=(quest.quest_slug,)), follow=True, HTTP_REFERER=reverse("home_index"), ) self.assertTrue(quest in response.context["DEFAULT_VIEW_OBJECTS"]["quests"]["user_quests"], "User should be participating in the test quest.") response = self.client.post( reverse("quests_cancel", args=(quest.quest_slug,)), follow=True, HTTP_REFERER=reverse("home_index"), ) self.assertRedirects(response, reverse("home_index")) self.assertTrue( quest not in response.context["DEFAULT_VIEW_OBJECTS"]["quests"]["user_quests"], "Test quest should not be in user's quests.") self.assertTrue( quest in response.context["DEFAULT_VIEW_OBJECTS"]["quests"]["available_quests"], "Test quest should be in available quests.")
def testEnergyScoreboard(self): """test Energy scoreboard.""" cache_mgr.clear() response = self.client.get(reverse("energy_index")) goals = response.context["view_objects"]["resource_scoreboard__energy"][ "round_resource_goal_ranks"]["Round 1"] for goal in goals: self.assertEqual(goal["completions"], 0, "No team should have completed a goal.") energy_goal = EnergyGoal.objects.create( team=self.team, date=datetime.date.today(), goal_status="Over the goal", ) response = self.client.get(reverse("energy_index")) goals = response.context["view_objects"]["resource_scoreboard__energy"][ "round_resource_goal_ranks"]["Round 1"] for goal in goals: self.assertEqual(goal["completions"], 0, "No team should have completed a goal.") energy_goal.goal_status = "Below the goal" energy_goal.save() cache_mgr.clear() response = self.client.get(reverse("energy_index")) goals = response.context["view_objects"]["resource_scoreboard__energy"][ "round_resource_goal_ranks"]["Round 1"] for team in goals: if team["team__name"] == self.team.name: # print team.teamenergygoal_set.all() self.assertEqual(team["completions"], 1, "User's team should have completed 1 goal, but completed %d" % team[ "completions"]) else: self.assertEqual(team["completions"], 0, "No team should have completed a goal.")
def save(self, *args, **kwargs): """Custom save method to set fields.""" super(Category, self).save(args, kwargs) cache_mgr.clear()
def save(self, *args, **kwargs): """Custom save method.""" super(PageInfo, self).save(*args, **kwargs) cache_mgr.clear()
def save(self, *args, **kwargs): """Custom save method.""" super(GameSetting, self).save(*args, **kwargs) cache_mgr.clear()
def save(self, *args, **kwargs): """Custom save method to set fields.""" super(Level, self).save(args, kwargs) cache_mgr.clear()
def handle(self, *args, **options): """handle clear cache""" cache_mgr.clear() print "makahiki cache cleared."
def save(self, *args, **kwargs): """Custom save method to set fields.""" super(LibraryColumnName, self).save(args, kwargs) cache_mgr.clear()
def clear_cache(request): """clear all cached content.""" _ = request cache_mgr.clear() return HttpResponseRedirect("/admin")