Commit 8024bae2 by muhammad-ammar

enforce display name in CAPA problems

FEDX-198
parent 849e3b79
......@@ -659,7 +659,7 @@ class CapaMixin(CapaFields):
check_button_checking = False
content = {
'name': self.display_name_with_default_escaped,
'name': self.display_name_with_default,
'html': html,
'weight': self.weight,
}
......
......@@ -128,6 +128,19 @@ class CapaModule(CapaMixin, XModule):
return json.dumps(result, cls=ComplexEncoder)
@property
def display_name_with_default(self):
"""
Constructs the display name for a CAPA problem.
Default to the display_name if it isn't None or not an empty string,
else fall back to problem category.
"""
if self.display_name is None or not self.display_name.strip():
return self.location.block_type
return self.display_name
class CapaDescriptor(CapaFields, RawDescriptor):
"""
......
......@@ -1719,6 +1719,34 @@ class CapaModuleTest(unittest.TestCase):
('answerpool', ['choice_1', 'choice_3', 'choice_2', 'choice_0']))
self.assertEquals(event_info['success'], 'incorrect')
@ddt.unpack
@ddt.data(
{'display_name': None, 'expected_display_name': 'problem'},
{'display_name': '', 'expected_display_name': 'problem'},
{'display_name': ' ', 'expected_display_name': 'problem'},
{'display_name': 'CAPA 101', 'expected_display_name': 'CAPA 101'}
)
def test_problem_display_name_with_default(self, display_name, expected_display_name):
"""
Verify that display_name_with_default works as expected.
"""
module = CapaFactory.create(display_name=display_name)
self.assertEqual(module.display_name_with_default, expected_display_name)
@ddt.data(
'',
' ',
)
def test_problem_no_display_name(self, display_name):
"""
Verify that if problem display name is not provided then a default name is used.
"""
module = CapaFactory.create(display_name=display_name)
module.get_problem_html()
render_args, _ = module.system.render_template.call_args
context = render_args[1]
self.assertEqual(context['problem']['name'], module.location.block_type)
@ddt.ddt
class CapaDescriptorTest(unittest.TestCase):
......
<%! from django.utils.translation import ugettext as _ %>
<%page expression_filter="h"/>
<%!
from django.utils.translation import ugettext as _
from openedx.core.djangolib.markup import HTML
%>
<%namespace name='static' file='static_content.html'/>
<h3 class="hd hd-2 problem-header">
......@@ -9,7 +13,7 @@
<div class="problem">
<div aria-live="polite">
${ problem['html'] }
${ HTML(problem['html']) }
</div>
<div class="action">
<input type="hidden" name="problem_id" value="${ problem['name'] }" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment