def testIndexMostPopular(self): """Test most popular""" posts = self.team.post_set.count() commitment = Commitment( type="commitment", title="Test commitment2", slug="test-commitment2", description="A commitment2!", point_value=10, ) commitment.save() member = ActionMember(action=commitment, user=self.user) member.save() member = ActionMember(action=commitment, user=self.user, approval_status="approved", award_date=datetime.datetime.today()) member.save() response = self.client.get(reverse("news_index")) self.failUnlessEqual(response.status_code, 200) self.assertEqual( posts + 2, self.team.post_set.count(), "Two posts should have been posted to the wall (commit and award)." )
def testCommitmentAchievement(self): """Check that the user's commitment achievements are loaded.""" commitment = Commitment( title="Test commitment", description="A commitment!", point_value=10, type="commitment", slug="test-commitment", ) commitment.save() # Test that profile page has a pending activity. member = ActionMember(user=self.user, action=commitment) member.save() response = self.client.get(reverse("profile_index")) self.assertContains(response, reverse("activity_task", args=(commitment.type, commitment.slug,))) self.assertContains(response, "In Progress") self.assertContains(response, "Commitment:") self.assertNotContains(response, "You have nothing in progress or pending.") # Test that the profile page has a rejected activity member.award_date = datetime.datetime.today() member.save() response = self.client.get(reverse("profile_index")) self.assertContains(response, reverse("activity_task", args=(commitment.type, commitment.slug,))) self.assertNotContains(response, "You have not been awarded anything yet!") self.assertNotContains(response, "In Progress")
def testIndexCommitment(self): """Tests that a commitment shows up in public commitments and in the wall.""" posts = self.team.post_set.count() # Create a commitment that will appear on the news page. commitment = Commitment( type="commitment", title="Test commitment", slug="test-commitment", description="A commitment!", point_value=10, ) commitment.save() member = ActionMember(action=commitment, user=self.user) member.save() response = self.client.get(reverse("news_index")) self.failUnlessEqual(response.status_code, 200) self.assertEqual( posts + 1, self.team.post_set.count(), "One post should have been posted to the wall (public commitment)." ) self.assertContains(response, commitment.title, 2, msg_prefix="Commitment title should only appear in the wall and the public " \ "commitments box." )
def instantiate_smartgrid_action_from_designer(draft, slug): """Creates a Smart Grid instance from the designer instance.""" des_action = get_designer_action(draft, slug) action_type = des_action.type old_obj = None try: old_obj = get_smartgrid_action(slug) except Http404: old_obj = None grid_action = None if old_obj == None: if action_type == 'activity': grid_action = Activity() if action_type == 'commitment': grid_action = Commitment() if action_type == 'event': grid_action = Event() if action_type == 'filler': grid_action = Filler() else: grid_action = old_obj _copy_fields_no_foriegn_keys(des_action, grid_action) grid_action.save() # Copy all the DesignerTextPropmtQuestions for question in DesignerTextPromptQuestion.objects.filter(draft=draft, action=des_action): old_ques = TextPromptQuestion.objects.filter(action=grid_action, \ question=question.question, \ answer=question.answer) if len(old_ques) == 0: tqp = TextPromptQuestion(action=grid_action, question=question.question, \ answer=question.answer) tqp.save() return grid_action
def testAddCommitment(self): """ Test that the user can add a commitment. """ commitment = Commitment( title="Test commitment", slug="test-commitment", description="A commitment!", point_value=10, type="commitment", ) commitment.save() response = self.client.post(reverse("activity_add_task", args=( commitment.type, commitment.slug, )), follow=True) self.failUnlessEqual(response.status_code, 200) points = Profile.objects.get(user=self.user).points response = self.client.post(reverse("activity_add_task", args=( commitment.type, commitment.slug, )), follow=True) self.failUnlessEqual(response.status_code, 200) self.assertEqual(points, Profile.objects.get(user=self.user).points)
def testHasCommitment(self): """Tests that has_action works for a commitment in progress.""" commitment = Commitment( title="Test commitment", type="commitment", name="Test", slug="test-commitment", description="A commitment!", point_value=10, ) commitment.save() # Test as an unlock condition. self.quest.unlock_conditions = "completed_action(slug='test-commitment')" self.quest.save() self.assertTrue( self.quest not in get_quests(self.user), "User should not be able to participate in this quest.") member = ActionMember(user=self.user, action=commitment) member.save() self.assertTrue(completed_action(self.user, slug='test-commitment'), "User should have a commitment in progress.") self.assertTrue(completed_some_of(self.user, action_type="commitment"), "User should have a commitment in progress.") self.assertTrue( self.quest in get_quests(self.user)["available_quests"], "User should be able to participate in this quest.") self.quest.unlock_conditions = "completed_some_of(action_type='commitment')" self.quest.save() self.assertTrue( self.quest in get_quests(self.user)["available_quests"], "User should be able to participate in this quest.") member.award_date = datetime.datetime.today() member.save() self.assertTrue(completed_action(self.user, slug='test-commitment'), "User should have a completed commitment.") self.assertTrue(completed_some_of(self.user, action_type="commitment"), "User should have a completed commitment.") # Test as a completion condition self.quest.accept(self.user) self.quest.completion_conditions = "not completed_action(slug='test-commitment')" self.quest.save() self.assertTrue(self.quest not in possibly_completed_quests(self.user), "User should not be able to complete this quest.") self.quest.completion_conditions = "not completed_some_of(action_type='commitment')" self.quest.save() self.assertTrue(self.quest not in possibly_completed_quests(self.user), "User should not be able to complete this quest.") self.quest.completion_conditions = "completed_action(slug='test-commitment')" self.quest.save() self.assertTrue(self.quest in possibly_completed_quests(self.user), "User should be able to complete this quest.")
def testCommitmentsNumCompleted(self): """Tests that approved_some_of works for a completed commitment.""" commitment = Commitment( title="Test commitment", type="commitment", slug="test", name="Test", description="A commitment!", point_value=10, ) commitment.save() member = ActionMember(user=self.user, action=commitment) member.save() self.assertFalse( approved_some(self.user, count=1), "User with commitment in progress should not have completed a task." ) # Test as an unlock condition self.quest.unlock_conditions = "approved_some(count=1)" self.quest.save() self.assertTrue( self.quest not in get_quests(self.user), "User should not be able to participate in this quest.") member.award_date = datetime.datetime.today() member.approval_status = "approved" member.save() self.assertTrue( approved_some(self.user, count=1), "User that has a completed commitment did not complete a task.") self.assertTrue( self.quest in get_quests(self.user)["available_quests"], "User should be able to participate in this quest.") # Test as a completion condition self.quest.accept(self.user) self.quest.completion_conditions = "approved_some(count=2)" self.quest.save() self.assertTrue(self.quest not in possibly_completed_quests(self.user), "User should not be able to complete this quest.") self.quest.completion_conditions = "approved_some(count=1)" self.quest.save() self.assertTrue(self.quest in possibly_completed_quests(self.user), "User should be able to complete this quest.")
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()