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_of(self.user, 1), "User with commitment in progress should not have completed a task." ) # Test as an unlock condition self.quest.unlock_conditions = "approved_some_of(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_of(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 = "approved_some_of(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_of(1)" self.quest.save() self.assertTrue(self.quest in possibly_completed_quests(self.user), "User should be able to complete this quest.")
def testCompletedActivity(self): """Tests that approved_action works when a task is completed.""" activity = Activity( type="activity", name="Test", title="Test activity", slug="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 = "approved_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="approved") member.save() self.assertTrue(approved_action(self.user, slug="test-activity"), "User should have completed 'Test'.") self.assertTrue(approved_some_of(self.user, action_type="activity"), "User should have completed an activity") 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(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.") # Test as a completion condition. self.quest.accept(self.user) self.quest.completion_conditions = "not approved_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 approved_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 = "approved_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.")
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_of(self.user, 1), "User with commitment in progress should not have completed a task.") # Test as an unlock condition self.quest.unlock_conditions = "approved_some_of(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_of(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 = "approved_some_of(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_of(1)" self.quest.save() self.assertTrue(self.quest in possibly_completed_quests(self.user), "User should be able to complete this quest.")
def testNumTasksCompletedWithType(self): """test task completed.""" activity = Activity( type="activity", name="Test", slug="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 = ActionMember(user=self.user, action=activity, approval_status="pending") member.save() self.assertFalse( approved_some_of(self.user, 1, action_type="activity"), "User with pending activity should not have completed a task.") # Test within context of a quest self.quest.unlock_conditions = "approved_some_of(1, action_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 = "approved_some_of(2, 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 = "approved_some_of(1, action_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.")
def testNumTasksCompletedWithType(self): """test task completed.""" 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() # Test activities member = ActionMember(user=self.user, action=activity, approval_status="pending") member.save() self.assertFalse(approved_some_of(self.user, 1, action_type="activity"), "User with pending activity should not have completed a task.") # Test within context of a quest self.quest.unlock_conditions = "approved_some_of(1, action_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 = "approved_some_of(2, 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 = "approved_some_of(1, action_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.")
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(self.user, 1, category_slug=column.slug), "User with pending activity should not have completed a task.") self.assertFalse(approved_some_of(self.user, 1), "User with pending activity should not have completed a task.") # Test within context of a quest self.quest.unlock_conditions = "approved_some_of(1, category_slug='test-column')" 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_of(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(1, category_slug='test-column')" 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(2, category_slug='test-column')" 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(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(1, category_slug='test-column')" self.quest.save() completed_quests = possibly_completed_quests(self.user) self.assertTrue(self.quest in completed_quests, "User should have completed the quest.")
def testCompletedActivity(self): """Tests that approved_action works when a task is completed.""" activity = Activity( type="activity", name="Test", title="Test activity", slug="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 = "approved_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="approved") member.save() self.assertTrue(approved_action(self.user, slug="test-activity"), "User should have completed 'Test'.") self.assertTrue(approved_some_of(self.user, action_type="activity"), "User should have completed an activity") 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(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.") # Test as a completion condition. self.quest.accept(self.user) self.quest.completion_conditions = "not approved_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 approved_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 = "approved_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.")