From 35adeafafdcc3a95af6db405dcc425d830f0d8d0 Mon Sep 17 00:00:00 2001 From: Irtaza Akram <51848298+irtazaakram@users.noreply.github.com> Date: Fri, 15 Aug 2025 20:44:04 +0500 Subject: [PATCH] fix: Allow tests for Extracted & Builtin Annotatable XBlock (#36246) Test Annotatable XBlock in both built-in and extracted modes to keep them in sync. Related to: https://github.com/openedx/edx-platform/issues/34841 --- xmodule/annotatable_block.py | 17 ++++++++++++---- xmodule/tests/test_annotatable_block.py | 27 ++++++++++++++++++++----- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/xmodule/annotatable_block.py b/xmodule/annotatable_block.py index 9dcc27198d..9883f6d7bd 100644 --- a/xmodule/annotatable_block.py +++ b/xmodule/annotatable_block.py @@ -202,8 +202,17 @@ class _BuiltInAnnotatableBlock( return fragment -AnnotatableBlock = ( - _ExtractedAnnotatableBlock if settings.USE_EXTRACTED_ANNOTATABLE_BLOCK - else _BuiltInAnnotatableBlock -) +AnnotatableBlock = None + + +def reset_class(): + """Reset class as per django settings flag""" + global AnnotatableBlock + AnnotatableBlock = ( + _ExtractedAnnotatableBlock if settings.USE_EXTRACTED_ANNOTATABLE_BLOCK else _BuiltInAnnotatableBlock + ) + return AnnotatableBlock + + +reset_class() AnnotatableBlock.__name__ = "AnnotatableBlock" diff --git a/xmodule/tests/test_annotatable_block.py b/xmodule/tests/test_annotatable_block.py index 3de253047a..fcecd073de 100644 --- a/xmodule/tests/test_annotatable_block.py +++ b/xmodule/tests/test_annotatable_block.py @@ -1,19 +1,19 @@ """Annotatable block tests""" -import unittest - +from django.test import TestCase +from django.test.utils import override_settings from lxml import etree from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator from xblock.field_data import DictFieldData from xblock.fields import ScopeIds -from xmodule.annotatable_block import AnnotatableBlock +from xmodule import annotatable_block from . import get_test_system -class AnnotatableBlockTestCase(unittest.TestCase): # lint-amnesty, pylint: disable=missing-class-docstring +class _AnnotatableBlockTestCaseBase(TestCase): # lint-amnesty, pylint: disable=missing-class-docstring sample_xml = ''' Read the text. @@ -31,9 +31,16 @@ class AnnotatableBlockTestCase(unittest.TestCase): # lint-amnesty, pylint: disa ''' + __test__ = False + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.annotatable_class = annotatable_block.reset_class() + def setUp(self): super().setUp() - self.annotatable = AnnotatableBlock( + self.annotatable = self.annotatable_class( get_test_system(), DictFieldData({'data': self.sample_xml}), ScopeIds(None, None, None, BlockUsageLocator(CourseLocator('org', 'course', 'run'), 'category', 'name')) @@ -142,3 +149,13 @@ class AnnotatableBlockTestCase(unittest.TestCase): # lint-amnesty, pylint: disa assert instructions is not None assert "Read the text." in instructions assert xmltree.find("instructions") is None + + +@override_settings(USE_EXTRACTED_ANNOTATABLE_BLOCK=True) +class ExtractedAnnotatableBlockTestCase(_AnnotatableBlockTestCaseBase): + __test__ = True + + +@override_settings(USE_EXTRACTED_ANNOTATABLE_BLOCK=False) +class BuiltInAnnotatableBlockTestCase(_AnnotatableBlockTestCaseBase): + __test__ = True