def get_xml_editable_fields(self, field_data):
     runtime = get_test_descriptor_system()
     return runtime.construct_xblock_from_class(
         XmlDescriptor,
         scope_ids=Mock(),
         field_data=field_data,
     ).editable_metadata_fields
Example #2
0
 def setUp(self):
     system = get_test_descriptor_system()
     self.descriptor = system.construct_xblock_from_class(
         VideoDescriptor,
         field_data=DictFieldData({}),
         scope_ids=ScopeIds(None, None, None, None),
     )
    def setUp(self):
        super(TabsEditingDescriptorTestCase, self).setUp()
        system = get_test_descriptor_system()
        system.render_template = Mock(return_value="<div>Test Template HTML</div>")
        self.tabs = [
            {
                'name': "Test_css",
                'template': "tabs/codemirror-edit.html",
                'current': True,
                'css': {
                    'scss': [resource_string(__name__,
                    '../../test_files/test_tabseditingdescriptor.scss')],
                    'css': [resource_string(__name__,
                    '../../test_files/test_tabseditingdescriptor.css')]
                }
            },
            {
                'name': "Subtitles",
                'template': "video/subtitles.html",
            },
            {
                'name': "Settings",
                'template': "tabs/video-metadata-edit-tab.html"
            }
        ]

        TabsEditingDescriptor.tabs = self.tabs
        self.descriptor = system.construct_xblock_from_class(
            TabsEditingDescriptor,
            field_data=DictFieldData({}),
            scope_ids=ScopeIds(None, None, None, None),
        )
 def leaf_descriptor(self, descriptor_cls):
     location = "i4x://org/course/category/name"
     runtime = get_test_descriptor_system()
     runtime.render_template = lambda *args, **kwargs: u"{!r}, {!r}".format(args, kwargs)
     return runtime.construct_xblock_from_class(
         descriptor_cls, ScopeIds(None, descriptor_cls.__name__, location, location), DictFieldData({})
     )
    def setUp(self):
        super(TabsEditingDescriptorTestCase, self).setUp()
        system = get_test_descriptor_system()
        system.render_template = Mock(return_value="<div>Test Template HTML</div>")
        self.tabs = [
            {
                'name': "Test_css",
                'template': "tabs/codemirror-edit.html",
                'current': True,
                'css': {
                    'scss': [resource_string(__name__,
                    '../../test_files/test_tabseditingdescriptor.scss')],
                    'css': [resource_string(__name__,
                    '../../test_files/test_tabseditingdescriptor.css')]
                }
            },
            {
                'name': "Subtitles",
                'template': "video/subtitles.html",
            },
            {
                'name': "Settings",
                'template': "tabs/video-metadata-edit-tab.html"
            }
        ]

        TabsEditingDescriptor.tabs = self.tabs
        self.descriptor = system.construct_xblock_from_class(
            TabsEditingDescriptor,
            scope_ids=ScopeIds(None, None, None, None),
            field_data=DictFieldData({}),
        )
Example #6
0
    def _create_peer_grading_descriptor_with_linked_problem(self):
        # Initialize the peer grading module.
        system = get_test_descriptor_system()

        return system.construct_xblock_from_class(PeerGradingDescriptor,
                                                  field_data=self.field_data,
                                                  scope_ids=self.scope_ids)
Example #7
0
 def setUp(self):
     system = get_test_descriptor_system()
     self.descriptor = system.construct_xblock_from_class(
         VideoDescriptor,
         field_data=DictFieldData({}),
         scope_ids=ScopeIds(None, None, None, None),
     )
    def _create_peer_grading_descriptor_with_linked_problem(self):
        # Initialize the peer grading module.
        system = get_test_descriptor_system()

        return system.construct_xblock_from_class(
            PeerGradingDescriptor, field_data=self.field_data, scope_ids=self.scope_ids
        )
