Ejemplo n.º 1
0
    def test_child_isinstance_descendants(self):
        """
        Check that child_isinstance() works on deeper descendants
        """
        root = self.runtime.get_block(self.root_id)
        block = root.runtime.get_block(root.children[0])
        self.assertIsInstance(block, BasicXBlock)

        self.assertFalse(child_isinstance(root, block.children[0], DogXBlock))
        self.assertTrue(child_isinstance(root, block.children[0], CatXBlock))

        self.assertTrue(child_isinstance(root, block.children[1], DogXBlock))
        self.assertTrue(child_isinstance(root, block.children[1], GoldenRetrieverXBlock))
        self.assertFalse(child_isinstance(root, block.children[1], CatXBlock))
Ejemplo n.º 2
0
    def test_child_isinstance_descendants(self):
        """
        Check that child_isinstance() works on deeper descendants
        """
        root = self.runtime.get_block(self.root_id)
        block = root.runtime.get_block(root.children[0])
        self.assertIsInstance(block, BasicXBlock)

        self.assertFalse(child_isinstance(root, block.children[0], DogXBlock))
        self.assertTrue(child_isinstance(root, block.children[0], CatXBlock))

        self.assertTrue(child_isinstance(root, block.children[1], DogXBlock))
        self.assertTrue(
            child_isinstance(root, block.children[1], GoldenRetrieverXBlock))
        self.assertFalse(child_isinstance(root, block.children[1], CatXBlock))
 def get_review_tip(self):
     """ Get the text to show on the assessment review when the student gets this question wrong """
     for child_id in self.children:
         if child_isinstance(self, child_id, MentoringMessageBlock):
             child = self.runtime.get_block(child_id)
             if child.type == "on-assessment-review-question":
                 return child.content
Ejemplo n.º 4
0
 def step_ids(self):
     """
     Get the usage_ids of all of this XBlock's children that are "Steps"
     """
     return [
         _normalize_id(child_id) for child_id in self.children if child_isinstance(self, child_id, QuestionMixin)
     ]
Ejemplo n.º 5
0
 def get_review_tip(self):
     """ Get the text to show on the assessment review when the student gets this question wrong """
     for child_id in self.children:
         if child_isinstance(self, child_id, MentoringMessageBlock):
             child = self.runtime.get_block(child_id)
             if child.type == "on-assessment-review-question":
                 return child.content
Ejemplo n.º 6
0
    def test_child_isinstance_descendants(self):
        """
        Check that child_isinstance() works on deeper descendants
        """
        self.runtime = WorkbenchRuntime()
        self.root_id = self.runtime.parse_xml_string('<block> <block><cat/><gr/></block> <cat/> <gr/> </block>')
        root = self.runtime.get_block(self.root_id)
        block = root.runtime.get_block(root.children[0])
        self.assertIsInstance(block, BasicXBlock)

        self.assertFalse(child_isinstance(root, block.children[0], DogXBlock))
        self.assertTrue(child_isinstance(root, block.children[0], CatXBlock))

        self.assertTrue(child_isinstance(root, block.children[1], DogXBlock))
        self.assertTrue(child_isinstance(root, block.children[1], GoldenRetrieverXBlock))
        self.assertFalse(child_isinstance(root, block.children[1], CatXBlock))
Ejemplo n.º 7
0
 def step_ids(self):
     """
     Get the usage_ids of all of this XBlock's children that are "Steps"
     """
     return [
         _normalize_id(child_id) for child_id in self.children if child_isinstance(self, child_id, QuestionMixin)
     ]
Ejemplo n.º 8
0
 def overlay_ids(self):
     """
     Get the usage_ids of all of this XBlock's children that are overlays.
     """
     return [
         _normalize_id(child_id) for child_id in self.children
         if child_isinstance(self, child_id, PlotOverlayBlock)
     ]
Ejemplo n.º 9
0
 def overlay_ids(self):
     """
     Get the usage_ids of all of this XBlock's children that are overlays.
     """
     return [
         _normalize_id(child_id) for child_id in self.children if
         child_isinstance(self, child_id, PlotOverlayBlock)
     ]
Ejemplo n.º 10
0
 def get_tips(self):
     """
     Returns the tips contained in this block
     """
     tips = []
     for child_id in self.children:
         if child_isinstance(self, child_id, TipBlock):
             tips.append(self.runtime.get_block(child_id))
     return tips
Ejemplo n.º 11
0
    def test_child_isinstance_descendants(self):
        """
        Check that child_isinstance() works on deeper descendants
        """
        self.runtime = WorkbenchRuntime()
        self.root_id = self.runtime.parse_xml_string(
            '<block> <block><cat/><gr/></block> <cat/> <gr/> </block>')
        root = self.runtime.get_block(self.root_id)
        block = root.runtime.get_block(root.children[0])
        self.assertIsInstance(block, BasicXBlock)

        self.assertFalse(child_isinstance(root, block.children[0], DogXBlock))
        self.assertTrue(child_isinstance(root, block.children[0], CatXBlock))

        self.assertTrue(child_isinstance(root, block.children[1], DogXBlock))
        self.assertTrue(
            child_isinstance(root, block.children[1], GoldenRetrieverXBlock))
        self.assertFalse(child_isinstance(root, block.children[1], CatXBlock))
Ejemplo n.º 12
0
 def step_ids(self):
     """
     Get the usage_ids of all of this XBlock's children that are steps.
     """
     from .step import MentoringStepBlock  # Import here to avoid circular dependency
     return [
         _normalize_id(child_id) for child_id in self.children if
         child_isinstance(self, child_id, MentoringStepBlock)
     ]
Ejemplo n.º 13
0
 def step_ids(self):
     """
     Get the usage_ids of all of this XBlock's children that are steps.
     """
     from .step import MentoringStepBlock  # Import here to avoid circular dependency
     return [
         _normalize_id(child_id) for child_id in self.children
         if child_isinstance(self, child_id, MentoringStepBlock)
     ]
 def get_tips(self):
     """
     Returns the tips contained in this block
     """
     tips = []
     for child_id in self.children:
         if child_isinstance(self, child_id, TipBlock):
             tips.append(self.runtime.get_block(child_id))
     return tips
Ejemplo n.º 15
0
    def test_child_isinstance(self):
        """
        Check that child_isinstance() works on direct children
        """
        root = self.runtime.get_block(self.root_id)
        self.assertFalse(child_isinstance(root, root.children[0], DogXBlock))
        self.assertFalse(child_isinstance(root, root.children[0], GoldenRetrieverXBlock))
        self.assertTrue(child_isinstance(root, root.children[0], BasicXBlock))

        self.assertFalse(child_isinstance(root, root.children[1], DogXBlock))
        self.assertFalse(child_isinstance(root, root.children[1], GoldenRetrieverXBlock))
        self.assertTrue(child_isinstance(root, root.children[1], CatXBlock))

        self.assertFalse(child_isinstance(root, root.children[2], CatXBlock))
        self.assertTrue(child_isinstance(root, root.children[2], DogXBlock))
        self.assertTrue(child_isinstance(root, root.children[2], GoldenRetrieverXBlock))
Ejemplo n.º 16
0
    def test_child_isinstance(self):
        """
        Check that child_isinstance() works on direct children
        """
        self.runtime = WorkbenchRuntime()
        self.root_id = self.runtime.parse_xml_string('<block> <block><cat/><gr/></block> <cat/> <gr/> </block>')
        root = self.runtime.get_block(self.root_id)
        self.assertFalse(child_isinstance(root, root.children[0], DogXBlock))
        self.assertFalse(child_isinstance(root, root.children[0], GoldenRetrieverXBlock))
        self.assertTrue(child_isinstance(root, root.children[0], BasicXBlock))

        self.assertFalse(child_isinstance(root, root.children[1], DogXBlock))
        self.assertFalse(child_isinstance(root, root.children[1], GoldenRetrieverXBlock))
        self.assertTrue(child_isinstance(root, root.children[1], CatXBlock))

        self.assertFalse(child_isinstance(root, root.children[2], CatXBlock))
        self.assertTrue(child_isinstance(root, root.children[2], DogXBlock))
        self.assertTrue(child_isinstance(root, root.children[2], GoldenRetrieverXBlock))
Ejemplo n.º 17
0
    def test_child_isinstance(self):
        """
        Check that child_isinstance() works on direct children
        """
        root = self.runtime.get_block(self.root_id)
        self.assertFalse(child_isinstance(root, root.children[0], DogXBlock))
        self.assertFalse(
            child_isinstance(root, root.children[0], GoldenRetrieverXBlock))
        self.assertTrue(child_isinstance(root, root.children[0], BasicXBlock))

        self.assertFalse(child_isinstance(root, root.children[1], DogXBlock))
        self.assertFalse(
            child_isinstance(root, root.children[1], GoldenRetrieverXBlock))
        self.assertTrue(child_isinstance(root, root.children[1], CatXBlock))

        self.assertFalse(child_isinstance(root, root.children[2], CatXBlock))
        self.assertTrue(child_isinstance(root, root.children[2], DogXBlock))
        self.assertTrue(
            child_isinstance(root, root.children[2], GoldenRetrieverXBlock))
