Files
edx-platform/xmodule/tests/test_error_module.py
0x29a cf1a7c616a refactor: remove error_descriptor_class and NonStaffErrorBlock
It's safe to remove this because non-staff [1] users cannot access [2]
an `ErrorBlock`. We were able to reproduce this with and without this commit
with the following results:
1. Staff users were seeing the `ErrorBlock`.
2. Non-staff users were getting an empty `<div class="vert-mod"></div>`.

In theory, error blocks should be hidden in the Learning MFE because of this
option [3]. However, when we manually set `hide_access_error_blocks` to
`False`, we kept getting identical results (with and without this commit), so
it looks that the removal `NonStaffErrorBlock` was just omitted at some point.

[1] a4ec4c1b8e/lms/djangoapps/courseware/access.py (L419-L436)
[2] a4ec4c1b8e/lms/djangoapps/courseware/access.py (L150-L151)
[3] 92ca176fde/lms/djangoapps/courseware/views/views.py (L1547-L1551)
2022-06-30 15:53:39 +02:00

45 lines
1.3 KiB
Python

"""
Tests for ErrorBlock
"""
import unittest
from opaque_keys.edx.locator import CourseLocator
from xmodule.error_module import ErrorBlock
from xmodule.modulestore.xml import CourseLocationManager
from xmodule.tests import get_test_system
from xmodule.x_module import STUDENT_VIEW
class SetupTestErrorBlock(unittest.TestCase):
"""Common setUp for use in ErrorBlock tests."""
def setUp(self):
super().setUp()
self.system = get_test_system()
self.course_id = CourseLocator('org', 'course', 'run')
self.location = self.course_id.make_usage_key('foo', 'bar')
self.valid_xml = "<problem>ABC \N{SNOWMAN}</problem>"
self.error_msg = "Error"
class TestErrorBlock(SetupTestErrorBlock):
"""
Tests for ErrorBlock
"""
def test_error_block_xml_rendering(self):
descriptor = ErrorBlock.from_xml(
self.valid_xml,
self.system,
CourseLocationManager(self.course_id),
self.error_msg
)
assert isinstance(descriptor, ErrorBlock)
descriptor.xmodule_runtime = self.system
context_repr = self.system.render(descriptor, STUDENT_VIEW).content
assert self.error_msg in context_repr
assert repr(self.valid_xml) in context_repr