Example #9
0
 def get_xml_editable_fields(self, field_data):
     runtime = get_test_descriptor_system()
     return runtime.construct_xblock_from_class(
         XmlDescriptor,
         scope_ids=Mock(),
         field_data=field_data,
     ).editable_metadata_fields
    def setUp(self):
        super().setUp()
        system = get_test_descriptor_system(render_template=Mock())
        self.tabs = [{
            'name': "Test_css",
            'template': "tabs/codemirror-edit.html",
            'current': True,
            'css': {
                'scss': [
                    resource_string(
                        __name__, 'test_files/test_tabseditingdescriptor.scss')
                ],
                'css': [
                    resource_string(
                        __name__, 'test_files/test_tabseditingdescriptor.css')
                ]
            }
        }, {
            'name': "Subtitles",
            'template': "video/subtitles.html",
        }, {
            'name': "Settings",
            'template': "tabs/video-metadata-edit-tab.html"
        }]

        TabsEditingDescriptor.tabs = self.tabs
        self.descriptor = system.construct_xblock_from_class(
            TabsEditingDescriptor,
            scope_ids=ScopeIds(
                None, None, None,
                BlockUsageLocator(
                    CourseLocator('org', 'course', 'run', branch='revision'),
                    'category', 'name')),
            field_data=DictFieldData({}),
        )
Example #11
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,
                org=source_location.org,
                course=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}
 def leaf_descriptor(self, descriptor_cls):
     location = 'i4x://org/course/category/name'
     runtime = get_test_descriptor_system()
     return runtime.construct_xblock_from_class(
         descriptor_cls,
         ScopeIds(None, descriptor_cls.__name__, location, location),
         DictFieldData({}),
     )
Example #13
0
 def setUp(self):
     system = get_test_descriptor_system()
     course_key = SlashSeparatedCourseKey("org", "course", "run")
     usage_key = course_key.make_usage_key("video", "name")
     self.descriptor = system.construct_xblock_from_class(
         VideoDescriptor, scope_ids=ScopeIds(None, None, usage_key, usage_key), field_data=DictFieldData({})
     )
     self.descriptor.runtime.handler_url = MagicMock()
Example #14
0
 def setUp(self):
     self.system = get_test_descriptor_system()
     self.all_blocks = {}
     self.system.get_block = self.all_blocks.get
     self.field_data = InheritingFieldData(
         inheritable_names=['inherited'],
         kvs=DictKeyValueStore({}),
     )
Example #15
0
 def leaf_descriptor(self, descriptor_cls):
     location = 'i4x://org/course/category/name'
     runtime = get_test_descriptor_system()
     runtime.render_template = lambda *args, **kwargs: u'{!r}, {!r}'.format(
         args, kwargs)
     return runtime.construct_xblock_from_class(
         descriptor_cls, DictFieldData({}),
         ScopeIds(None, descriptor_cls.__name__, location, location))
Example #16
0
 def setUp(self):
     system = get_test_descriptor_system()
     location = Location('i4x://org/course/video/name')
     self.descriptor = system.construct_xblock_from_class(
         VideoDescriptor,
         scope_ids=ScopeIds(None, None, location, location),
         field_data=DictFieldData({}),
     )
 def leaf_descriptor(self, descriptor_cls):
     location = Location('i4x://org/course/category/name')
     runtime = get_test_descriptor_system()
     return runtime.construct_xblock_from_class(
         descriptor_cls,
         ScopeIds(None, descriptor_cls.__name__, location, location),
         DictFieldData({}),
     )
Example #18
0
 def setUp(self):
     system = get_test_descriptor_system()
     location = Location('org', 'course', 'run', 'video', 'name', None)
     self.descriptor = system.construct_xblock_from_class(
         VideoDescriptor,
         scope_ids=ScopeIds(None, None, location, location),
         field_data=DictFieldData({}),
     )
 def setUp(self):
     self.system = get_test_descriptor_system()
     self.all_blocks = {}
     self.system.get_block = self.all_blocks.get
     self.field_data = InheritingFieldData(
         inheritable_names=['inherited'],
         kvs=DictKeyValueStore({}),
     )
