Skip to content

Commit

Permalink
refactor: rename InheritanceMixin to InheritableFieldsMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
Cup0fCoffee committed Jan 9, 2025
1 parent 02d9f7c commit 9199188
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 52 deletions.
4 changes: 2 additions & 2 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@
############# XBlock Configuration ##########

# Import after sys.path fixup
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore.inheritance import InheritableFieldsMixin
from xmodule.x_module import XModuleMixin

# These are the Mixins that will be added to every Blocklike upon instantiation.
Expand All @@ -1008,7 +1008,7 @@
# (a) merge their functionality into the base Blocklike class, or
# (b) refactor their functionality out of the Blocklike objects and into the edx-platform block runtimes.
LmsBlockMixin,
InheritanceMixin,
InheritableFieldsMixin,
XModuleMixin,
EditInfoMixin,
AuthoringMixin,
Expand Down
6 changes: 3 additions & 3 deletions lms/djangoapps/courseware/field_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from edx_django_utils.cache import DEFAULT_REQUEST_CACHE
from xblock.field_data import FieldData

from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore.inheritance import InheritableFieldsMixin

NOTSET = object()
ENABLED_OVERRIDE_PROVIDERS_KEY = 'lms.djangoapps.courseware.field_overrides.enabled_providers.{course_id}'
Expand Down Expand Up @@ -234,7 +234,7 @@ def has(self, block, name):
# If this is an inheritable field and an override is set above,
# then we want to return False here, so the field_data uses the
# override and not the original value for this block.
inheritable = list(InheritanceMixin.fields.keys()) # pylint: disable=no-member
inheritable = list(InheritableFieldsMixin.fields.keys()) # pylint: disable=no-member
if name in inheritable:
for ancestor in _lineage(block):
if self.get_override(ancestor, name) is not NOTSET:
Expand All @@ -249,7 +249,7 @@ def default(self, block, name):
# The `default` method is overloaded by the field storage system to
# also handle inheritance.
if self.providers and not overrides_disabled():
inheritable = list(InheritanceMixin.fields.keys()) # pylint: disable=no-member
inheritable = list(InheritableFieldsMixin.fields.keys()) # pylint: disable=no-member
if name in inheritable:
for ancestor in _lineage(block):
value = self.get_override(ancestor, name)
Expand Down
4 changes: 2 additions & 2 deletions lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ def _make_mako_template_dirs(settings):

# Import after sys.path fixup
from xmodule.modulestore.edit_info import EditInfoMixin # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position
from xmodule.modulestore.inheritance import InheritanceMixin # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position
from xmodule.modulestore.inheritance import InheritableFieldsMixin # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position
from xmodule.x_module import XModuleMixin # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position

# These are the Mixins that will be added to every Blocklike upon instantiation.
Expand All @@ -1649,7 +1649,7 @@ def _make_mako_template_dirs(settings):
# (a) merge their functionality into the base Blocklike class, or
# (b) refactor their functionality out of the Blocklike objects and into the edx-platform block runtimes.
LmsBlockMixin,
InheritanceMixin,
InheritableFieldsMixin,
XModuleMixin,
EditInfoMixin,
)
Expand Down
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/xblock/runtime/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from xmodule.errortracker import make_error_tracker
from xmodule.contentstore.django import contentstore
from xmodule.modulestore.django import XBlockI18nService
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore.inheritance import InheritableFieldsMixin
from xmodule.services import EventPublishingService, RebindUserService, ProblemFeedbackService
from xmodule.util.sandboxing import SandboxService
from common.djangoapps.edxmako.services import MakoService
Expand Down Expand Up @@ -125,7 +125,7 @@ def __init__(
mixins=(
LmsBlockMixin, # Adds Non-deprecated LMS/Studio functionality
XBlockShim, # Adds deprecated LMS/Studio functionality / backwards compatibility
InheritanceMixin, # Adds inheritable fields common for all XBlocks
InheritableFieldsMixin, # Adds inheritable fields common for all XBlocks
),
default_class=None,
select=None,
Expand Down
14 changes: 9 additions & 5 deletions xmodule/modulestore/inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ def to_json(self, values): # lint-amnesty, pylint: disable=arguments-differ
for user_partition in values]


class InheritanceMixin(XBlockMixin):
"""Field definitions for inheritable fields."""
class InheritableFieldsMixin(XBlockMixin):
"""
Field definitions for inheritable fields.
Defines fields which the modulestore runtime treats as inheritable.
"""

graded = Boolean(
help="Whether this block contributes to the final course grade",
Expand Down Expand Up @@ -306,7 +310,7 @@ def compute_inherited_metadata(block):
else:
parent_metadata = {}
# add any of block's explicitly set fields to the inheriting list
for field in InheritanceMixin.fields.values(): # lint-amnesty, pylint: disable=no-member
for field in InheritableFieldsMixin.fields.values(): # lint-amnesty, pylint: disable=no-member
if field.is_set_on(block):
# inherited_settings values are json repr
parent_metadata[field.name] = field.read_json(block)
Expand Down Expand Up @@ -413,9 +417,9 @@ def default(self, block, name):


def inheriting_field_data(kvs):
"""Create an InheritanceFieldData that inherits the names in InheritanceMixin."""
"""Create an InheritanceFieldData that inherits the names in InheritableFieldsMixin."""
return InheritingFieldData(
inheritable_names=InheritanceMixin.fields.keys(), # lint-amnesty, pylint: disable=no-member
inheritable_names=InheritableFieldsMixin.fields.keys(), # lint-amnesty, pylint: disable=no-member
kvs=kvs,
)

Expand Down
4 changes: 2 additions & 2 deletions xmodule/modulestore/split_mongo/caching_descriptor_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from xmodule.modulestore import BlockData
from xmodule.modulestore.edit_info import EditInfoRuntimeMixin
from xmodule.modulestore.exceptions import ItemNotFoundError
from xmodule.modulestore.inheritance import InheritanceMixin, inheriting_field_data
from xmodule.modulestore.inheritance import InheritableFieldsMixin, inheriting_field_data
from xmodule.modulestore.split_mongo import BlockKey, CourseEnvelope
from xmodule.modulestore.split_mongo.definition_lazy_loader import DefinitionLazyLoader
from xmodule.modulestore.split_mongo.id_manager import SplitMongoIdManager
Expand Down Expand Up @@ -303,7 +303,7 @@ def _init_field_data_for_block(self, block):
field_decorator=field_decorator,
)

