Beispiel #1
0
 def test_from_xml_render(self):
     descriptor = NonStaffErrorDescriptor.from_xml(
         self.valid_xml, self.system,
         CourseLocationGenerator(self.org, self.course))
     descriptor.xmodule_runtime = self.system
     context_repr = self.system.render(descriptor, 'student_view').content
     self.assertNotIn(self.error_msg, context_repr)
     self.assertNotIn(repr(self.valid_xml), context_repr)
Beispiel #2
0
 def process_xml(self, xml):  # pylint: disable=method-hidden
     """Parse `xml` as an XBlock, and add it to `self._descriptors`"""
     descriptor = create_block_from_xml(
         xml,
         self,
         CourseLocationGenerator(self.org, self.course),
     )
     self._descriptors[descriptor.location.url()] = descriptor
     return descriptor
Beispiel #3
0
 def test_error_module_xml_rendering(self):
     descriptor = ErrorDescriptor.from_xml(
         self.valid_xml, self.system,
         CourseLocationGenerator(self.org, self.course), self.error_msg)
     self.assertIsInstance(descriptor, ErrorDescriptor)
     descriptor.xmodule_runtime = self.system
     context_repr = self.system.render(descriptor, 'student_view').content
     self.assertIn(self.error_msg, context_repr)
     self.assertIn(repr(self.valid_xml), context_repr)
Beispiel #4
0
    def create(system, source_is_error_module=False):
        """
        return a dict of modules: the conditional with a single source and a single child.
        Keys are 'cond_module', 'source_module', and 'child_module'.

        if the source_is_error_module flag is set, create a real ErrorModule for the source.
        """
        descriptor_system = get_test_descriptor_system()

        # construct source descriptor and module:
        source_location = Location(
            ["i4x", "edX", "conditional_test", "problem", "SampleProblem"])
        if source_is_error_module:
            # Make an error descriptor and module
            source_descriptor = NonStaffErrorDescriptor.from_xml(
                'some random xml data',
                system,
                id_generator=CourseLocationGenerator(source_location.org,
                                                     source_location.course),
                error_msg='random error message')
        else:
            source_descriptor = Mock()
            source_descriptor.location = source_location

        source_descriptor.runtime = descriptor_system
        source_descriptor.render = lambda view, context=None: descriptor_system.render(
            source_descriptor, view, context)

        # construct other descriptors:
        child_descriptor = Mock()
        child_descriptor._xmodule.student_view.return_value.content = u'<p>This is a secret</p>'
        child_descriptor.student_view = child_descriptor._xmodule.student_view
        child_descriptor.displayable_items.return_value = [child_descriptor]
        child_descriptor.runtime = descriptor_system
        child_descriptor.xmodule_runtime = get_test_system()
        child_descriptor.render = lambda view, context=None: descriptor_system.render(
            child_descriptor, view, context)

        descriptor_system.load_item = {
            'child': child_descriptor,
            'source': source_descriptor
        }.get

        # construct conditional module:
        cond_location = Location([
            "i4x", "edX", "conditional_test", "conditional",
            "SampleConditional"
        ])
        field_data = DictFieldData({
            'data': '<conditional/>',
            'xml_attributes': {
                'attempted': 'true'
            },
            'children': ['child'],
        })

        cond_descriptor = ConditionalDescriptor(
            descriptor_system, field_data,
            ScopeIds(None, None, cond_location, cond_location))
        cond_descriptor.xmodule_runtime = system
        system.get_module = lambda desc: desc
        cond_descriptor.get_required_module_descriptors = Mock(
            return_value=[source_descriptor])

        # return dict:
        return {
            'cond_module': cond_descriptor,
            'source_module': source_descriptor,
            'child_module': child_descriptor
        }
Beispiel #5
0
 def test_non_staff_error_module_create(self):
     descriptor = NonStaffErrorDescriptor.from_xml(
         self.valid_xml, self.system,
         CourseLocationGenerator(self.org, self.course))
     self.assertIsInstance(descriptor, NonStaffErrorDescriptor)