Add test of local_resource_url in AcidBlock

This commit is contained in:
Calen Pennington
2014-02-14 06:44:10 -05:00
parent 39563c327c
commit 9126777ed7
19 changed files with 146 additions and 15 deletions

View File

@@ -1496,7 +1496,7 @@ class SplitMongoModuleStore(ModuleStoreWriteBase):
"""
if fields is None:
return {}
cls = self.mixologist.mix(XBlock.load_class(category, select=prefer_xmodules))
cls = self.mixologist.mix(XBlock.load_class(category, select=self.xblock_select))
result = collections.defaultdict(dict)
for field_name, value in fields.iteritems():
field = getattr(cls, field_name)

View File

@@ -47,6 +47,9 @@ class TestModuleSystem(ModuleSystem): # pylint: disable=abstract-method
def handler_url(self, block, handler, suffix='', query='', thirdparty=False):
return str(block.scope_ids.usage_id) + '/' + handler + '/' + suffix + '?' + query
def local_resource_url(self, block, uri):
return 'resource/' + str(block.scope_ids.block_type) + '/' + uri
def get_test_system(course_id=''):
"""

View File

@@ -143,6 +143,9 @@ class XModuleMixin(XBlockMixin):
@property
def system(self):
"""
Return the XBlock runtime (backwards compatibility alias provided for XModules).
"""
return self.runtime
@property
@@ -893,8 +896,21 @@ class ConfigurableFragmentWrapper(object): # pylint: disable=abstract-method
# 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")
def descriptor_global_handler_url(block, handler_name, suffix='', query='', thirdparty=False): # pylint: disable=invalid-name, unused-argument
"""
See :meth:`xblock.runtime.Runtime.handler_url`.
"""
raise NotImplementedError("Applications must monkey-patch this function before using handler_url for studio_view")
# 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.local_resource_url interface
def descriptor_global_local_resource_url(block, uri): # pylint: disable=invalid-name, unused-argument
"""
See :meth:`xblock.runtime.Runtime.local_resource_url`.
"""
raise NotImplementedError("Applications must monkey-patch this function before using local_resource_url for studio_view")
class DescriptorSystem(ConfigurableFragmentWrapper, Runtime): # pylint: disable=abstract-method
@@ -943,6 +959,8 @@ class DescriptorSystem(ConfigurableFragmentWrapper, Runtime): # pylint: disable
get_policy: a function that takes a usage id and returns a dict of
policy to apply.
local_resource_url: an implementation of :meth:`xblock.runtime.Runtime.local_resource_url`
"""
super(DescriptorSystem, self).__init__(**kwargs)
@@ -1010,13 +1028,30 @@ class DescriptorSystem(ConfigurableFragmentWrapper, Runtime): # pylint: disable
# global function that the application can override.
return descriptor_global_handler_url(block, handler_name, suffix, query, thirdparty)
def resource_url(self, resource):
raise NotImplementedError("edX Platform doesn't currently implement XBlock resource urls")
def local_resource_url(self, block, uri):
"""
See :meth:`xblock.runtime.Runtime:local_resource_url` for documentation.
"""
xmodule_runtime = getattr(block, 'xmodule_runtime', None)
if xmodule_runtime is not None:
return xmodule_runtime.local_resource_url(block, uri)
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 local_resource_url. So, for now, instead, we will reference a
# global function that the application can override.
return descriptor_global_local_resource_url(block, uri)
def resource_url(self, resource):
"""
See :meth:`xblock.runtime.Runtime:resource_url` for documentation.
"""
raise NotImplementedError("edX Platform doesn't currently implement XBlock resource urls")
def publish(self, block, event):
"""
See :meth:`xblock.runtime.Runtime:publish` for documentation.
"""
raise NotImplementedError("edX Platform doesn't currently implement XBlock publish")
def add_block_as_child_node(self, block, node):
@@ -1182,9 +1217,6 @@ class ModuleSystem(ConfigurableFragmentWrapper, Runtime): # pylint: disable=abs
def resource_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")
def publish(self, block, event):
pass

View File

@@ -61,6 +61,13 @@ class AcidView(PageObject):
self.test_passed('.child-values-match')
])
@property
def resource_url_passed(self):
"""
Whether the resource-url test passed in this view of the :class:`.AcidBlock`.
"""
return self.test_passed('.local-resource-test')
def scope_passed(self, scope):
return all(
self.test_passed('.scope-storage-test.scope-{} {}'.format(scope, test))

View File

@@ -371,6 +371,7 @@ class XBlockAcidBase(UniqueCourseTest):
self.assertTrue(acid_block.init_fn_passed)
self.assertTrue(acid_block.doc_ready_passed)
self.assertTrue(acid_block.child_tests_passed)
self.assertTrue(acid_block.resource_url_passed)
self.assertTrue(acid_block.scope_passed('user_state'))

View File

@@ -159,6 +159,7 @@ class XBlockAcidBase(WebAppTest):
self.assertTrue(acid_block.init_fn_passed)
self.assertTrue(acid_block.doc_ready_passed)
self.assertTrue(acid_block.child_tests_passed)
self.assertTrue(acid_block.resource_url_passed)
self.assertTrue(acid_block.scope_passed('user_state'))
def test_acid_block_editor(self):
@@ -175,6 +176,7 @@ class XBlockAcidBase(WebAppTest):
self.assertTrue(acid_block.init_fn_passed)
self.assertTrue(acid_block.doc_ready_passed)
self.assertTrue(acid_block.child_tests_passed)
self.assertTrue(acid_block.resource_url_passed)
self.assertTrue(acid_block.scope_passed('content'))
self.assertTrue(acid_block.scope_passed('settings'))