Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 71 additions & 5 deletions common/lib/xmodule/xmodule/tests/test_xblock_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,25 @@
CourseDescriptor,
)

# These modules are editable in studio yet
NOT_STUDIO_EDITABLE = (
CrowdsourceHinterDescriptor,
GraphicalSliderToolDescriptor,
PollDescriptor
)


class TestXBlockWrapper(object):

@property
def leaf_module_runtime(self):
runtime = Mock()
runtime.render_template = lambda *args, **kwargs: unicode((args, kwargs))
runtime.anonymous_student_id = 'anonymous_student_id'
runtime.anonymous_student_id = 'dummy_anonymous_student_id'
runtime.open_ended_grading_interface = {}
runtime.seed = 5
runtime.get = lambda x: getattr(runtime, x)
runtime.position = 2
runtime.ajax_url = 'ajax_url'
runtime.ajax_url = 'dummy_ajax_url'
runtime.xblock_model_data = lambda d: d._model_data
return runtime

Expand All @@ -78,7 +84,7 @@ def leaf_descriptor_runtime(self):
def leaf_descriptor(self, descriptor_cls):
return descriptor_cls(
self.leaf_descriptor_runtime,
{'location': 'i4x://org/course/catagory/name'}
{'location': 'i4x://org/course/category/name'}
)

def leaf_module(self, descriptor_cls):
Expand All @@ -90,6 +96,7 @@ def container_module_runtime(self, depth):
runtime.get_module.side_effect = lambda x: self.leaf_module(HtmlDescriptor)
else:
runtime.get_module.side_effect = lambda x: self.container_module(VerticalDescriptor, depth-1)
runtime.position = 2
return runtime

@property
Expand All @@ -102,7 +109,7 @@ def container_descriptor(self, descriptor_cls):
return descriptor_cls(
self.container_descriptor_runtime,
{
'location': 'i4x://org/course/catagory/name',
'location': 'i4x://org/course/category/name',
'children': range(3)
}
)
Expand Down Expand Up @@ -158,3 +165,62 @@ def check_student_view_container_node_mixed(self, descriptor_cls):
def check_student_view_container_node_xblocks_only(self, descriptor_cls):
raise SkipTest("XBlock support in XModules not yet fully implemented")


class TestStudioView(TestXBlockWrapper):

# Test that for all of the Descriptors listed in LEAF_XMODULES,
# the studio_view wrapper returns the same thing in its content
# as get_html returns
def test_studio_view_leaf_node(self):
for descriptor_cls in LEAF_XMODULES:
yield self.check_studio_view_leaf_node, descriptor_cls

# Check that when a descriptor is instantiated from descriptor_cls
# it generates the same thing from studio_view that it does from get_html
def check_studio_view_leaf_node(self, descriptor_cls):
if descriptor_cls in NOT_STUDIO_EDITABLE:
raise SkipTest(descriptor_cls.__name__ + "is not editable in studio")

descriptor = self.leaf_descriptor(descriptor_cls)
assert_equal(descriptor.get_html(), descriptor.studio_view(None).content)


# Test that for all of the Descriptors listed in CONTAINER_XMODULES
# render the same thing using studio_view as they do using get_html, under the following conditions:
# a) All of its descendents are xmodules
# b) Some of its descendents are xmodules and some are xblocks
# c) All of its descendents are xblocks
def test_studio_view_container_node(self):
for descriptor_cls in CONTAINER_XMODULES:
yield self.check_studio_view_container_node_xmodules_only, descriptor_cls
yield self.check_studio_view_container_node_mixed, descriptor_cls
yield self.check_studio_view_container_node_xblocks_only, descriptor_cls


# Check that when a descriptor is generated from descriptor_cls
# with only xmodule children, it generates the same html from studio_view
# as it does using get_html
def check_studio_view_container_node_xmodules_only(self, descriptor_cls):
if descriptor_cls in NOT_STUDIO_EDITABLE:
raise SkipTest(descriptor_cls.__name__ + "is not editable in studio")

descriptor = self.container_descriptor(descriptor_cls)
assert_equal(descriptor.get_html(), descriptor.studio_view(None).content)

# Check that when a descriptor is generated from descriptor_cls
# with mixed xmodule and xblock children, it generates the same html from studio_view
# as it does using get_html
def check_studio_view_container_node_mixed(self, descriptor_cls):
if descriptor_cls in NOT_STUDIO_EDITABLE:
raise SkipTest(descriptor_cls.__name__ + "is not editable in studio")

raise SkipTest("XBlock support in XDescriptor not yet fully implemented")

# Check that when a descriptor is generated from descriptor_cls
# with only xblock children, it generates the same html from studio_view
# as it does using get_html
def check_studio_view_container_node_xblocks_only(self, descriptor_cls):
if descriptor_cls in NOT_STUDIO_EDITABLE:
raise SkipTest(descriptor_cls.__name__ + "is not editable in studio")

raise SkipTest("XBlock support in XModules not yet fully implemented")
12 changes: 12 additions & 0 deletions common/lib/xmodule/xmodule/x_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,18 @@ def editable_metadata_fields(self):

return metadata_fields

# ~~~~~~~~~~~~~~~ XBlock API Wrappers ~~~~~~~~~~~~~~~~
def studio_view(self, context):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if context is not yet used, shouldn't it be _context?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I do that, then I'm changing the signature from the standard for a view, which means that a call using a named argument view_fn(context=blarg) wouldn't work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay.

"""
Return a fragment with the html from this XModuleDescriptor's editing view

Doesn't yet add any of the javascript to the fragment, nor the css.
Also doesn't expect any javascript binding, yet.

Makes no use of the context parameter
"""
return Fragment(self.get_html())


class DescriptorSystem(object):
def __init__(self, load_item, resources_fs, error_tracker, **kwargs):
Expand Down