Commit 7df50a16 by Calen Pennington Committed by David Baumgold

get the raw DescriptorSystem, not the CombinedSystem when instantiating xmodules (TNL-1226)

get the raw DescriptorSystem, not the CombinedSystem when instantiating xmodules (TNL-1226)

quality fixes

remove trailing comma
parent fa5da96d
......@@ -185,7 +185,8 @@ def _preview_module_system(request, descriptor, field_data):
wrappers=wrappers,
error_descriptor_class=ErrorDescriptor,
get_user_role=lambda: get_user_role(request.user, course_id),
descriptor_runtime=descriptor.runtime,
# Get the raw DescriptorSystem, not the CombinedSystem
descriptor_runtime=descriptor._runtime, # pylint: disable=protected-access
services={
"i18n": ModuleI18nService(),
"field-data": field_data,
......
......@@ -94,7 +94,7 @@ def get_test_system(course_id=SlashSeparatedCourseKey('org', 'course', 'run')):
"""
user = Mock(name='get_test_system.user', is_staff=False)
descriptor_system = get_test_descriptor_system(),
descriptor_system = get_test_descriptor_system()
def get_module(descriptor):
"""Mocks module_system get_module function"""
......@@ -107,7 +107,7 @@ def get_test_system(course_id=SlashSeparatedCourseKey('org', 'course', 'run')):
# Descriptors can all share a single DescriptorSystem.
# So, bind to the same one as the current descriptor.
module_system.descriptor_runtime = descriptor.runtime._descriptor_system
module_system.descriptor_runtime = descriptor._runtime # pylint: disable=protected-access
descriptor.bind_for_student(module_system, descriptor._field_data)
......
......@@ -54,14 +54,14 @@ class LibraryContentTest(MixedSplitTestCase):
Bind a module (part of self.course) so we can access student-specific data.
"""
module_system = get_test_system(course_id=self.course.location.course_key)
module_system.descriptor_runtime = module.runtime
module_system.descriptor_runtime = module.runtime._descriptor_system # pylint: disable=protected-access
module_system._services['library_tools'] = self.tools # pylint: disable=protected-access
def get_module(descriptor):
"""Mocks module_system get_module function"""
sub_module_system = get_test_system(course_id=self.course.location.course_key)
sub_module_system.get_module = get_module
sub_module_system.descriptor_runtime = descriptor.runtime
sub_module_system.descriptor_runtime = descriptor._runtime # pylint: disable=protected-access
descriptor.bind_for_student(sub_module_system, descriptor._field_data) # pylint: disable=protected-access
return descriptor
......
......@@ -78,7 +78,7 @@ class SplitTestModuleTest(XModuleXmlImportTest, PartitionTestCase):
self.course_sequence = self.course.get_children()[0]
self.module_system = get_test_system()
self.module_system.descriptor_runtime = self.course.runtime._descriptor_system # pylint: disable=protected-access
self.module_system.descriptor_runtime = self.course._runtime # pylint: disable=protected-access
self.course.runtime.export_fs = MemoryFS()
self.partitions_service = StaticPartitionService(
......
......@@ -27,7 +27,7 @@ class BaseVerticalModuleTest(XModuleXmlImportTest):
course_seq = self.course.get_children()[0]
self.module_system = get_test_system()
self.module_system.descriptor_runtime = self.course.runtime._descriptor_system # pylint: disable=protected-access
self.module_system.descriptor_runtime = self.course._runtime # pylint: disable=protected-access
self.course.runtime.export_fs = MemoryFS()
self.vertical = course_seq.get_children()[0]
......
......@@ -3,6 +3,7 @@ import os
import sys
import yaml
from contracts import contract, new_contract
from functools import partial
from lxml import etree
from collections import namedtuple
......@@ -1307,6 +1308,9 @@ class DescriptorSystem(MetricsMixin, ConfigurableFragmentWrapper, Runtime): # p
pass
new_contract('DescriptorSystem', DescriptorSystem)
class XMLParsingSystem(DescriptorSystem):
def __init__(self, process_xml, **kwargs):
"""
......@@ -1427,6 +1431,8 @@ class ModuleSystem(MetricsMixin, ConfigurableFragmentWrapper, Runtime): # pylin
Note that these functions can be closures over e.g. a django request
and user, or other environment-specific info.
"""
@contract(descriptor_runtime='DescriptorSystem')
def __init__(
self, static_url, track_function, get_module, render_template,
replace_urls, descriptor_runtime, user=None, filestore=None,
......
......@@ -647,7 +647,7 @@ def get_module_system_for_user(user, field_data_cache,
'user': DjangoXBlockUserService(user),
},
get_user_role=lambda: get_user_role(user, course_id),
descriptor_runtime=descriptor.runtime,
descriptor_runtime=descriptor._runtime, # pylint: disable=protected-access
rebind_noauth_module_to_user=rebind_noauth_module_to_user,
user_location=user_location,
request_token=request_token,
......
......@@ -41,7 +41,7 @@ from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory, check_mongo_calls
from xmodule.x_module import XModuleDescriptor, XModule, STUDENT_VIEW
from xmodule.x_module import XModuleDescriptor, XModule, STUDENT_VIEW, CombinedSystem
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
......@@ -903,13 +903,16 @@ class TestAnonymousStudentId(ModuleStoreTestCase, LoginEnrollmentTestCase):
_field_data=Mock(spec=FieldData),
location=location,
static_asset_path=None,
runtime=Mock(
_runtime=Mock(
spec=Runtime,
resources_fs=None,
mixologist=Mock(_mixins=())
mixologist=Mock(_mixins=(), name='mixologist'),
name='runtime',
),
scope_ids=Mock(spec=ScopeIds),
name='descriptor'
)
descriptor.runtime = CombinedSystem(descriptor._runtime, None) # pylint: disable=protected-access
# Use the xblock_class's bind_for_student method
descriptor.bind_for_student = partial(xblock_class.bind_for_student, descriptor)
......@@ -919,10 +922,10 @@ class TestAnonymousStudentId(ModuleStoreTestCase, LoginEnrollmentTestCase):
return render.get_module_for_descriptor_internal(
user=self.user,
descriptor=descriptor,
field_data_cache=Mock(spec=FieldDataCache),
field_data_cache=Mock(spec=FieldDataCache, name='field_data_cache'),
course_id=course_id,
track_function=Mock(), # Track Function
xqueue_callback_url_prefix=Mock(), # XQueue Callback Url Prefix
track_function=Mock(name='track_function'), # Track Function
xqueue_callback_url_prefix=Mock(name='xqueue_callback_url_prefix'), # XQueue Callback Url Prefix
request_token='request_token',
).xmodule_runtime.anonymous_student_id
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment