refactor: delete class XmlDescriptor
It also adds `@XBlock.needs("i18n")` to `XModuleMixin` because this service is
required there.
This commit is contained in:
committed by
Piotr Surowiec
parent
8127d19115
commit
3380f88ab3
@@ -24,7 +24,7 @@ from xmodule.html_module import CourseInfoBlock # lint-amnesty, pylint: disable
|
||||
from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order
|
||||
|
||||
# # This should be in a class which inherits from XmlDescriptor
|
||||
# # This should be in a class which inherits from XModuleDescriptor
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import re
|
||||
|
||||
from lxml import etree
|
||||
from xblock.fields import Scope, String
|
||||
from xmodule.xml_module import XmlDescriptor # pylint: disable=unused-import
|
||||
|
||||
from .exceptions import SerializationError
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ from xmodule.tests import get_test_descriptor_system
|
||||
from xmodule.tests.xml import XModuleXmlImportTest
|
||||
from xmodule.tests.xml.factories import CourseFactory, ProblemFactory, SequenceFactory
|
||||
from xmodule.x_module import XModuleMixin
|
||||
from xmodule.xml_module import XmlDescriptor, deserialize_field, serialize_field
|
||||
from xmodule.xml_module import XmlMixin, deserialize_field, serialize_field
|
||||
|
||||
|
||||
class CrazyJsonString(String):
|
||||
@@ -65,7 +65,7 @@ class InheritingFieldDataTest(unittest.TestCase):
|
||||
Tests of InheritingFieldData.
|
||||
"""
|
||||
|
||||
class TestableInheritingXBlock(XmlDescriptor): # lint-amnesty, pylint: disable=abstract-method
|
||||
class TestableInheritingXBlock(XmlMixin): # lint-amnesty, pylint: disable=abstract-method
|
||||
"""
|
||||
An XBlock we can use in these tests.
|
||||
"""
|
||||
@@ -227,11 +227,15 @@ class InheritingFieldDataTest(unittest.TestCase):
|
||||
|
||||
|
||||
class EditableMetadataFieldsTest(unittest.TestCase):
|
||||
class TestableXmlXBlock(XmlMixin, XModuleMixin): # lint-amnesty, pylint: disable=abstract-method
|
||||
"""
|
||||
This is subclassing `XModuleMixin` to use metadata fields in the unmixed class.
|
||||
"""
|
||||
|
||||
def test_display_name_field(self):
|
||||
editable_fields = self.get_xml_editable_fields(DictFieldData({}))
|
||||
# Tests that the xblock fields (currently tags and name) get filtered out.
|
||||
# Also tests that xml_attributes is filtered out of XmlDescriptor.
|
||||
# Also tests that xml_attributes is filtered out of XmlMixin.
|
||||
assert 1 == len(editable_fields), editable_fields
|
||||
self.assert_field_values(
|
||||
editable_fields, 'display_name', XModuleMixin.display_name,
|
||||
@@ -334,13 +338,13 @@ class EditableMetadataFieldsTest(unittest.TestCase):
|
||||
def get_xml_editable_fields(self, field_data):
|
||||
runtime = get_test_descriptor_system()
|
||||
return runtime.construct_xblock_from_class(
|
||||
XmlDescriptor,
|
||||
self.TestableXmlXBlock,
|
||||
scope_ids=Mock(),
|
||||
field_data=field_data,
|
||||
).editable_metadata_fields
|
||||
|
||||
def get_descriptor(self, field_data):
|
||||
class TestModuleDescriptor(TestFields, XmlDescriptor): # lint-amnesty, pylint: disable=abstract-method
|
||||
class TestModuleDescriptor(TestFields, self.TestableXmlXBlock): # lint-amnesty, pylint: disable=abstract-method
|
||||
@property
|
||||
def non_editable_metadata_fields(self):
|
||||
non_editable_fields = super().non_editable_metadata_fields
|
||||
|
||||
@@ -279,6 +279,7 @@ class XModuleFields:
|
||||
)
|
||||
|
||||
|
||||
@XBlock.needs("i18n")
|
||||
class XModuleMixin(XModuleFields, XBlock):
|
||||
"""
|
||||
Fields and methods used by XModules internally.
|
||||
|
||||
@@ -8,14 +8,12 @@ import os
|
||||
|
||||
from lxml import etree
|
||||
from lxml.etree import ElementTree, XMLParser
|
||||
from xblock.core import XBlock, XML_NAMESPACES
|
||||
from xblock.core import XML_NAMESPACES
|
||||
from xblock.fields import Dict, Scope, ScopeIds
|
||||
from xblock.runtime import KvsFieldData
|
||||
from xmodule.modulestore import EdxJSONEncoder
|
||||
from xmodule.modulestore.inheritance import InheritanceKeyValueStore, own_metadata
|
||||
|
||||
from .x_module import XModuleMixin
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
# assume all XML files are persisted as utf-8.
|
||||
@@ -505,8 +503,3 @@ class XmlMixin:
|
||||
non_editable_fields = super().non_editable_metadata_fields
|
||||
non_editable_fields.append(XmlMixin.xml_attributes)
|
||||
return non_editable_fields
|
||||
|
||||
|
||||
@XBlock.needs("i18n")
|
||||
class XmlDescriptor(XmlMixin, XModuleMixin): # lint-amnesty, pylint: disable=abstract-method
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user