Add handler_url usable by descriptors

[LMS-1614]
This commit is contained in:
Calen Pennington
2013-12-06 09:15:20 -05:00
parent 8e98c8cbb7
commit aa57481ecc
14 changed files with 238 additions and 18 deletions

View File

@@ -10,6 +10,7 @@ from mock import MagicMock, Mock, patch
from xblock.runtime import Runtime, UsageStore
from xblock.field_data import FieldData
from xblock.fields import ScopeIds
from xblock.test.tools import unabc
class SetupTestErrorModules():
@@ -103,6 +104,11 @@ class TestException(Exception):
pass
@unabc("Tests should not call {}")
class TestRuntime(Runtime):
pass
class TestErrorModuleConstruction(unittest.TestCase):
"""
Test that error module construction happens correctly
@@ -111,11 +117,11 @@ class TestErrorModuleConstruction(unittest.TestCase):
def setUp(self):
field_data = Mock(spec=FieldData)
self.descriptor = BrokenDescriptor(
Runtime(Mock(spec=UsageStore), field_data),
TestRuntime(Mock(spec=UsageStore), field_data),
field_data,
ScopeIds(None, None, None, 'i4x://org/course/broken/name')
)
self.descriptor.xmodule_runtime = Runtime(Mock(spec=UsageStore), field_data)
self.descriptor.xmodule_runtime = TestRuntime(Mock(spec=UsageStore), field_data)
self.descriptor.xmodule_runtime.error_descriptor_class = ErrorDescriptor
self.descriptor.xmodule_runtime.xmodule_instance = None

View File

@@ -841,6 +841,13 @@ class ConfigurableFragmentWrapper(object): # pylint: disable=abstract-method
return frag
# This function exists to give applications (LMS/CMS) a place to monkey-patch until
# we can refactor modulestore to split out the FieldData half of its interface from
# the Runtime part of its interface. This function matches the Runtime.handler_url interface
def descriptor_global_handler_url(block, handler_name, suffix='', query='', thirdparty=False):
raise NotImplementedError("Applications must monkey-patch this function before using handler-urls for studio_view")
class DescriptorSystem(ConfigurableFragmentWrapper, Runtime): # pylint: disable=abstract-method
"""
Base class for :class:`Runtime`s to be used with :class:`XModuleDescriptor`s
@@ -891,9 +898,9 @@ class DescriptorSystem(ConfigurableFragmentWrapper, Runtime): # pylint: disable
self.resources_fs = resources_fs
self.error_tracker = error_tracker
def get_block(self, block_id):
def get_block(self, usage_id):
"""See documentation for `xblock.runtime:Runtime.get_block`"""
return self.load_item(block_id)
return self.load_item(usage_id)
def get_field_provenance(self, xblock, field):
"""
@@ -933,6 +940,23 @@ class DescriptorSystem(ConfigurableFragmentWrapper, Runtime): # pylint: disable
else:
return super(DescriptorSystem, self).render(block, view_name, context)
def handler_url(self, block, handler_name, suffix='', query='', thirdparty=False):
xmodule_runtime = getattr(block, 'xmodule_runtime', None)
if xmodule_runtime is not None:
return xmodule_runtime.handler_url(block, handler_name, suffix, query, thirdparty)
else:
# Currently, Modulestore is responsible for instantiating DescriptorSystems
# This means that LMS/CMS don't have a way to define a subclass of DescriptorSystem
# that implements the correct handler url. So, for now, instead, we will reference a
# global function that the application can override.
return descriptor_global_handler_url(block, handler_name, suffix, query, thirdparty)
def resources_url(self, resource):
raise NotImplementedError("edX Platform doesn't currently implement XBlock resource urls")
def local_resource_url(self, block, uri):
raise NotImplementedError("edX Platform doesn't currently implement XBlock resource urls")
class XMLParsingSystem(DescriptorSystem):
def __init__(self, process_xml, policy, **kwargs):
@@ -1079,6 +1103,15 @@ class ModuleSystem(ConfigurableFragmentWrapper, Runtime): # pylint: disable=abs
assert self.xmodule_instance is not None
return self.handler_url(self.xmodule_instance, 'xmodule_handler', '', '').rstrip('/?')
def get_block(self, block_id):
raise NotImplementedError("XModules must use get_module to load other modules")
def resources_url(self, resource):
raise NotImplementedError("edX Platform doesn't currently implement XBlock resource urls")
def local_resource_url(self, block, uri):
raise NotImplementedError("edX Platform doesn't currently implement XBlock resource urls")
class DoNothingCache(object):
"""A duck-compatible object to use in ModuleSystem when there's no cache."""