Пример #1
0
    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.")
Пример #2
0
    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.")
Пример #3
0
    def testHasActivity(self):
        """Test that completing an activity works with has_action."""
        activity = Activity(
            type="activity",
            name="Test",
            slug="test-activity",
            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 within context of a quest
        self.quest.unlock_conditions = "completed_action(slug='test-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.")

        member = ActionMember(user=self.user, action=activity, approval_status="pending")
        member.save()
        self.assertTrue(completed_action(self.user, slug="test-activity"),
            "User should have a pending task.")
        self.assertTrue(completed_some_of(self.user, action_type="activity"),
            "User should have a pending task.")

        quests = get_quests(self.user)
        self.assertTrue(self.quest in quests["available_quests"],
            "User should be able to participate in this quest.")

        self.quest.unlock_conditions = "completed_some_of(action_type='activity')"
        self.quest.save()
        quests = get_quests(self.user)
        self.assertTrue(self.quest in quests["available_quests"],
            "User should be able to participate in this quest.")

        member.approval_status = "approved"
        member.save()
        self.assertTrue(completed_action(self.user, slug='test-activity'),
            "User should have a completed task.")
        self.assertTrue(completed_some_of(self.user, action_type="activity"),
            "User should have a completed task.")

        # Test as a completion condition.
        self.quest.accept(self.user)
        self.quest.completion_conditions = "not completed_action(slug='test-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 = "not completed_some_of(action_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 = "completed_action(slug='test-activity')"
        self.quest.save()
        completed_quests = possibly_completed_quests(self.user)
        self.assertTrue(self.quest in completed_quests, "User should have completed the quest.")
Пример #4
0
    def testHasActivity(self):
        """Test that completing an activity works with has_action."""
        activity = Activity(
            type="activity",
            name="Test",
            slug="test-activity",
            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 within context of a quest
        self.quest.unlock_conditions = "completed_action(slug='test-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.")

        member = ActionMember(user=self.user,
                              action=activity,
                              approval_status="pending")
        member.save()
        self.assertTrue(completed_action(self.user, slug="test-activity"),
                        "User should have a pending task.")
        self.assertTrue(completed_some_of(self.user, action_type="activity"),
                        "User should have a pending task.")

        quests = get_quests(self.user)
        self.assertTrue(self.quest in quests["available_quests"],
                        "User should be able to participate in this quest.")

        self.quest.unlock_conditions = "completed_some_of(action_type='activity')"
        self.quest.save()
        quests = get_quests(self.user)
        self.assertTrue(self.quest in quests["available_quests"],
                        "User should be able to participate in this quest.")

        member.approval_status = "approved"
        member.save()
        self.assertTrue(completed_action(self.user, slug='test-activity'),
                        "User should have a completed task.")
        self.assertTrue(completed_some_of(self.user, action_type="activity"),
                        "User should have a completed task.")

        # Test as a completion condition.
        self.quest.accept(self.user)
        self.quest.completion_conditions = "not completed_action(slug='test-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 = "not completed_some_of(action_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 = "completed_action(slug='test-activity')"
        self.quest.save()
        completed_quests = possibly_completed_quests(self.user)
        self.assertTrue(self.quest in completed_quests,
                        "User should have completed the quest.")