def testBasicCompletion(self): """Tests that the user can complete quests.""" quest = test_utils.create_quest(completion_conditions=False) quests = get_quests(self.user) self.assertEqual(len(quests["available_quests"]), 1, "User should have one quest.") quests["available_quests"][0].accept(self.user) possibly_completed_quests(self.user) complete_quests = self.user.quest_set.filter(questmember__completed=True) self.assertTrue(quest not in complete_quests, "Quest should not be completed.") quest.completion_conditions = True quest.save() possibly_completed_quests(self.user) complete_quests = self.user.quest_set.filter(questmember__completed=True) self.assertTrue(quest in complete_quests, "Quest should be in the user's complete quests list.") quests = get_quests(self.user) self.assertTrue(quest not in quests["available_quests"], "Quest should not be available after completion.") self.assertTrue(quest not in quests["user_quests"], "Quest should not be in the user's active quests.")
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 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 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 testBasicCompletion(self): """Tests that the user can complete quests.""" quest = test_utils.create_quest(completion_conditions=False) quests = get_quests(self.user) self.assertEqual(len(quests["available_quests"]), 1, "User should have one quest.") quests["available_quests"][0].accept(self.user) possibly_completed_quests(self.user) complete_quests = self.user.quest_set.filter( questmember__completed=True) self.assertTrue(quest not in complete_quests, "Quest should not be completed.") quest.completion_conditions = True quest.save() possibly_completed_quests(self.user) complete_quests = self.user.quest_set.filter( questmember__completed=True) self.assertTrue(quest in complete_quests, "Quest should be in the user's complete quests list.") quests = get_quests(self.user) self.assertTrue(quest not in quests["available_quests"], "Quest should not be available after completion.") self.assertTrue(quest not in quests["user_quests"], "Quest should not be in the user's active 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 testBasicPrerequisites(self): """Tests that the user can only get quests for which they meet the prerequisites.""" quest = test_utils.create_quest(completion_conditions=False) quest.unlock_conditions = "False" quest.save() quests = get_quests(self.user) self.assertEqual(len(quests["available_quests"]), 0, "User should not have this quest available.") quest.unlock_conditions = "True" quest.save() quests = get_quests(self.user) self.assertEqual(len(quests["available_quests"]), 1, "User should now have one quest.")
def testAcceptQuest(self): """Test that a user can accept a quest using a url.""" quest = test_utils.create_quest(completion_conditions=False) 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 testOptOutOfQuest(self): """Test that a user can opt out of the quest.""" quest = test_utils.create_quest(completion_conditions=False) 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["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() 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() response = self.client.get(reverse("home_index")) self.assertContains(response, "Test quest", msg_prefix="Test quest should be available to the user.")
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 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 testCancelQuest(self): """Test that a user can cancel their participation in a quest.""" quest = test_utils.create_quest(completion_conditions=False) response = self.client.post( reverse("quests_accept", args=(quest.quest_slug,)), follow=True, HTTP_REFERER=reverse("home_index"), ) self.assertTrue(quest in response.context["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["view_objects"]["quests"]["user_quests"], "Test quest should not be in user's quests.") self.assertTrue( quest in response.context["view_objects"]["quests"]["available_quests"], "Test quest should be in available quests.")