Commit 7fcf02a0 by Victor Shnayder

Further refactor

- small Attribute and InputTypeBase interface changes to make things cleaner
- move html quoting into templates (use ${blah | h} syntax)
- converting input types to use new format.
parent 74e23546
......@@ -12,7 +12,7 @@
% endif
<p class="debug">${status}</p>
<input type="file" name="input_${id}" id="input_${id}" value="${value}" multiple="multiple" data-required_files="${required_files}" data-allowed_files="${allowed_files}"/>
<input type="file" name="input_${id}" id="input_${id}" value="${value}" multiple="multiple" data-required_files="${required_files|h}" data-allowed_files="${allowed_files|h}"/>
</div>
<div class="message">${msg|n}</div>
</section>
......@@ -2,7 +2,7 @@
<input type="hidden" name="input_${id}" id="input_${id}" class="javascriptinput_input"/>
<div class="javascriptinput_data" data-display_class="${display_class}"
data-problem_state="${problem_state}" data-params="${params}"
data-submission="${value}" data-evaluation="${evaluation}">
data-submission="${value|h}" data-evaluation="${msg|h}">
</div>
<div class="script_placeholder" data-src="/static/js/${display_file}"></div>
<div class="javascriptinput_container"></div>
......
......@@ -20,7 +20,7 @@
<div style="display:none;" name="${hidden}" inputid="input_${id}" />
% endif
<input type="text" name="input_${id}" id="input_${id}" value="${value}"
<input type="text" name="input_${id}" id="input_${id}" value="${value|h}"
% if do_math:
class="math"
% endif
......
......@@ -46,6 +46,19 @@ class OptionInputTest(unittest.TestCase):
self.assertEqual(context, expected)
def test_option_parsing(self):
f = inputtypes.OptionInput.parse_options
def check(input, options):
"""Take list of options, confirm that output is in the silly doubled format"""
expected = [(o, o) for o in options]
self.assertEqual(f(input), expected)
check("('a','b')", ['a', 'b'])
check("('a', 'b')", ['a', 'b'])
check("('a b','b')", ['a b', 'b'])
check("('My \"quoted\"place','b')", ['My \"quoted\"place', 'b'])
class ChoiceGroupTest(unittest.TestCase):
'''
Test choice groups, radio groups, and checkbox groups
......@@ -73,6 +86,7 @@ class ChoiceGroupTest(unittest.TestCase):
expected = {'id': 'sky_input',
'value': 'foil3',
'status': 'answered',
'msg': '',
'input_type': expected_input_type,
'choices': [('foil1', '<text>This is foil One.</text>'),
('foil2', '<text>This is foil Two.</text>'),
......@@ -119,12 +133,13 @@ class JavascriptInputTest(unittest.TestCase):
context = the_input._get_render_context()
expected = {'id': 'prob_1_2',
'status': 'unanswered',
'msg': '',
'value': '3',
'params': params,
'display_file': display_file,
'display_class': display_class,
'problem_state': problem_state,
'value': '3',
'evaluation': '',}
'problem_state': problem_state,}
self.assertEqual(context, expected)
......@@ -204,9 +219,6 @@ class FileSubmissionTest(unittest.TestCase):
element = etree.fromstring(xml_str)
escapedict = {'"': '&quot;'}
esc = lambda s: saxutils.escape(s, escapedict)
state = {'value': 'BumbleBee.py',
'status': 'incomplete',
'feedback' : {'message': '3'}, }
......@@ -220,8 +232,8 @@ class FileSubmissionTest(unittest.TestCase):
'msg': input_class.submitted_msg,
'value': 'BumbleBee.py',
'queue_len': '3',
'allowed_files': esc('["runme.py", "nooooo.rb", "ohai.java"]'),
'required_files': esc('["cookies.py"]')}
'allowed_files': '["runme.py", "nooooo.rb", "ohai.java"]',
'required_files': '["cookies.py"]'}
self.assertEqual(context, expected)
......
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