Commit ecba779b by gradyward

Merge pull request #508 from edx/grady/ORA-668

Grady/Fix Assessment Rendering
parents ee97c2d6 6f4b3a8c
...@@ -80,9 +80,7 @@ class StudioMixin(object): ...@@ -80,9 +80,7 @@ class StudioMixin(object):
submission_start, submission_due = date_ranges[0] submission_start, submission_due = date_ranges[0]
assessments = self._assessments_editor_context(date_ranges[1:]) assessments = self._assessments_editor_context(date_ranges[1:])
used_assessments = set(assessments.keys()) - {'training'} used_assessments, unused_assessments = self._get_assessment_order_and_use()
all_assessments = set(['student_training', 'peer_assessment', 'self_assessment', 'example_based_assessment'])
unused_assessments = all_assessments - used_assessments
# Every rubric requires one criterion. If there is no criteria # Every rubric requires one criterion. If there is no criteria
# configured for the XBlock, return one empty default criterion, with # configured for the XBlock, return one empty default criterion, with
...@@ -247,3 +245,26 @@ class StudioMixin(object): ...@@ -247,3 +245,26 @@ class StudioMixin(object):
assessments['training'] = {'examples': [student_training_template], 'template': student_training_template} assessments['training'] = {'examples': [student_training_template], 'template': student_training_template}
return assessments return assessments
def _get_assessment_order_and_use(self):
"""
Returns the names of assessments that should be displayed to the author, in the format that
our template expects, and in the order in which they are currently stored in the OA problem
definition.
Returns:
Tuple of the form ((list of str), (list of str))
Between the two lists, all of the assessment modules that the author should see are displayed.
"""
used_assessments = []
for assessment in self.rubric_assessments:
used_assessments.append(
assessment['name'].replace('-','_')
)
# NOTE: This is a perfect opportunity to gate the author to allow or disallow Example Based Assessment.
all_assessments = {'student_training', 'peer_assessment', 'self_assessment', 'example_based_assessment'}
unused_assessments = list(all_assessments - set(used_assessments))
return used_assessments, unused_assessments
...@@ -7,6 +7,7 @@ import datetime as dt ...@@ -7,6 +7,7 @@ import datetime as dt
import pytz import pytz
from ddt import ddt, file_data from ddt import ddt, file_data
from .base import scenario, XBlockHandlerTestCase from .base import scenario, XBlockHandlerTestCase
import xml.etree.ElementTree as etree
@ddt @ddt
...@@ -157,6 +158,70 @@ class StudioViewTest(XBlockHandlerTestCase): ...@@ -157,6 +158,70 @@ class StudioViewTest(XBlockHandlerTestCase):
self.assertFalse(resp['is_released']) self.assertFalse(resp['is_released'])
self.assertIn('msg', resp) self.assertIn('msg', resp)
@scenario('data/example_based_assessment.xml')
def test_assessment_module_ordering_example_based(self, xblock):
self.assert_assessment_order_(xblock)
@scenario('data/basic_scenario.xml')
def test_assessment_module_ordering_basic(self, xblock):
self.assert_assessment_order_(xblock)
@scenario('data/self_then_peer.xml')
def test_assessment_module_ordering_self_peer(self, xblock):
self.assert_assessment_order_(xblock)
@scenario('data/student_training.xml')
def test_assessment_module_ordering_student_training(self, xblock):
self.assert_assessment_order_(xblock)
@scenario('data/self_only_scenario.xml')
def test_assessment_module_ordering_self_only(self, xblock):
self.assert_assessment_order_(xblock)
def assert_assessment_order_(self, xblock):
"""
Asserts that the assessment module editors are rendered in the correct order.
Renders the Studio View, and then examines the html body for the tags that we anticipate
to be in the tag for each editor, and compare the order. If it is anything besides
strictly increasing, we say that they rendered in the incorrect order.
"""
frag = self.runtime.render(xblock, 'studio_view')
frag = frag.body_html()
assessments_in_order = self._find_assessment_order(xblock)
assessment_indicies = [frag.find(assessment) for assessment in assessments_in_order]
# Asserts that for any pairwise comparison of elements n and n-1 in the lookup of indicies
# the value at n will be greater than n-1 (i.e. the place we find one ID is after the one before it)
self.assertTrue(
all(a < b for a, b in zip(assessment_indicies, assessment_indicies[1:]))
)
def _find_assessment_order(self, xblock):
"""
Finds the order that we anticipate HTML ID tags of the section editors within the settings editor.
Returns:
A list with the four setting editor IDs, in the the order that we would anticipate given
the Xblock's problem definition that is handed in.
"""
assessments = []
for assessment in xblock.rubric_assessments:
assessments.append(assessment['name'].replace('-', '_'))
all_assessments = {'student_training', 'peer_assessment', 'self_assessment', 'example_based_assessment'}
unused_assessments = list(all_assessments - set(assessments))
assessments.extend(unused_assessments)
id_dictionary = {
"example_based_assessment": "oa_ai_assessment_editor",
"peer_assessment": "oa_peer_assessment_editor",
"self_assessment": "oa_self_assessment_editor",
"student_training": "oa_student_training_editor"
}
return [id_dictionary[name] for name in assessments]
@scenario('data/basic_scenario.xml') @scenario('data/basic_scenario.xml')
def test_editor_context_assigns_labels(self, xblock): def test_editor_context_assigns_labels(self, xblock):
# Strip out any labels from criteria/options that may have been imported. # Strip out any labels from criteria/options that may have been imported.
...@@ -175,4 +240,3 @@ class StudioViewTest(XBlockHandlerTestCase): ...@@ -175,4 +240,3 @@ class StudioViewTest(XBlockHandlerTestCase):
self.assertEqual(criterion['label'], criterion['name']) self.assertEqual(criterion['label'], criterion['name'])
for option in criterion['options']: for option in criterion['options']:
self.assertEqual(option['label'], option['name']) self.assertEqual(option['label'], option['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