Exemple #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")
Exemple #2
0
def deploy_designer_to_smartgrid(draft, use_filler):  # pylint: disable=R0914
    """Clears the current Smart Grid Game and copies the designer instances to the
    Smart Grid Game. Clearing the grid does not delete the actions just clears their
    Levels and Categories."""
    clear_smartgrid()
    # deploy the Levels
    for level in DesignerLevel.objects.filter(draft=draft):
        instantiate_smartgrid_level_from_designer(level)
    # deploy the ColumnNames
    for col in DesignerColumnName.objects.filter(draft=draft):
        instantiate_smartgrid_column_from_designer(col)
    # deploy the actions
    for action in DesignerAction.objects.filter(draft=draft):
        instantiate_smartgrid_action_from_designer(draft, action.slug)
    # set the ColumnGrid objects.
    for des_col in DesignerColumnGrid.objects.filter(draft=draft):
        col = ColumnGrid()
        col.column = des_col.column
        col.level = get_smartgrid_level(des_col.level.slug)
        col.name = get_smartgrid_column_name(des_col.name.slug)
        col.save()
    # set the Grid objects.
    for des_row in DesignerGrid.objects.filter(draft=draft):
        row = Grid()
        row.row = des_row.row
        row.column = des_row.column
        row.level = get_smartgrid_level(des_row.level.slug)
        row.action = get_smartgrid_action(des_row.action.slug)
        row.save()
    if use_filler:
        # need to instantiate the filler objects and put them in the grid.
        filler_count = len(Filler.objects.all())
        sizes = get_smart_grid_size()
        for slug in list(sizes):
            level = Level.objects.get(slug=slug)
            for c in range(1, sizes[slug][0] + 1):
                for r in range(1, sizes[slug][1] + 1):
                    cell = Grid.objects.filter(level=level, column=c, row=r)
                    if not cell:
                        filler_count += 1
                        name = 'Filler %s' % filler_count
                        filler_slug = 'filler-%s' % filler_count
                        filler = Filler(name=name, slug=filler_slug, type='filler', title=name)
                        filler.save()
                        grid = Grid(level=level, column=c, row=r, action=filler)
                        grid.save()  # pylint: enable=R0914
    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.")