Commit 3d01658f by Braden MacDonald

Get some of the tests passing

parent 59d2b222
......@@ -25,6 +25,8 @@
from xblock.core import XBlock
from xblock.fields import Scope, String
from xblock.fragment import Fragment
from xblockutils.resources import ResourceLoader
# Classes ###########################################################
......@@ -35,3 +37,22 @@ class ChoiceBlock(XBlock):
"""
value = String(help="Value of the choice when selected", scope=Scope.content, default="")
content = String(help="Human-readable version of the choice value", scope=Scope.content, default="")
has_children = True
def render(self):
"""
Returns a fragment containing the formatted choice
"""
fragment = Fragment()
child_content = u""
for child_id in self.children:
child = self.runtime.get_block(child_id)
child_fragment = child.render('mentoring_view', {})
fragment.add_frag_resources(child_fragment)
child_content += child_fragment.content
fragment.add_content(ResourceLoader(__name__).render_template('templates/html/choice.html', {
'self': self,
'child_content': child_content,
}))
return fragment # TODO: fragment_text_rewriting
......@@ -23,11 +23,10 @@
# Imports ###########################################################
from lxml import etree
from xblock.core import XBlock
from xblock.fields import Scope, String, Float
from xblock.fragment import Fragment
from xblockutils.resources import ResourceLoader
from .choice import ChoiceBlock
......@@ -67,7 +66,7 @@ class QuestionnaireAbstractBlock(XBlock, StepMixin):
block.question = xml_child.text
elif xml_child.tag == 'message' and xml_child.get('type') == 'on-submit':
block.message = (xml_child.text or '').strip()
else:
elif xml_child.tag is not etree.Comment:
block.runtime.add_node_as_child(block, xml_child, id_generator)
return block
......
......@@ -9,10 +9,12 @@ class StepParentMixin(object):
Generator returning the usage_id for all of this XBlock's
children that are "Steps"
"""
step_ids = []
for child_id in self.children:
child = self.runtime.get_block(child_id)
if isinstance(child, StepMixin):
yield child_id
step_ids.append(child_id)
return step_ids
class StepMixin(object):
......
<span class="choice-text">
{% if self.content %}{{ self.content }}{% endif %}
{% for name, c in named_children %}
{{c.body_html|safe}}
{% endfor %}
{{ child_content|safe }}
</span>
\ No newline at end of file
......@@ -9,7 +9,7 @@
<div class="choice-result fa icon-2x"></div>
<label class="choice-label">
<input class="choice-selector" type="radio" name="{{ self.name }}" value="{{ choice.value }}"{% if self.student_choice == choice.value %} checked{% endif %} />
{{ choice.content|safe }}
{{ choice.render.content|safe }}
</label>
<div class="choice-tips"></div>
</div>
......
......@@ -35,7 +35,7 @@
<div class="choice">
<div class="choice-result fa icon-2x"></div>
<label><input type="radio" name="{{ self.name }}" value="{{ choice.value }}"{% if self.student_choice == '{{ choice.value }}' %} checked{% endif %} />
{{ choice.content|safe }}
{{ choice.render.content|safe }}
</label>
<div class="choice-tips"></div>
</div>
......
......@@ -11,7 +11,7 @@
<input class="choice-selector" type="checkbox" name="{{ self.name }}"
value="{{ choice.value }}"
{% if choice.value in self.student_choices %} checked{% endif %} />
{{ choice.content|safe }}
{{ choice.render.content|safe }}
</label>
<div class="choice-tips"></div>
</div>
......
import copy
from mentoring import MentoringBlock
from mock import MagicMock, Mock
import unittest
from xblock.field_data import DictFieldData
class TestFieldMigration(unittest.TestCase):
"""
Test mentoring fields data migration
"""
def test_partial_completion_status_migration(self):
"""
Changed `completed` to `status` in `self.student_results` to accomodate partial responses
"""
# Instantiate a mentoring block with the old format
student_results = [
[ u'goal',
{ u'completed': True,
u'score': 1,
u'student_input': u'test',
u'weight': 1}],
[ u'mcq_1_1',
{ u'completed': False,
u'score': 0,
u'submission': u'maybenot',
u'weight': 1}],
]
mentoring = MentoringBlock(MagicMock(), DictFieldData({'student_results': student_results}), Mock())
self.assertEqual(copy.deepcopy(student_results), mentoring.student_results)
migrated_student_results = copy.deepcopy(student_results)
migrated_student_results[0][1]['status'] = 'correct'
migrated_student_results[1][1]['status'] = 'incorrect'
del migrated_student_results[0][1]['completed']
del migrated_student_results[1][1]['completed']
mentoring.migrate_fields()
self.assertEqual(migrated_student_results, mentoring.student_results)
import copy
import unittest
from mock import MagicMock, Mock
from xblock.field_data import DictFieldData
from mentoring import MentoringBlock
from mentoring.step import StepMixin, StepParentMixin
from mentoring.components.step import StepMixin, StepParentMixin
from mock import Mock
class Parent(StepParentMixin):
def get_children_objects(self):
return list(self._children)
@property
def children(self):
""" Return an ID for each of our chilren"""
return range(0, len(self._children))
@property
def runtime(self):
return Mock(get_block=lambda i: self._children[i])
def _set_children_for_test(self, *children):
self._children = children
for child in self._children:
for idx, child in enumerate(self._children):
try:
child.parent = self
child.get_parent = lambda: self
child.scope_ids = Mock(usage_id=idx)
except AttributeError:
pass
......@@ -36,7 +39,8 @@ class TestStepMixin(unittest.TestCase):
step = Step()
block._children = [step]
self.assertSequenceEqual(block.steps, [step])
steps = [block.runtime.get_block(cid) for cid in block.steps]
self.assertSequenceEqual(steps, [step])
def test_only_steps_are_returned(self):
block = Parent()
......@@ -44,7 +48,8 @@ class TestStepMixin(unittest.TestCase):
step2 = Step()
block._set_children_for_test(step1, 1, "2", "Step", NotAStep(), False, step2, NotAStep())
self.assertSequenceEqual(block.steps, [step1, step2])
steps = [block.runtime.get_block(cid) for cid in block.steps]
self.assertSequenceEqual(steps, [step1, step2])
def test_proper_number_is_returned_for_step(self):
block = Parent()
......@@ -79,37 +84,3 @@ class TestStepMixin(unittest.TestCase):
self.assertFalse(step1.lonely_step)
self.assertFalse(step2.lonely_step)
class TestFieldMigration(unittest.TestCase):
"""
Test mentoring fields data migration
"""
def test_partial_completion_status_migration(self):
"""
Changed `completed` to `status` in `self.student_results` to accomodate partial responses
"""
# Instantiate a mentoring block with the old format
student_results = [
[ u'goal',
{ u'completed': True,
u'score': 1,
u'student_input': u'test',
u'weight': 1}],
[ u'mcq_1_1',
{ u'completed': False,
u'score': 0,
u'submission': u'maybenot',
u'weight': 1}],
]
mentoring = MentoringBlock(MagicMock(), DictFieldData({'student_results': student_results}), Mock())
self.assertEqual(copy.deepcopy(student_results), mentoring.student_results)
migrated_student_results = copy.deepcopy(student_results)
migrated_student_results[0][1]['status'] = 'correct'
migrated_student_results[1][1]['status'] = 'incorrect'
del migrated_student_results[0][1]['completed']
del migrated_student_results[1][1]['completed']
mentoring.migrate_fields()
self.assertEqual(migrated_student_results, mentoring.student_results)
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