refactor: removes calls to deprecated properties from source and tests.

This commit is contained in:
Jillian Vogel
2021-12-06 12:05:58 +10:30
parent 2173a98ef8
commit 57b390f8e2
2 changed files with 26 additions and 12 deletions

View File

@@ -31,12 +31,6 @@ from capa.capa_problem import LoncapaProblem, LoncapaSystem
from capa.inputtypes import Status
from capa.responsetypes import LoncapaProblemError, ResponseError, StudentInputError
from capa.util import convert_files_to_filenames, get_inner_html_from_xpath
from common.djangoapps.xblock_django.constants import (
ATTR_KEY_ANONYMOUS_USER_ID,
ATTR_KEY_USER_IS_STAFF,
ATTR_KEY_USER_ID,
)
from openedx.core.djangolib.markup import HTML, Text
from xmodule.contentstore.django import contentstore
from xmodule.editing_module import EditingMixin
from xmodule.exceptions import NotFoundError, ProcessingError
@@ -53,6 +47,12 @@ from xmodule.x_module import (
shim_xmodule_js
)
from xmodule.xml_module import XmlMixin
from common.djangoapps.xblock_django.constants import (
ATTR_KEY_ANONYMOUS_USER_ID,
ATTR_KEY_USER_IS_STAFF,
ATTR_KEY_USER_ID,
)
from openedx.core.djangolib.markup import HTML, Text
from .fields import Date, ScoreField, Timedelta
from .progress import Progress
@@ -121,6 +121,8 @@ class Randomization(String):
@XBlock.needs('user')
@XBlock.needs('i18n')
@XBlock.needs('mako')
@XBlock.needs('cache')
@XBlock.needs('sandbox')
# Studio doesn't provide XQueueService, but the LMS does.
@XBlock.wants('xqueue')
@XBlock.wants('call_to_action')
@@ -814,12 +816,15 @@ class ProblemBlock(
anonymous_student_id = user_service.get_current_user().opt_attrs.get(ATTR_KEY_ANONYMOUS_USER_ID)
seed = user_service.get_current_user().opt_attrs.get(ATTR_KEY_USER_ID) or 0
sandbox_service = self.runtime.service(self, 'sandbox')
cache_service = self.runtime.service(self, 'cache')
capa_system = LoncapaSystem(
ajax_url=self.ajax_url,
anonymous_student_id=anonymous_student_id,
cache=self.runtime.cache,
can_execute_unsafe_code=self.runtime.can_execute_unsafe_code,
get_python_lib_zip=self.runtime.get_python_lib_zip,
cache=cache_service,
can_execute_unsafe_code=sandbox_service.can_execute_unsafe_code,
get_python_lib_zip=sandbox_service.get_python_lib_zip,
DEBUG=self.runtime.DEBUG,
filestore=self.runtime.filestore,
i18n=self.runtime.service(self, "i18n"),

View File

@@ -28,6 +28,7 @@ from xblock.fields import Reference, ReferenceList, ReferenceValueDict, ScopeIds
from capa.xqueue_interface import XQueueService
from xmodule.assetstore import AssetMetadata
from xmodule.contentstore.django import contentstore
from xmodule.error_module import ErrorBlock
from xmodule.mako_module import MakoDescriptorSystem
from xmodule.modulestore import ModuleStoreEnum
@@ -35,7 +36,9 @@ from xmodule.modulestore.draft_and_published import ModuleStoreDraftAndPublished
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore.xml import CourseLocationManager
from xmodule.tests.helpers import mock_render_template, StubMakoService, StubUserService
from xmodule.x_module import ModuleSystem, XModuleDescriptor, XModuleMixin
from xmodule.util.sandboxing import SandboxService
from xmodule.x_module import DoNothingCache, ModuleSystem, XModuleDescriptor, XModuleMixin
from openedx.core.lib.cache_utils import CacheService
MODULE_DIR = path(__file__).dirname()
@@ -49,10 +52,16 @@ class TestModuleSystem(ModuleSystem): # pylint: disable=abstract-method
ModuleSystem for testing
"""
def __init__(self, **kwargs):
id_manager = CourseLocationManager(kwargs['course_id'])
course_id = kwargs['course_id']
id_manager = CourseLocationManager(course_id)
kwargs.setdefault('id_reader', id_manager)
kwargs.setdefault('id_generator', id_manager)
kwargs.setdefault('services', {}).setdefault('field-data', DictFieldData({}))
services = kwargs.get('services', {})
services.setdefault('cache', CacheService(DoNothingCache()))
services.setdefault('field-data', DictFieldData({}))
services.setdefault('sandbox', SandboxService(contentstore, course_id))
kwargs['services'] = services
super().__init__(**kwargs)
def handler_url(self, block, handler, suffix='', query='', thirdparty=False): # lint-amnesty, pylint: disable=arguments-differ