Example #1
0
 def testCommitmentsNumCompleted(self):
   """Tests that num_tasks_completed works for a completed commitment."""
   commitment = Commitment(
       title="Test commitment",
       type="commitment",
       name="Test",
       description="A commitment!",
       point_value=10,
   )
   commitment.save()
   
   member = CommitmentMember(user=self.user, commitment=commitment)
   member.save()
   self.assertFalse(num_tasks_completed(self.user, 1), "User with commitment in progress should not have completed a task.")
   
   # Test as an unlock condition
   self.quest.unlock_conditions = "num_tasks_completed(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.save()
   self.assertTrue(num_tasks_completed(self.user, 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 = "num_tasks_completed(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 = "num_tasks_completed(1)"
   self.quest.save()
   self.assertTrue(self.quest in possibly_completed_quests(self.user), "User should be able to complete this quest.")
Example #2
0
 def test_awarding(self):
   """
   Tests that the fully committed badge is awarded to a user.
   """
   user = User(username="******", password="******")
   user.save()
   
   
   commitments = []
   # Create 5 test commitments.
   for i in range(0, 5):
     commitment = Commitment(
         title="Test commitment %i" % i,
         description="A commitment!",
         point_value=10,
     )
     commitment.save()
     commitments.append(commitment)
   
   # Add the commitments one by one and see if the user earned a badge.
   # The badge should not be awarded until the very end.
   for index, commitment in enumerate(commitments):
     self.assertEqual(user.badges_earned.count(), 0, "Badge should not be awarded after %i commitments" % index)
     member = CommitmentMember(user=user, commitment=commitment, award_date=datetime.datetime.today())
     member.save()
     self.assertEqual(user.badges_earned.count(), 0, "Badge should not be awarded after commitment %i is awarded" % index)
     member.award_date = None
     member.save()
     
   self.assertEqual(user.badges_earned.count(), 1, "A badge should have been awarded.")
   self.assertEqual(user.badges_earned.all()[0].slug, "fully_committed", "Check that the Fully Committed badge was awarded.")
     
Example #3
0
  def testCommitmentAchievement(self):
    """Check that the user's achievements are loaded."""
    commitment = Commitment(
        title="Test commitment",
        description="A commitment!",
        point_value=10,
        type="commitment",
    )
    commitment.save()

    # Test that profile page has a pending activity.
    member = CommitmentMember(user=self.user, commitment=commitment)
    member.save()
    response = self.client.get(reverse("profile_index"))
    self.assertContains(response, reverse("activity_task", args=(commitment.id,)))
    self.assertContains(response, "In Progress")
    self.assertContains(response, "Commitment:")
    self.assertContains(response, "Made 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.id,)))
    self.assertNotContains(response, "You have not been awarded anything yet!")
    self.assertContains(response, "You have nothing in progress or pending.")
    
Example #4
0
 def test_awarding(self):
   """
   Tests that the fully committed badge is awarded to a user.
   """
   user = User(username="******", password="******")
   user.save()
   
   commitments = []
   # Create 5 test commitments.
   for i in range(0, 5):
     commitment = Commitment(
         title="Test commitment %i" % i,
         description="A commitment!",
         point_value=10,
     )
     commitment.save()
     commitments.append(commitment)
   
   # Add the commitments one by one and see if the user earned a badge.
   # The badge should not be awarded until the very end.
   for index, commitment in enumerate(commitments):
     self.assertEqual(user.badges_earned.count(), 0, "Badge should not be awarded after %i commitments" % index)
     member = CommitmentMember(user=user, commitment=commitment, award_date=datetime.datetime.today())
     member.save()
     self.assertEqual(user.badges_earned.count(), 0, "Badge should not be awarded after commitment %i is awarded" % index)
     member.award_date = None
     member.save()
     
   self.assertEqual(user.badges_earned.count(), 1, "A badge should have been awarded.")
   self.assertEqual(user.badges_earned.all()[0].slug, "fully_committed", "Check that the Fully Committed badge was awarded.")
Example #5
0
  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 = CommitmentMember(user=self.user, commitment=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.assertContains(response, "You have nothing in progress or pending.")
Example #6
0
    def testHasCommitment(self):
        """Tests that has_task 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 = "has_task(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 = CommitmentMember(user=self.user, commitment=commitment)
        member.save()
        self.assertTrue(has_task(self.user, slug="test-commitment"), "User should have a commitment in progress.")
        self.assertTrue(has_task(self.user, task_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 = "has_task(task_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(has_task(self.user, slug="test-commitment"), "User should have a completed commitment.")
        self.assertTrue(has_task(self.user, task_type="commitment"), "User should have a completed commitment.")

        # Test as a completion condition
        self.quest.accept(self.user)
        self.quest.completion_conditions = "not has_task(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 has_task(task_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 = "has_task(slug='test-commitment')"
        self.quest.save()
        self.assertTrue(
            self.quest in possibly_completed_quests(self.user), "User should be able to complete this quest."
        )
Example #7
0
 def testAddCommitment(self):
   """
   Test that the user can add a commitment.
   """
   commitment = Commitment(
       title="Test commitment",
       description="A commitment!",
       point_value=10,
       type="commitment",
   )
   commitment.save()
   
   response = self.client.post(reverse("activity_add_task", args=(commitment.id,)), follow=True)
   self.failUnlessEqual(response.status_code, 200)
   
Example #8
0
 def testHasCommitment(self):
   """Tests that has_task 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 = "has_task(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 = CommitmentMember(user=self.user, commitment=commitment)
   member.save()
   self.assertTrue(has_task(self.user, slug='test-commitment'), "User should have a commitment in progress.")
   self.assertTrue(has_task(self.user, task_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 = "has_task(task_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(has_task(self.user, slug='test-commitment'), "User should have a completed commitment.")
   self.assertTrue(has_task(self.user, task_type="commitment"), "User should have a completed commitment.")
   
   # Test as a completion condition
   self.quest.accept(self.user)
   self.quest.completion_conditions = "not has_task(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 has_task(task_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 = "has_task(slug='test-commitment')"
   self.quest.save()
   self.assertTrue(self.quest in possibly_completed_quests(self.user), "User should be able to complete this quest.")
Example #9
0
 def testIndexMostPopular(self):
   posts = self.floor.post_set.count()
   commitment = Commitment(
               type="commitment",
               title="Test commitment",
               description="A commitment!",
               point_value=10,
   )
   commitment.save()
   
   member = CommitmentMember(commitment=commitment, user=self.user, 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.floor.post_set.count(), "Two posts should have been posted to the wall (commit and award).")
   self.assertContains(response, commitment.title, 3, 
       msg_prefix="""
       Commitment title should appear in the wall twice and in the most popular box. Note, may fail because of caching.
       """
   )
Example #10
0
 def testIndexCommitment(self):
   """Tests that a commitment shows up in public commitments and in the wall."""
   posts = self.floor.post_set.count()
   # Create a commitment that will appear on the news page.
   commitment = Commitment(
               type="commitment",
               title="Test commitment",
               description="A commitment!",
               point_value=10,
   )
   commitment.save()
   
   member = CommitmentMember(commitment=commitment, user=self.user)
   member.save()
   
   response = self.client.get(reverse("news_index"))
   self.failUnlessEqual(response.status_code, 200)
   self.assertEqual(posts + 1, self.floor.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."
   )
Example #11
0
    def testIndexMostPopular(self):
        posts = self.floor.post_set.count()
        commitment = Commitment(type="commitment", title="Test commitment", description="A commitment!", point_value=10)
        commitment.save()

        member = CommitmentMember(commitment=commitment, user=self.user, 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.floor.post_set.count(), "Two posts should have been posted to the wall (commit and award)."
        )
        self.assertContains(
            response,
            commitment.title,
            3,
            msg_prefix="""
        Commitment title should appear in the wall twice and in the most popular box. Note, may fail because of caching.
        """,
        )
Example #12
0
    def testIndexCommitment(self):
        """Tests that a commitment shows up in public commitments and in the wall."""
        posts = self.floor.post_set.count()
        # Create a commitment that will appear on the news page.
        commitment = Commitment(type="commitment", title="Test commitment", description="A commitment!", point_value=10)
        commitment.save()

        member = CommitmentMember(commitment=commitment, user=self.user)
        member.save()

        response = self.client.get(reverse("news_index"))
        self.failUnlessEqual(response.status_code, 200)
        self.assertEqual(
            posts + 1, self.floor.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.",
        )