From 7e33dce1ab828de87c140bf0f3802cafc5cf9996 Mon Sep 17 00:00:00 2001 From: 0x29a Date: Wed, 26 Oct 2022 21:01:43 +0200 Subject: [PATCH] refactor: xmodule/conditional_module.py -> xmodule/conditional_block.py --- .../contentstore/tests/test_import.py | 8 +++---- .../contentstore/views/tests/test_preview.py | 4 ++-- ...nal_module.html => conditional_block.html} | 2 +- setup.py | 2 +- xmodule/capa_block.py | 4 ++-- ...itional_module.py => conditional_block.py} | 12 +++++----- xmodule/static_content.py | 2 +- xmodule/tests/test_conditional.py | 22 +++++++++---------- 8 files changed, 28 insertions(+), 28 deletions(-) rename lms/templates/{conditional_module.html => conditional_block.html} (91%) rename xmodule/{conditional_module.py => conditional_block.py} (97%) diff --git a/cms/djangoapps/contentstore/tests/test_import.py b/cms/djangoapps/contentstore/tests/test_import.py index 0f80667938..4994ba1180 100644 --- a/cms/djangoapps/contentstore/tests/test_import.py +++ b/cms/djangoapps/contentstore/tests/test_import.py @@ -192,24 +192,24 @@ class ContentStoreImportTest(ModuleStoreTestCase): ['conditional'], target_id=target_id ) - conditional_module = module_store.get_item( + conditional_block = module_store.get_item( target_id.make_usage_key('conditional', 'condone') ) - self.assertIsNotNone(conditional_module) + self.assertIsNotNone(conditional_block) different_course_id = module_store.make_course_key('edX', 'different_course', None) self.assertListEqual( [ target_id.make_usage_key('problem', 'choiceprob'), different_course_id.make_usage_key('html', 'for_testing_import_rewrites') ], - conditional_module.sources_list + conditional_block.sources_list ) self.assertListEqual( [ target_id.make_usage_key('html', 'congrats'), target_id.make_usage_key('html', 'secret_page') ], - conditional_module.show_tag_list + conditional_block.show_tag_list ) def test_rewrite_reference_value_dict_published(self): diff --git a/cms/djangoapps/contentstore/views/tests/test_preview.py b/cms/djangoapps/contentstore/views/tests/test_preview.py index a46f35cef5..0a0018854d 100644 --- a/cms/djangoapps/contentstore/views/tests/test_preview.py +++ b/cms/djangoapps/contentstore/views/tests/test_preview.py @@ -118,8 +118,8 @@ class GetPreviewHtmlTestCase(ModuleStoreTestCase): self.assertNotRegex(html, r"data-block-type=[\"\']test_aside[\"\']") self.assertNotRegex(html, "Aside rendered") - @mock.patch('xmodule.conditional_module.ConditionalBlock.is_condition_satisfied') - def test_preview_conditional_module_children_context(self, mock_is_condition_satisfied): + @mock.patch('xmodule.conditional_block.ConditionalBlock.is_condition_satisfied') + def test_preview_conditional_block_children_context(self, mock_is_condition_satisfied): """ Tests that when empty context is pass to children of ConditionalBlock it will not raise KeyError. """ diff --git a/lms/templates/conditional_module.html b/lms/templates/conditional_block.html similarity index 91% rename from lms/templates/conditional_module.html rename to lms/templates/conditional_block.html index 06a055e2a0..0b6c348cbd 100644 --- a/lms/templates/conditional_module.html +++ b/lms/templates/conditional_block.html @@ -19,7 +19,7 @@ def _message(reqm, message):

${_message(reqm, message)}

% else:

- ${_("You do not have access to this dependency module.")} + ${_("You do not have access to this dependency block.")}

% endif % endfor diff --git a/setup.py b/setup.py index a614cfd903..619cfe578a 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ XBLOCKS = [ "book = xmodule.template_module:TranslateCustomTagBlock", "annotatable = xmodule.annotatable_block:AnnotatableBlock", "chapter = xmodule.seq_module:SectionBlock", - "conditional = xmodule.conditional_module:ConditionalBlock", + "conditional = xmodule.conditional_block:ConditionalBlock", "course = xmodule.course_module:CourseBlock", "course_info = xmodule.html_module:CourseInfoBlock", "customtag = xmodule.template_module:CustomTagBlock", diff --git a/xmodule/capa_block.py b/xmodule/capa_block.py index 422bcbb643..e2496bf2ce 100644 --- a/xmodule/capa_block.py +++ b/xmodule/capa_block.py @@ -1410,14 +1410,14 @@ class ProblemBlock( Problem can be completely wrong. Pressing RESET button makes this function to return False. """ - # used by conditional module + # used by conditional block return self.lcp.done def is_attempted(self): """ Has the problem been attempted? - used by conditional module + used by conditional block """ return self.attempts > 0 diff --git a/xmodule/conditional_module.py b/xmodule/conditional_block.py similarity index 97% rename from xmodule/conditional_module.py rename to xmodule/conditional_block.py index 238d5564ff..54b8f6ca6c 100644 --- a/xmodule/conditional_module.py +++ b/xmodule/conditional_block.py @@ -102,7 +102,7 @@ class ConditionalBlock( sources_list = ReferenceList( display_name=_("Source Components"), help=_("The component location IDs of all source components that are used to determine whether a learner is " - "shown the content of this conditional module. Copy the component location ID of a component from its " + "shown the content of this conditional block. Copy the component location ID of a component from its " "Settings dialog in Studio."), scope=Scope.content ) @@ -110,7 +110,7 @@ class ConditionalBlock( conditional_attr = String( display_name=_("Conditional Attribute"), help=_("The attribute of the source components that determines whether a learner is shown the content of this " - "conditional module."), + "conditional block."), scope=Scope.content, default='correct', values=lambda: [{'display_name': xml_attr, 'value': xml_attr} @@ -120,7 +120,7 @@ class ConditionalBlock( conditional_value = String( display_name=_("Conditional Value"), help=_("The value that the conditional attribute of the source components must match before a learner is shown " - "the content of this conditional module."), + "the content of this conditional block."), scope=Scope.content, default='True' ) @@ -128,7 +128,7 @@ class ConditionalBlock( conditional_message = String( display_name=_("Blocked Content Message"), help=_("The message that is shown to learners when not all conditions are met to show the content of this " - "conditional module. Include {link} in the text of your message to give learners a direct link to " + "conditional block. Include {link} in the text of your message to give learners a direct link to " "required units. For example, 'You must complete {link} before you can access this unit'."), scope=Scope.content, default=_('You must complete {link} before you can access this unit.') @@ -219,7 +219,7 @@ class ConditionalBlock( if module is not None: # We do not want to log when module is None, and it is when requester # does not have access to the requested required module. - log.warning('Error in conditional module: \ + log.warning('Error in conditional block: \ required module {module} has no {module_attr}'.format(module=module, module_attr=attr_name)) return False @@ -284,7 +284,7 @@ class ConditionalBlock( if not self.is_condition_satisfied(): context = {'module': self, 'message': self.conditional_message} - html = self.runtime.service(self, 'mako').render_template('conditional_module.html', context) + html = self.runtime.service(self, 'mako').render_template('conditional_block.html', context) return json.dumps({'fragments': [{'content': html}], 'message': bool(self.conditional_message)}) fragments = [child.render(STUDENT_VIEW).to_dict() for child in self.get_display_items()] diff --git a/xmodule/static_content.py b/xmodule/static_content.py index b89d225a1b..0aee38db3a 100755 --- a/xmodule/static_content.py +++ b/xmodule/static_content.py @@ -21,7 +21,7 @@ from path import Path as path from xmodule.annotatable_block import AnnotatableBlock from xmodule.capa_block import ProblemBlock -from xmodule.conditional_module import ConditionalBlock +from xmodule.conditional_block import ConditionalBlock from xmodule.html_module import AboutBlock, CourseInfoBlock, HtmlBlock, StaticTabBlock from xmodule.library_content_module import LibraryContentBlock from xmodule.lti_module import LTIBlock diff --git a/xmodule/tests/test_conditional.py b/xmodule/tests/test_conditional.py index 6783ec7a33..00abe5f340 100644 --- a/xmodule/tests/test_conditional.py +++ b/xmodule/tests/test_conditional.py @@ -13,7 +13,7 @@ from web_fragments.fragment import Fragment from xblock.field_data import DictFieldData from xblock.fields import ScopeIds -from xmodule.conditional_module import ConditionalBlock +from xmodule.conditional_block import ConditionalBlock from xmodule.error_module import ErrorBlock from xmodule.modulestore.xml import CourseLocationManager, ImportSystem, XMLModuleStore from xmodule.tests import DATA_DIR, get_test_descriptor_system, get_test_system @@ -54,7 +54,7 @@ class ConditionalBlockFactory(xml.XmlImportFactory): class ConditionalFactory: """ - A helper class to create a conditional module and associated source and child modules + A helper class to create a conditional block and associated source and child blocks to allow for testing. """ @staticmethod @@ -114,7 +114,7 @@ class ConditionalFactory: system.descriptor_runtime = descriptor_system - # construct conditional module: + # construct conditional block: cond_location = BlockUsageLocator(CourseLocator("edX", "conditional_test", "test_run", deprecated=True), "conditional", "SampleConditional", deprecated=True) field_data = DictFieldData({ @@ -144,8 +144,8 @@ class ConditionalFactory: class ConditionalBlockBasicTest(unittest.TestCase): """ - Make sure that conditional module works, using mocks for - other modules. + Make sure that conditional block works, using mocks for + other blocks. """ def setUp(self): @@ -200,7 +200,7 @@ class ConditionalBlockBasicTest(unittest.TestCase): fragments = ajax['fragments'] assert not any(('This is a secret' in item['content']) for item in fragments) - @patch('xmodule.conditional_module.log') + @patch('xmodule.conditional_block.log') def test_conditional_with_staff_only_source_module(self, mock_log): modules = ConditionalFactory.create( self.test_system, @@ -233,8 +233,8 @@ class ConditionalBlockXmlTest(unittest.TestCase): @patch('xmodule.x_module.descriptor_global_local_resource_url') @patch.dict(settings.FEATURES, {'ENABLE_EDXNOTES': False}) - def test_conditional_module(self, _): - """Make sure that conditional module works""" + def test_conditional_block(self, _): + """Make sure that conditional block works""" # edx - HarvardX # cond_test - ER22x location = BlockUsageLocator(CourseLocator("HarvardX", "ER22x", "2013_Spring", deprecated=True), @@ -268,7 +268,7 @@ class ConditionalBlockXmlTest(unittest.TestCase): fragments = ajax['fragments'] assert any(('This is a secret' in item['content']) for item in fragments) - def test_conditional_module_with_empty_sources_list(self): + def test_conditional_block_with_empty_sources_list(self): """ If a ConditionalBlock is initialized with an empty sources_list, we assert that the sources_list is set via generating UsageKeys from the values in xml_attributes['sources'] @@ -292,7 +292,7 @@ class ConditionalBlockXmlTest(unittest.TestCase): assert conditional.sources_list[0] == BlockUsageLocator.from_string(conditional.xml_attributes['sources'])\ .replace(run=dummy_location.course_key.run) - def test_conditional_module_parse_sources(self): + def test_conditional_block_parse_sources(self): dummy_system = Mock() dummy_location = BlockUsageLocator(CourseLocator("edX", "conditional_test", "test_run"), "conditional", "SampleConditional") @@ -310,7 +310,7 @@ class ConditionalBlockXmlTest(unittest.TestCase): assert conditional.parse_sources(conditional.xml_attributes) == ['i4x://HarvardX/ER22x/poll_question/T15_poll', 'i4x://HarvardX/ER22x/poll_question/T16_poll'] - def test_conditional_module_parse_attr_values(self): + def test_conditional_block_parse_attr_values(self): root = '' xml_object = etree.XML(root) definition = ConditionalBlock.definition_from_xml(xml_object, Mock())[0]