コード例 #1
0
ファイル: predicate_tests.py プロジェクト: csdl/makahiki
 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.")
コード例 #2
0
    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.")
コード例 #3
0
    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.")
コード例 #4
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.")
コード例 #5
0
    def testNumTasksCompleted(self):
        """Test that completing an activity works with approved_some_of and has_action."""
        # put the grid together. First the ColumnName
        level = Level(name="Test level", slug="test-level")
        level.save()
        column = ColumnName(name="Test column", slug="test-column")
        column.save()
        c_grid = ColumnGrid(level=level, column=1, name=column)
        c_grid.save()
        # Then the activity
        activity = Activity(
            type="activity",
            name="Test",
            slug="test",
            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()
        grid = Grid(level=level, column=1, row=1, action=activity)
        grid.save()

        # Test activities
        member = ActionMember(user=self.user,
                              action=activity,
                              approval_status="pending")
        member.save()
        self.assertFalse(
            approved_some_of_type(self.user, action_type='activity', count=1),
            "User with pending activity should not have completed a task.")
        self.assertFalse(
            approved_some(self.user, count=1),
            "User with pending activity should not have completed a task.")

        # Test within context of a quest
        self.quest.unlock_conditions = "approved_some_of_type(action_type='activity', count=1)"
        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.")

        self.quest.unlock_conditions = "approved_some(count=1)"
        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.")

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

        # Test as a completion condition.
        self.quest.accept(self.user)
        self.quest.completion_conditions = "approved_some_of_type(action_type='activity', count=2)"
        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 = "approved_some(count=2)"
        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 = "approved_some_of_type(action_type='activity', count=1)"
        self.quest.save()
        completed_quests = possibly_completed_quests(self.user)
        self.assertTrue(self.quest in completed_quests,
                        "User should have completed the quest.")
コード例 #6
0
    def testNumTasksCompleted(self):
        """Test that completing an activity works with approved_some_of and has_action."""
        # put the grid together. First the ColumnName
        level = Level(name="Test level", slug="test-level")
        level.save()
        column = ColumnName(name="Test column", slug="test-column")
        column.save()
        c_grid = ColumnGrid(level=level, column=1, name=column)
        c_grid.save()
        # Then the activity
        activity = Activity(
            type="activity",
            name="Test",
            slug="test",
            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()
        grid = Grid(level=level, column=1, row=1, action=activity)
        grid.save()

        # Test activities
        member = ActionMember(user=self.user, action=activity, approval_status="pending")
        member.save()
        self.assertFalse(approved_some_of_type(self.user, action_type='activity', count=1),
            "User with pending activity should not have completed a task.")
        self.assertFalse(approved_some(self.user, count=1),
            "User with pending activity should not have completed a task.")

        # Test within context of a quest
        self.quest.unlock_conditions = "approved_some_of_type(action_type='activity', count=1)"
        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.")

        self.quest.unlock_conditions = "approved_some(count=1)"
        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.")

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

        # Test as a completion condition.
        self.quest.accept(self.user)
        self.quest.completion_conditions = "approved_some_of_type(action_type='activity', count=2)"
        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 = "approved_some(count=2)"
        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 = "approved_some_of_type(action_type='activity', count=1)"
        self.quest.save()
        completed_quests = possibly_completed_quests(self.user)
        self.assertTrue(self.quest in completed_quests, "User should have completed the quest.")