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 = "submitted_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(submitted_action(self.user, slug='test-commitment'),
            "User should have a commitment in progress.")
        self.assertTrue(submitted_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 = "submitted_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(submitted_action(self.user, slug='test-commitment'),
            "User should have a completed commitment.")
        self.assertTrue(submitted_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 submitted_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 submitted_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 = "submitted_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 testAction(self):
     """Tests submitted_action and approved_action predicates."""
     self.assertFalse(submitted_some(self.user, count=1), "Haven't submitted any yet")
     action_member = ActionMember(user=self.user, action=self.activity)
     action_member.save()
     self.assertTrue(submitted_some(self.user, count=1), "Have submitted one.")
     self.assertTrue(submitted_action(self.user, self.activity.slug),
                     "submitted_action should be true")
     self.assertFalse(approved_action(self.user, self.activity.slug),
                      "approved_action should be false")
     self.assertFalse(approved_some(self.user, count=1), "Haven't had it approved yet.")
     action_member.approval_status = 'approved'
     action_member.save()
     self.assertTrue(approved_action(self.user, self.activity.slug),
                     "approved_action should be true")
     self.assertTrue(approved_some(self.user, count=1), "Have had one approved.")
예제 #3
0
 def testAction(self):
     """Tests submitted_action and approved_action predicates."""
     self.assertFalse(submitted_some(self.user, count=1),
                      "Haven't submitted any yet")
     action_member = ActionMember(user=self.user, action=self.activity)
     action_member.save()
     self.assertTrue(submitted_some(self.user, count=1),
                     "Have submitted one.")
     self.assertTrue(submitted_action(self.user, self.activity.slug),
                     "submitted_action should be true")
     self.assertFalse(approved_action(self.user, self.activity.slug),
                      "approved_action should be false")
     self.assertFalse(approved_some(self.user, count=1),
                      "Haven't had it approved yet.")
     action_member.approval_status = 'approved'
     action_member.save()
     self.assertTrue(approved_action(self.user, self.activity.slug),
                     "approved_action should be true")
     self.assertTrue(approved_some(self.user, count=1),
                     "Have had one approved.")
    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!",
            expected_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 = "submitted_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(submitted_action(self.user, slug="test-activity"),
            "User should have a pending task.")
        self.assertTrue(submitted_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 = "submitted_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(submitted_action(self.user, slug='test-activity'),
            "User should have a completed task.")
        self.assertTrue(submitted_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 submitted_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 submitted_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 = "submitted_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.")
예제 #5
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 = "submitted_action(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(
            submitted_action(self.user, action_slug='test-commitment'),
            "User should have a commitment in progress.")
        self.assertTrue(
            submitted_some_of_type(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 = "submitted_some_of_type(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(
            submitted_action(self.user, action_slug='test-commitment'),
            "User should have a completed commitment.")
        self.assertTrue(
            submitted_some_of_type(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 submitted_action(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 submitted_some_of_type(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 = "submitted_action(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.")
예제 #6
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!",
            expected_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 = "submitted_action(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(
            submitted_action(self.user, action_slug="test-activity"),
            "User should have a pending task.")
        self.assertTrue(
            submitted_some_of_type(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 = "submitted_some_of_type(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(
            submitted_action(self.user, action_slug='test-activity'),
            "User should have a completed task.")
        self.assertTrue(
            submitted_some_of_type(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 submitted_action(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 submitted_some_of_type(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 = "submitted_action(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.")