Example #20
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("edX", "conditional_test", "test_run", "problem", "SampleProblem", None)
        if source_is_error_module:
            # Make an error descriptor and module
            source_descriptor = NonStaffErrorDescriptor.from_xml(
                "some random xml data",
                system,
                id_generator=CourseLocationManager(source_location.course_key),
                error_msg="random error message",
            )
        else:
            source_descriptor = Mock(name="source_descriptor")
            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(name="child_descriptor")
        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)
        child_descriptor.location = source_location.replace(category="html", name="child")

        descriptor_system.load_item = {
            child_descriptor.location: child_descriptor,
            source_location: source_descriptor,
        }.get

        system.descriptor_runtime = descriptor_system

        # construct conditional module:
        cond_location = Location("edX", "conditional_test", "test_run", "conditional", "SampleConditional", None)
        field_data = DictFieldData(
            {"data": "<conditional/>", "xml_attributes": {"attempted": "true"}, "children": [child_descriptor.location]}
        )

        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}
Example #21
0
 def setUp(self):
     system = get_test_descriptor_system()
     location = Location('i4x://org/course/video/name')
     self.descriptor = system.construct_xblock_from_class(
         VideoDescriptor,
         scope_ids=ScopeIds(None, None, location, location),
         field_data=DictFieldData({}),
     )
     self.descriptor.runtime.handler_url = MagicMock()
Example #22
0
    def get_descriptor(self, field_data):
        class TestModuleDescriptor(TestFields, XmlDescriptor):  # lint-amnesty, pylint: disable=abstract-method
            @property
            def non_editable_metadata_fields(self):
                non_editable_fields = super().non_editable_metadata_fields
                non_editable_fields.append(TestModuleDescriptor.due)
                return non_editable_fields

        system = get_test_descriptor_system(render_template=Mock())
        return system.construct_xblock_from_class(TestModuleDescriptor, field_data=field_data, scope_ids=Mock())
Example #23
0
 def setUp(self):
     system = get_test_descriptor_system()
     course_key = SlashSeparatedCourseKey('org', 'course', 'run')
     usage_key = course_key.make_usage_key('video', 'name')
     self.descriptor = system.construct_xblock_from_class(
         VideoDescriptor,
         scope_ids=ScopeIds(None, None, usage_key, usage_key),
         field_data=DictFieldData({}),
     )
     self.descriptor.runtime.handler_url = MagicMock()
Example #24
0
 def setUp(self):
     super(InheritingFieldDataTest, self).setUp()
     self.dummy_course_key = CourseLocator('test_org', 'test_123', 'test_run')
     self.system = get_test_descriptor_system()
     self.all_blocks = {}
     self.system.get_block = self.all_blocks.get
     self.field_data = InheritingFieldData(
         inheritable_names=['inherited'],
         kvs=DictKeyValueStore({}),
     )
Example #25
0
    def get_descriptor(self, field_data):
        class TestModuleDescriptor(TestFields, XmlDescriptor):
            @property
            def non_editable_metadata_fields(self):
                non_editable_fields = super(TestModuleDescriptor, self).non_editable_metadata_fields
                non_editable_fields.append(TestModuleDescriptor.due)
                return non_editable_fields

        system = get_test_descriptor_system()
        system.render_template = Mock(return_value="<div>Test Template HTML</div>")
        return system.construct_xblock_from_class(TestModuleDescriptor, field_data=field_data, scope_ids=Mock())
 def container_descriptor(self, descriptor_cls):
     location = 'i4x://org/course/category/name'
     runtime = get_test_descriptor_system()
     runtime.render_template = lambda *args, **kwargs: u'{!r}, {!r}'.format(args, kwargs)
     return runtime.construct_xblock_from_class(
         descriptor_cls,
         DictFieldData({
             'children': range(3)
         }),
         ScopeIds(None, descriptor_cls.__name__, location, location)
     )