if InheritanceMixin in self.modulestore.xblock_mixins:
if InheritableFieldsMixin in self.modulestore.xblock_mixins:
field_data = inheriting_field_data(kvs)
else:
field_data = KvsFieldData(kvs)
Expand Down
4 changes: 2 additions & 2 deletions xmodule/modulestore/split_mongo/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -2103,7 +2103,7 @@ def create_xblock(
else:
inherited_settings = parent_xblock.xblock_kvs.inherited_settings.copy()
if fields is not None:
for field_name in inheritance.InheritanceMixin.fields: # lint-amnesty, pylint: disable=not-an-iterable
for field_name in inheritance.InheritableFieldsMixin.fields: # lint-amnesty, pylint: disable=not-an-iterable
if field_name in fields:
inherited_settings[field_name] = fields[field_name]

Expand Down Expand Up @@ -2644,7 +2644,7 @@ def inherit_settings(
# update the inheriting w/ what should pass to children
inheriting_settings = inherited_settings_map[block_key].copy()
block_fields = block_data.fields
for field_name in inheritance.InheritanceMixin.fields: # lint-amnesty, pylint: disable=not-an-iterable
for field_name in inheritance.InheritableFieldsMixin.fields: # lint-amnesty, pylint: disable=not-an-iterable
if field_name in block_fields:
inheriting_settings[field_name] = block_fields[field_name]

Expand Down
8 changes: 4 additions & 4 deletions xmodule/modulestore/tests/test_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from xblock.fields import ScopeIds
from xblock.test.tools import TestRuntime

from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore.inheritance import InheritableFieldsMixin


class TestXBlock(XBlock):
Expand All @@ -23,17 +23,17 @@ class TestXBlock(XBlock):


@ddt.ddt
class TestInheritanceMixin(unittest.TestCase):
class TestInheritableFieldsMixin(unittest.TestCase):
"""
Test Suite to verify various methods of the InheritanceMixin
Test Suite to verify various methods of the InheritableFieldsMixin
"""

def setUp(self):
"""
Create a test xblock with mock runtime.
"""
runtime = TestRuntime(
Mock(entry_point=XBlock.entry_point), mixins=[InheritanceMixin], services={'field-data': {}}
Mock(entry_point=XBlock.entry_point), mixins=[InheritableFieldsMixin], services={'field-data': {}}
)
self.xblock = runtime.construct_xblock_from_class(
TestXBlock, ScopeIds('user', 'TestXBlock', 'def_id', 'usage_id')
Expand Down
4 changes: 2 additions & 2 deletions xmodule/modulestore/tests/test_mixed_modulestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
ItemNotFoundError,
NoPathToItem,
)
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore.inheritance import InheritableFieldsMixin
from xmodule.modulestore.mixed import MixedModuleStore
from xmodule.modulestore.search import navigation_index, path_to_location
from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore
Expand Down Expand Up @@ -91,7 +91,7 @@ class CommonMixedModuleStoreSetup(CourseComparisonTest, OpenEdxEventsTestMixin):
'default_class': DEFAULT_CLASS,
'fs_root': DATA_DIR,
'render_template': RENDER_TEMPLATE,
'xblock_mixins': (EditInfoMixin, InheritanceMixin, LocationMixin, XModuleMixin),
'xblock_mixins': (EditInfoMixin, InheritableFieldsMixin, LocationMixin, XModuleMixin),
}
DOC_STORE_CONFIG = {
'host': HOST,
Expand Down
4 changes: 2 additions & 2 deletions xmodule/modulestore/tests/test_split_modulestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
ItemNotFoundError,
VersionConflictError
)
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore.inheritance import InheritableFieldsMixin
from xmodule.modulestore.split_mongo import BlockKey
from xmodule.modulestore.split_mongo.mongo_connection import CourseStructureCache
from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore
Expand Down Expand Up @@ -71,7 +71,7 @@ class SplitModuleTest(unittest.TestCase):
modulestore_options = {
'default_class': 'xmodule.hidden_block.HiddenBlock',
'fs_root': tempdir.mkdtemp_clean(),
'xblock_mixins': (InheritanceMixin, XModuleMixin, EditInfoMixin)
'xblock_mixins': (InheritableFieldsMixin, XModuleMixin, EditInfoMixin)
}

MODULESTORE = {
Expand Down
4 changes: 2 additions & 2 deletions xmodule/modulestore/tests/test_split_w_old_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator

from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore.inheritance import InheritableFieldsMixin
from xmodule.modulestore.mongo import DraftMongoModuleStore
from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore
from xmodule.modulestore.tests.mongo_connection import MONGO_HOST, MONGO_PORT_NUM
Expand Down Expand Up @@ -46,7 +46,7 @@ class SplitWMongoCourseBootstrapper(unittest.TestCase):
'default_class': 'xmodule.hidden_block.HiddenBlock',
'fs_root': '',
'render_template': mock.Mock(return_value=""),
'xblock_mixins': (InheritanceMixin, XModuleMixin)
'xblock_mixins': (InheritableFieldsMixin, XModuleMixin)
}

split_course_key = CourseLocator('test_org', 'test_course', 'runid', branch=ModuleStoreEnum.BranchName.draft)
Expand Down
4 changes: 2 additions & 2 deletions xmodule/modulestore/tests/test_xml_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from xblock.runtime import DictKeyValueStore, KvsFieldData, Runtime

from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore.inheritance import InheritableFieldsMixin
from xmodule.modulestore.tests.mongo_connection import MONGO_HOST, MONGO_PORT_NUM
from xmodule.modulestore.xml_importer import StaticContentImporter, _update_block_location
from xmodule.tests import DATA_DIR
Expand Down Expand Up @@ -107,7 +107,7 @@ def render_to_template_mock(*args):
pass


class StubXBlock(XModuleMixin, InheritanceMixin):
class StubXBlock(XModuleMixin, InheritableFieldsMixin):
"""
Stub XBlock used for testing.
"""
Expand Down
4 changes: 2 additions & 2 deletions xmodule/modulestore/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from xmodule.contentstore.mongo import MongoContentStore
from xmodule.modulestore.draft_and_published import ModuleStoreDraftAndPublished
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore.inheritance import InheritableFieldsMixin
from xmodule.modulestore.mixed import MixedModuleStore
from xmodule.modulestore.mongo.base import ModuleStoreEnum
from xmodule.modulestore.mongo.draft import DraftModuleStore
Expand Down Expand Up @@ -425,7 +425,7 @@ def asset_collection(self):
DATA_DIR = path(__file__).dirname().parent.parent / "tests" / "data" / "xml-course-root"
TEST_DATA_DIR = 'common/test/data/'

XBLOCK_MIXINS = (InheritanceMixin, XModuleMixin)
XBLOCK_MIXINS = (InheritableFieldsMixin, XModuleMixin)


MIXED_MODULESTORE_BOTH_SETUP = MixedModulestoreBuilder([
Expand Down
6 changes: 3 additions & 3 deletions xmodule/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from xmodule.mako_block import MakoDescriptorSystem
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.draft_and_published import ModuleStoreDraftAndPublished
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore.inheritance import InheritableFieldsMixin
from xmodule.modulestore.xml import CourseLocationManager
from xmodule.tests.helpers import StubReplaceURLService, mock_render_template, StubMakoService, StubUserService
from xmodule.util.sandboxing import SandboxService
Expand Down Expand Up @@ -235,7 +235,7 @@ def get_block(block):
# runtime.resources_fs=Mock(name='get_test_descriptor_system.resources_fs')
# runtime.error_tracker=Mock(name='get_test_descriptor_system.error_tracker')
# runtime.render_template=render_template or mock_render_template,
# runtime.mixins=(InheritanceMixin, XModuleMixin)
# runtime.mixins=(InheritableFieldsMixin, XModuleMixin)

return runtime

Expand All @@ -251,7 +251,7 @@ def get_test_descriptor_system(render_template=None, **kwargs):
resources_fs=Mock(name='get_test_descriptor_system.resources_fs'),
error_tracker=Mock(name='get_test_descriptor_system.error_tracker'),
render_template=render_template or mock_render_template,
mixins=(InheritanceMixin, XModuleMixin),
mixins=(InheritableFieldsMixin, XModuleMixin),
services={'field-data': field_data},
**kwargs
)
Expand Down
2 changes: 1 addition & 1 deletion xmodule/tests/test_capa_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ def test_closed(self):
due=self.yesterday_str)
assert block.closed()

@patch('xmodule.modulestore.inheritance.InheritanceMixin.course_end_date', new_callable=PropertyMock)
@patch('xmodule.modulestore.inheritance.InheritableFieldsMixin.course_end_date', new_callable=PropertyMock)
def test_closed_for_archive(self, mock_course_end_date):

# Utility to create a datetime object in the past
Expand Down
6 changes: 3 additions & 3 deletions xmodule/tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from xblock.runtime import DictKeyValueStore, KvsFieldData

from xmodule.fields import Date
from xmodule.modulestore.inheritance import InheritanceMixin, compute_inherited_metadata
from xmodule.modulestore.inheritance import InheritableFieldsMixin, compute_inherited_metadata
from xmodule.modulestore.xml import ImportSystem, LibraryXMLModuleStore, XMLModuleStore
from xmodule.tests import DATA_DIR
from xmodule.x_module import XModuleMixin
Expand Down Expand Up @@ -47,7 +47,7 @@ def __init__(self, load_error_blocks, library=False):
course_dir=course_dir,
error_tracker=error_tracker,
load_error_blocks=load_error_blocks,
mixins=(InheritanceMixin, XModuleMixin),
mixins=(InheritableFieldsMixin, XModuleMixin),
services={'field-data': KvsFieldData(DictKeyValueStore())},
)

Expand All @@ -67,7 +67,7 @@ def get_course(self, name):
modulestore = XMLModuleStore(
DATA_DIR,
source_dirs=[name],
xblock_mixins=(InheritanceMixin,),
xblock_mixins=(InheritableFieldsMixin,),
)
courses = modulestore.get_courses()
assert len(courses) == 1
Expand Down
Loading

0 comments on commit 9199188

Please sign in to comment.