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 testNumTasksCompletedWithType(self):
        activity = Activity(
            type="activity",
            name="Test",
            title="Test activity",
            description="Variable points!",
            duration=10,
            point_value=10,
            pub_date=datetime.datetime.today(),
            expire_date=datetime.datetime.today() + datetime.timedelta(days=7),
            confirm_type="text",
        )
        activity.save()

        # Test activities
        member = ActivityMember(user=self.user, activity=activity, approval_status="pending")
        member.save()
        self.assertFalse(
            num_tasks_completed(self.user, 1, task_type="activity"),
            "User with pending activity should not have completed a task.",
        )

        # Test within context of a quest
        self.quest.unlock_conditions = "num_tasks_completed(1, task_type='activity')"
        self.quest.save()
        quests = get_quests(self.user)
        self.assertTrue(self.quest not in quests, "User should not be able to participate in this quest.")

        # Check that the user can now add the quest.
        member.approval_status = "approved"
        member.save()
        quests = get_quests(self.user)
        self.assertTrue(self.quest in quests["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, task_type='activity')"
        self.quest.save()
        completed_quests = possibly_completed_quests(self.user)
        self.assertTrue(self.quest not in completed_quests, "User should not be able to complete the quest.")

        self.quest.completion_conditions = "num_tasks_completed(1, task_type='activity')"
        self.quest.save()
        completed_quests = possibly_completed_quests(self.user)
        self.assertTrue(self.quest in completed_quests, "User should have completed the quest.")