Example #27
0
def instantiate_descriptor(**field_data):
    """
    Instantiate descriptor with most properties.
    """
    system = get_test_descriptor_system()
    course_key = SlashSeparatedCourseKey('org', 'course', 'run')
    usage_key = course_key.make_usage_key('video', 'SampleProblem')
    return system.construct_xblock_from_class(
        VideoDescriptor,
        scope_ids=ScopeIds(None, None, usage_key, usage_key),
        field_data=DictFieldData(field_data),
    )
    def create():
        """Method return Video Xmodule instance."""
        location = Location(["i4x", "edX", "video", "default",
                             "SampleProblem1"])
        field_data = {'data': VideoFactory.sample_problem_xml_youtube,
                      'location': location}

        system = get_test_descriptor_system()

        descriptor = VideoDescriptor(system, DictFieldData(field_data), ScopeIds(None, None, None, None))
        descriptor.xmodule_runtime = get_test_system()
        return descriptor
Example #29
0
    def create():
        """Method return Video Xmodule instance."""
        location = Location(["i4x", "edX", "video", "default",
                             "SampleProblem1"])
        field_data = {'data': VideoFactory.sample_problem_xml_youtube,
                      'location': location}

        system = get_test_descriptor_system()

        descriptor = VideoDescriptor(system, DictFieldData(field_data), ScopeIds(None, None, None, None))
        descriptor.xmodule_runtime = get_test_system()
        return descriptor
Example #30
0
def instantiate_descriptor(**field_data):
    """
    Instantiate descriptor with most properties.
    """
    system = get_test_descriptor_system()
    course_key = SlashSeparatedCourseKey('org', 'course', 'run')
    usage_key = course_key.make_usage_key('video', 'SampleProblem')
    return system.construct_xblock_from_class(
        VideoDescriptor,
        scope_ids=ScopeIds(None, None, usage_key, usage_key),
        field_data=DictFieldData(field_data),
    )
Example #31
0
def instantiate_descriptor(**field_data):
    """
    Instantiate descriptor with most properties.
    """
    if field_data.get('data', None):
        field_data = VideoBlock.parse_video_xml(field_data['data'])
    system = get_test_descriptor_system()
    course_key = CourseLocator('org', 'course', 'run')
    usage_key = course_key.make_usage_key('video', 'SampleProblem')
    return system.construct_xblock_from_class(
        VideoBlock,
        scope_ids=ScopeIds(None, None, usage_key, usage_key),
        field_data=DictFieldData(field_data),
    )
    def container_descriptor(self, descriptor_cls, depth):
        """Return an instance of `descriptor_cls` with `depth` levels of children"""
        location = Location('i4x://org/course/category/name')
        runtime = get_test_descriptor_system()

        if depth == 0:
            runtime.load_item.side_effect = lambda x: self.leaf_module(HtmlDescriptor)
        else:
            runtime.load_item.side_effect = lambda x: self.container_module(VerticalDescriptor, depth - 1)

        return runtime.construct_xblock_from_class(
            descriptor_cls,
            ScopeIds(None, descriptor_cls.__name__, location, location),
            DictFieldData({
                'children': range(3)
            }),
        )
    def container_descriptor(self, descriptor_cls, depth):
        """Return an instance of `descriptor_cls` with `depth` levels of children"""
        location = 'i4x://org/course/category/name'
        runtime = get_test_descriptor_system()

        if depth == 0:
            runtime.load_item.side_effect = lambda x: self.leaf_module(HtmlDescriptor)
        else:
            runtime.load_item.side_effect = lambda x: self.container_module(VerticalDescriptor, depth - 1)

        return runtime.construct_xblock_from_class(
            descriptor_cls,
            ScopeIds(None, descriptor_cls.__name__, location, location),
            DictFieldData({
                'children': range(3)
            }),
        )
Example #34
0
 def _build(cls, target_class, *args, **kwargs):  # pylint: disable=unused-argument
     """See documentation from :meth:`factory.Factory._build`"""
     return get_test_descriptor_system(*args, **kwargs)
