Skip to content

Commit bbc29bc

Browse files
committed
fix: extracted problem xblock
1 parent 42afa1b commit bbc29bc

12 files changed

Lines changed: 77 additions & 45 deletions

File tree

lms/djangoapps/courseware/tests/test_submitting_problems.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
SchematicResponseXMLFactory
3030
)
3131
from xmodule.capa.tests.test_util import use_unsafe_codejail
32-
from xmodule.capa.xqueue_interface import XQueueInterface
3332
from common.djangoapps.course_modes.models import CourseMode
3433
from lms.djangoapps.courseware.models import BaseStudentModuleHistory, StudentModule
3534
from lms.djangoapps.courseware.tests.helpers import LoginEnrollmentTestCase
@@ -44,6 +43,12 @@
4443
from xmodule.partitions.partitions import Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order
4544

4645

46+
if settings.USE_EXTRACTED_PROBLEM_BLOCK:
47+
from xblocks_contrib.problem.capa.xqueue_interface import XQueueInterface
48+
else:
49+
from xmodule.capa.xqueue_interface import XQueueInterface
50+
51+
4752
class ProblemSubmissionTestMixin(TestCase):
4853
"""
4954
TestCase mixin that provides functions to submit answers to problems.

lms/djangoapps/instructor_task/tests/test_integration.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
2020
from django.test.utils import override_settings
2121
from django.urls import reverse
22+
from django.conf import settings
2223

2324
from xmodule.capa.responsetypes import StudentInputError
2425
from xmodule.capa.tests.response_xml_factory import CodeResponseXMLFactory, CustomResponseXMLFactory
@@ -45,6 +46,8 @@
4546
from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order
4647
from xmodule.modulestore.tests.factories import BlockFactory # lint-amnesty, pylint: disable=wrong-import-order
4748

49+
PREFIX_CAPA = "xblocks_contrib.problem" if settings.USE_EXTRACTED_PROBLEM_BLOCK else "xmodule"
50+
4851
log = logging.getLogger(__name__)
4952

5053

@@ -275,7 +278,7 @@ def test_rescoring_failure(self):
275278
self.submit_student_answer('u1', problem_url_name, [OPTION_1, OPTION_1])
276279

277280
expected_message = "bad things happened"
278-
with patch('xmodule.capa.capa_problem.LoncapaProblem.get_grade_from_current_answers') as mock_rescore:
281+
with patch(f'{PREFIX_CAPA}.capa.capa_problem.LoncapaProblem.get_grade_from_current_answers') as mock_rescore:
279282
mock_rescore.side_effect = ZeroDivisionError(expected_message)
280283
instructor_task = self.submit_rescore_all_student_answers('instructor', problem_url_name)
281284
self._assert_task_failure(
@@ -295,7 +298,7 @@ def test_rescoring_bad_unicode_input(self):
295298

296299
# return an input error as if it were a numerical response, with an embedded unicode character:
297300
expected_message = "Could not interpret '2/3\u03a9' as a number"
298-
with patch('xmodule.capa.capa_problem.LoncapaProblem.get_grade_from_current_answers') as mock_rescore:
301+
with patch(f'{PREFIX_CAPA}.capa.capa_problem.LoncapaProblem.get_grade_from_current_answers') as mock_rescore:
299302
mock_rescore.side_effect = StudentInputError(expected_message)
300303
instructor_task = self.submit_rescore_all_student_answers('instructor', problem_url_name)
301304

lms/envs/common.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@
15841584
# Import after sys.path fixup
15851585
from xmodule.modulestore.edit_info import EditInfoMixin # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position
15861586
from xmodule.modulestore.inheritance import InheritanceMixin # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position
1587-
from xmodule.x_module import XModuleMixin # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position
1587+
from xmodule.x_module import XModuleMixin, ResourceTemplates # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position
15881588

15891589
# These are the Mixins that will be added to every Blocklike upon instantiation.
15901590
# DO NOT EXPAND THIS LIST!! We want it eventually to be EMPTY. Why? Because dynamically adding functions/behaviors to
@@ -1597,6 +1597,7 @@
15971597
# (b) refactor their functionality out of the Blocklike objects and into the edx-platform block runtimes.
15981598
LmsBlockMixin,
15991599
InheritanceMixin,
1600+
ResourceTemplates,
16001601
XModuleMixin,
16011602
EditInfoMixin,
16021603
)
@@ -3164,6 +3165,9 @@
31643165
"openedx_learning.apps.authoring.units",
31653166
"openedx_learning.apps.authoring.subsections",
31663167
"openedx_learning.apps.authoring.sections",
3168+
3169+
# Extracted problem xblock
3170+
"xblocks_contrib.problem.capa"
31673171
]
31683172

31693173
######################### CSRF #########################################

openedx/envs/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ def _make_locale_paths(settings):
763763
# .. toggle_warning: Not production-ready until relevant subtask https://github.com/openedx/edx-platform/issues/34827 is done.
764764
# .. toggle_creation_date: 2024-11-10
765765
# .. toggle_target_removal_date: 2025-06-01
766-
USE_EXTRACTED_PROBLEM_BLOCK = False
766+
USE_EXTRACTED_PROBLEM_BLOCK = True
767767

768768
# .. toggle_name: USE_EXTRACTED_VIDEO_BLOCK
769769
# .. toggle_default: False

requirements/edx/base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ xblock-utils==4.0.0
12801280
# via
12811281
# edx-sga
12821282
# xblock-poll
1283-
xblocks-contrib==0.6.0
1283+
git+https://github.com/openedx/xblocks-contrib.git@problemblock
12841284
# via -r requirements/edx/bundled.in
12851285
xmlsec==1.3.14
12861286
# via

requirements/edx/development.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2285,7 +2285,7 @@ xblock-utils==4.0.0
22852285
# -r requirements/edx/testing.txt
22862286
# edx-sga
22872287
# xblock-poll
2288-
xblocks-contrib==0.6.0
2288+
git+https://github.com/openedx/xblocks-contrib.git@problemblock
22892289
# via
22902290
# -r requirements/edx/doc.txt
22912291
# -r requirements/edx/testing.txt

requirements/edx/doc.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ xblock-utils==4.0.0
16091609
# -r requirements/edx/base.txt
16101610
# edx-sga
16111611
# xblock-poll
1612-
xblocks-contrib==0.6.0
1612+
git+https://github.com/openedx/xblocks-contrib.git@problemblock
16131613
# via -r requirements/edx/base.txt
16141614
xmlsec==1.3.14
16151615
# via

requirements/edx/testing.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,7 @@ xblock-utils==4.0.0
16911691
# -r requirements/edx/base.txt
16921692
# edx-sga
16931693
# xblock-poll
1694-
xblocks-contrib==0.6.0
1694+
git+https://github.com/openedx/xblocks-contrib.git@problemblock
16951695
# via -r requirements/edx/base.txt
16961696
xmlsec==1.3.14
16971697
# via

xmodule/modulestore/tests/factories.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ def _create(cls, target_class, **kwargs): # lint-amnesty, pylint: disable=argum
397397
if 'boilerplate' in kwargs:
398398
template_id = kwargs.pop('boilerplate')
399399
clz = XBlock.load_class(category)
400-
template = clz.get_template(template_id)
400+
dynamic_clz = parent.runtime.mixologist.mix(clz)
401+
template = dynamic_clz.get_template(template_id)
401402
assert template is not None
402403
metadata.update(template.get('metadata', {}))
403404
if not isinstance(data, str):

xmodule/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def get_block(block):
164164

165165
descriptor_system.get_block_for_descriptor = get_block # lint-amnesty, pylint: disable=attribute-defined-outside-init
166166
descriptor_system._services.update(services) # lint-amnesty, pylint: disable=protected-access
167+
descriptor_system.render_template = Mock(side_effect=render_template)
167168

168169
return descriptor_system
169170

0 commit comments

Comments
 (0)