Beispiel #1
0
 def testRevertToGrid(self):
     """Tests reverting the DesignerGrid to the SmartGrid using the url interface."""
     # set up really fake designer grid
     self.client.get(reverse('instantiate_action', \
                             args=(self.action_slug,
                                   self.level_slug,
                                   2,
                                   2,
                                   self.draft_slug)))
     # set up fake smartgrid
     level = Level(name='Foo', slug='foo', priority=1)
     level.save()
     action = Activity(name='Test', slug='test', title='test title', description='description', \
                       type='activity', expected_duration=2)
     action.save()
     column = ColumnName(name='Column', slug='column')
     column.save()
     loc = ColumnGrid(level=level, column=1, name=column)
     loc.save()
     loc = Grid(level=level, column=1, row=2, action=action)
     loc.save()
     response = self.client.post(reverse('revert_to_grid', args=(self.draft_slug, )), {}, \
                                 follow=True)
     self.failUnlessEqual(response.status_code, 200)
     draft = smartgrid_mgr.get_designer_draft(self.draft_slug)
     try:
         smartgrid_mgr.get_designer_action(draft, self.action_slug)
         self.fail("Old Action should be deleted")
     except Http404:
         pass
     try:
         level = smartgrid_mgr.get_designer_level(draft, slug='foo')
     except Http404:
         self.fail("Didn't copy Level Foo to designer.")
     try:
         action = smartgrid_mgr.get_designer_action(draft, slug='test')
     except Http404:
         self.fail("Didn't copy action Test to designer.")
     try:
         column = smartgrid_mgr.get_designer_column_name(draft, slug='column')
     except Http404:
         self.fail("Didn't copy the ColumnName to designer.")
     qs = DesignerColumnGrid.objects.filter(name=column)
     self.failUnlessEqual(len(qs), 1, "Column is not in Designer Grid")
     loc = qs[0]
     self.failUnlessEqual(loc.level, level, "Wrong level in Designer Grid")
     self.failUnlessEqual(loc.column, 1, "Wrong column in Designer Grid")
     self.failUnlessEqual(loc.name, column, "Wrong column name in Designer Grid")
     qs = DesignerGrid.objects.filter(action=action)
     self.failUnlessEqual(len(qs), 1, "Action is not in Designer Grid")
     loc = qs[0]
     self.failUnlessEqual(loc.level, level, "Wrong level in Designer Grid")
     self.failUnlessEqual(loc.column, 1, "Wrong column in Designer Grid")
     self.failUnlessEqual(loc.row, 2, "Wrong row in Designer Grid")
Beispiel #2
0
def instantiate_smartgrid_column_from_designer(des_col):
    """Creates a Smart Grid ColumnName from the DesignerColumnName."""
    col = None
    try:
        col = get_smartgrid_column_name(des_col.slug)
    except Http404:
        col = ColumnName()
    _copy_fields(des_col, col)
    return col
    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 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.")