Example #35
0
 def new_descriptor_runtime(self):
     runtime = get_test_descriptor_system()
     runtime.get_block = modulestore().get_item
     return runtime
    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("edX", "conditional_test", "test_run",
                                   "problem", "SampleProblem", None)
        if source_is_error_module:
            # Make an error descriptor and module
            source_descriptor = NonStaffErrorDescriptor.from_xml(
                'some random xml data',
                system,
                id_generator=CourseLocationManager(source_location.course_key),
                error_msg='random error message')
        else:
            source_descriptor = Mock(name='source_descriptor')
            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(name='child_descriptor')
        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)
        child_descriptor.location = source_location.replace(category='html',
                                                            name='child')

        descriptor_system.load_item = {
            child_descriptor.location: child_descriptor,
            source_location: source_descriptor
        }.get

        system.descriptor_runtime = descriptor_system

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

        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
        }
Example #37
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("edX", "conditional_test", "test_run", "problem", "SampleProblem", None)
        if source_is_error_module:
            # Make an error descriptor and module
            source_descriptor = NonStaffErrorDescriptor.from_xml(
                'some random xml data',
                system,
                id_generator=CourseLocationManager(source_location.course_key),
                error_msg='random error message'
            )
        else:
            source_descriptor = Mock(name='source_descriptor')
            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(name='child_descriptor')
        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)
        child_descriptor.location = source_location.replace(category='html', name='child')

        def load_item(usage_id, for_parent=None):  # pylint: disable=unused-argument
            """Test-only implementation of load_item that simply returns static xblocks."""
            return {
                child_descriptor.location: child_descriptor,
                source_location: source_descriptor
            }.get(usage_id)

        descriptor_system.load_item = load_item

        system.descriptor_runtime = descriptor_system

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

        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}
Example #38
0
    def create(system,
               source_is_error_module=False,
               source_visible_to_staff_only=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 = BlockUsageLocator(CourseLocator("edX",
                                                          "conditional_test",
                                                          "test_run",
                                                          deprecated=True),
                                            "problem",
                                            "SampleProblem",
                                            deprecated=True)
        if source_is_error_module:
            # Make an error descriptor and module
            source_descriptor = NonStaffErrorDescriptor.from_xml(
                'some random xml data',
                system,
                id_generator=CourseLocationManager(source_location.course_key),
                error_msg='random error message')
        else:
            source_descriptor = Mock(name='source_descriptor')
            source_descriptor.location = source_location

        source_descriptor.visible_to_staff_only = source_visible_to_staff_only
        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(name='child_descriptor')
        child_descriptor.visible_to_staff_only = False
        child_descriptor._xmodule.student_view.return_value = Fragment(
            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)
        child_descriptor.location = source_location.replace(category='html',
                                                            name='child')

        def visible_to_nonstaff_users(desc):
            """
            Returns if the object is visible to nonstaff users.
            """
            return not desc.visible_to_staff_only

        def load_item(usage_id, for_parent=None):  # pylint: disable=unused-argument
            """Test-only implementation of load_item that simply returns static xblocks."""
            return {
                child_descriptor.location: child_descriptor,
                source_location: source_descriptor
            }.get(usage_id)

        descriptor_system.load_item = load_item

        system.descriptor_runtime = descriptor_system

        # construct conditional module:
        cond_location = BlockUsageLocator(CourseLocator("edX",
                                                        "conditional_test",
                                                        "test_run",
                                                        deprecated=True),
                                          "conditional",
                                          "SampleConditional",
                                          deprecated=True)
        field_data = DictFieldData({
            'data': '<conditional/>',
            'conditional_attr': 'attempted',
            'conditional_value': 'true',
            'xml_attributes': {
                'attempted': 'true'
            },
            'children': [child_descriptor.location],
        })

        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 if visible_to_nonstaff_users(
            desc) else None
        cond_descriptor.get_required_module_descriptors = Mock(
            return_value=[source_descriptor])
        cond_descriptor.required_modules = [
            system.get_module(descriptor) for descriptor in
            cond_descriptor.get_required_module_descriptors()
        ]

        # return dict:
        return {
            'cond_module': cond_descriptor,
            'source_module': source_descriptor,
            'child_module': child_descriptor
        }