Ejemplo n.º 18
0
 def get_message_content(self, message_type, or_default=False):
     from problem_builder.message import MentoringMessageBlock  # Import here to avoid circular dependency
     for child_id in self.children:
         if child_isinstance(self, child_id, MentoringMessageBlock):
             child = self.runtime.get_block(child_id)
             if child.type == message_type:
                 content = child.content
                 if hasattr(self.runtime, 'replace_jump_to_id_urls'):
                     content = self.runtime.replace_jump_to_id_urls(content)
                 return content
     if or_default:
         # Return the default value since no custom message is set.
         # Note the WYSIWYG editor usually wraps the .content HTML in a <p> tag so we do the same here.
         return '<p>{}</p>'.format(MentoringMessageBlock.MESSAGE_TYPES[message_type]['default'])
Ejemplo n.º 19
0
 def get_message_content(self, message_type, or_default=False):
     from problem_builder.message import MentoringMessageBlock  # Import here to avoid circular dependency
     for child_id in self.children:
         if child_isinstance(self, child_id, MentoringMessageBlock):
             child = self.runtime.get_block(child_id)
             if child.type == message_type:
                 content = child.content
                 if getattr(self.runtime, 'replace_jump_to_id_urls', None) is not None:
                     content = self.runtime.replace_jump_to_id_urls(content)
                 return content
     if or_default:
         # Return the default value since no custom message is set.
         # Note the WYSIWYG editor usually wraps the .content HTML in a <p> tag so we do the same here.
         return '<p>{}</p>'.format(MentoringMessageBlock.MESSAGE_TYPES[message_type]['default'])
Ejemplo n.º 20
0
    def test_child_isinstance(self):
        """
        Check that child_isinstance() works on direct children
        """
        self.runtime = WorkbenchRuntime()
        self.root_id = self.runtime.parse_xml_string(
            '<block> <block><cat/><gr/></block> <cat/> <gr/> </block>')
        root = self.runtime.get_block(self.root_id)
        self.assertFalse(child_isinstance(root, root.children[0], DogXBlock))
        self.assertFalse(
            child_isinstance(root, root.children[0], GoldenRetrieverXBlock))
        self.assertTrue(child_isinstance(root, root.children[0], BasicXBlock))

        self.assertFalse(child_isinstance(root, root.children[1], DogXBlock))
        self.assertFalse(
            child_isinstance(root, root.children[1], GoldenRetrieverXBlock))
        self.assertTrue(child_isinstance(root, root.children[1], CatXBlock))

        self.assertFalse(child_isinstance(root, root.children[2], CatXBlock))
        self.assertTrue(child_isinstance(root, root.children[2], DogXBlock))
        self.assertTrue(
            child_isinstance(root, root.children[2], GoldenRetrieverXBlock))
Ejemplo n.º 21
0
 def _get_problem_questions(self, mentoring_block):
     """ Generator returning only children of specified block that are MCQs """
     for child_id in mentoring_block.children:
         if child_isinstance(mentoring_block, child_id, MCQBlock):
             yield child_id
Ejemplo n.º 22
0
 def review_step(self):
     """ Get the Review Step XBlock child, if any. Otherwise returns None """
     for step_id in self.children:
         if child_isinstance(self, step_id, ReviewStepBlock):
             return self.runtime.get_block(step_id)
Ejemplo n.º 23
0
 def review_step(self):
     """ Get the Review Step XBlock child, if any. Otherwise returns None """
     for step_id in self.children:
         if child_isinstance(self, step_id, ReviewStepBlock):
             return self.runtime.get_block(step_id)
Ejemplo n.º 24
0
 def has_review_step(self):
     return any(
         child_isinstance(self, child_id, ReviewStepBlock)
         for child_id in self.children)
Ejemplo n.º 25
0
 def custom_choices(self):
     custom_choices = []
     for child_id in self.children:
         if child_isinstance(self, child_id, ChoiceBlock):
             custom_choices.append(self.runtime.get_block(child_id))
     return custom_choices
 def custom_choices(self):
     custom_choices = []
     for child_id in self.children:
         if child_isinstance(self, child_id, ChoiceBlock):
             custom_choices.append(self.runtime.get_block(child_id))
     return custom_choices
Ejemplo n.º 27
0
 def has_review_step(self):
     from .step import ReviewStepBlock
     return any(child_isinstance(self, child_id, ReviewStepBlock) for child_id in self.children)
 def _get_problem_questions(self, mentoring_block):
     """ Generator returning only children of specified block that are MCQs """
     for child_id in mentoring_block.children:
         if child_isinstance(mentoring_block, child_id, MCQBlock):
             yield child_id