Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
problem-builder
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
problem-builder
Commits
3d01658f
Commit
3d01658f
authored
Jan 24, 2015
by
Braden MacDonald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get some of the tests passing
parent
59d2b222
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
87 additions
and
56 deletions
+87
-56
mentoring/components/choice.py
+21
-0
mentoring/components/questionnaire.py
+2
-3
mentoring/components/step.py
+3
-1
mentoring/components/templates/html/choice.html
+2
-3
mentoring/components/templates/html/mcqblock_choices.html
+1
-1
mentoring/components/templates/html/mcqblock_rating.html
+1
-1
mentoring/components/templates/html/mrqblock_choices.html
+1
-1
tests/unit/test_migration.py
+39
-0
tests/unit/test_step.py
+17
-46
No files found.
mentoring/components/choice.py
View file @
3d01658f
...
@@ -25,6 +25,8 @@
...
@@ -25,6 +25,8 @@
from
xblock.core
import
XBlock
from
xblock.core
import
XBlock
from
xblock.fields
import
Scope
,
String
from
xblock.fields
import
Scope
,
String
from
xblock.fragment
import
Fragment
from
xblockutils.resources
import
ResourceLoader
# Classes ###########################################################
# Classes ###########################################################
...
@@ -35,3 +37,22 @@ class ChoiceBlock(XBlock):
...
@@ -35,3 +37,22 @@ class ChoiceBlock(XBlock):
"""
"""
value
=
String
(
help
=
"Value of the choice when selected"
,
scope
=
Scope
.
content
,
default
=
""
)
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
=
""
)
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
mentoring/components/questionnaire.py
View file @
3d01658f
...
@@ -23,11 +23,10 @@
...
@@ -23,11 +23,10 @@
# Imports ###########################################################
# Imports ###########################################################
from
lxml
import
etree
from
xblock.core
import
XBlock
from
xblock.core
import
XBlock
from
xblock.fields
import
Scope
,
String
,
Float
from
xblock.fields
import
Scope
,
String
,
Float
from
xblock.fragment
import
Fragment
from
xblock.fragment
import
Fragment
from
xblockutils.resources
import
ResourceLoader
from
xblockutils.resources
import
ResourceLoader
from
.choice
import
ChoiceBlock
from
.choice
import
ChoiceBlock
...
@@ -67,7 +66,7 @@ class QuestionnaireAbstractBlock(XBlock, StepMixin):
...
@@ -67,7 +66,7 @@ class QuestionnaireAbstractBlock(XBlock, StepMixin):
block
.
question
=
xml_child
.
text
block
.
question
=
xml_child
.
text
elif
xml_child
.
tag
==
'message'
and
xml_child
.
get
(
'type'
)
==
'on-submit'
:
elif
xml_child
.
tag
==
'message'
and
xml_child
.
get
(
'type'
)
==
'on-submit'
:
block
.
message
=
(
xml_child
.
text
or
''
)
.
strip
()
block
.
message
=
(
xml_child
.
text
or
''
)
.
strip
()
el
se
:
el
if
xml_child
.
tag
is
not
etree
.
Comment
:
block
.
runtime
.
add_node_as_child
(
block
,
xml_child
,
id_generator
)
block
.
runtime
.
add_node_as_child
(
block
,
xml_child
,
id_generator
)
return
block
return
block
...
...
mentoring/components/step.py
View file @
3d01658f
...
@@ -9,10 +9,12 @@ class StepParentMixin(object):
...
@@ -9,10 +9,12 @@ class StepParentMixin(object):
Generator returning the usage_id for all of this XBlock's
Generator returning the usage_id for all of this XBlock's
children that are "Steps"
children that are "Steps"
"""
"""
step_ids
=
[]
for
child_id
in
self
.
children
:
for
child_id
in
self
.
children
:
child
=
self
.
runtime
.
get_block
(
child_id
)
child
=
self
.
runtime
.
get_block
(
child_id
)
if
isinstance
(
child
,
StepMixin
):
if
isinstance
(
child
,
StepMixin
):
yield
child_id
step_ids
.
append
(
child_id
)
return
step_ids
class
StepMixin
(
object
):
class
StepMixin
(
object
):
...
...
mentoring/components/templates/html/choice.html
View file @
3d01658f
<span
class=
"choice-text"
>
<span
class=
"choice-text"
>
{% if self.content %}{{ self.content }}{% endif %}
{% if self.content %}{{ self.content }}{% endif %}
{% for name, c in named_children %}
{{ child_content|safe }}
{{c.body_html|safe}}
{% endfor %}
</span>
</span>
\ No newline at end of file
mentoring/components/templates/html/mcqblock_choices.html
View file @
3d01658f
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
<div
class=
"choice-result fa icon-2x"
></div>
<div
class=
"choice-result fa icon-2x"
></div>
<label
class=
"choice-label"
>
<label
class=
"choice-label"
>
<input
class=
"choice-selector"
type=
"radio"
name=
"{{ self.name }}"
value=
"{{ choice.value }}"
{%
if
self
.
student_choice =
=
choice
.
value
%}
checked
{%
endif
%}
/>
<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>
</label>
<div
class=
"choice-tips"
></div>
<div
class=
"choice-tips"
></div>
</div>
</div>
...
...
mentoring/components/templates/html/mcqblock_rating.html
View file @
3d01658f
...
@@ -35,7 +35,7 @@
...
@@ -35,7 +35,7 @@
<div
class=
"choice"
>
<div
class=
"choice"
>
<div
class=
"choice-result fa icon-2x"
></div>
<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
%}
/>
<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>
</label>
<div
class=
"choice-tips"
></div>
<div
class=
"choice-tips"
></div>
</div>
</div>
...
...
mentoring/components/templates/html/mrqblock_choices.html
View file @
3d01658f
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
<input
class=
"choice-selector"
type=
"checkbox"
name=
"{{ self.name }}"
<input
class=
"choice-selector"
type=
"checkbox"
name=
"{{ self.name }}"
value=
"{{ choice.value }}"
value=
"{{ choice.value }}"
{%
if
choice
.
value
in
self
.
student_choices
%}
checked
{%
endif
%}
/>
{%
if
choice
.
value
in
self
.
student_choices
%}
checked
{%
endif
%}
/>
{{ choice.content|safe }}
{{ choice.
render.
content|safe }}
</label>
</label>
<div
class=
"choice-tips"
></div>
<div
class=
"choice-tips"
></div>
</div>
</div>
...
...
tests/unit/test_migration.py
0 → 100644
View file @
3d01658f
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
)
tests/unit/test_step.py
View file @
3d01658f
import
copy
import
unittest
import
unittest
from
mock
import
MagicMock
,
Mock
from
xblock.field_data
import
DictFieldData
from
mentoring.components.step
import
StepMixin
,
StepParentMixin
from
mock
import
Mock
from
mentoring
import
MentoringBlock
from
mentoring.step
import
StepMixin
,
StepParentMixin
class
Parent
(
StepParentMixin
):
class
Parent
(
StepParentMixin
):
def
get_children_objects
(
self
):
@property
return
list
(
self
.
_children
)
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
):
def
_set_children_for_test
(
self
,
*
children
):
self
.
_children
=
children
self
.
_children
=
children
for
child
in
self
.
_children
:
for
idx
,
child
in
enumerate
(
self
.
_children
)
:
try
:
try
:
child
.
parent
=
self
child
.
get_parent
=
lambda
:
self
child
.
scope_ids
=
Mock
(
usage_id
=
idx
)
except
AttributeError
:
except
AttributeError
:
pass
pass
...
@@ -36,7 +39,8 @@ class TestStepMixin(unittest.TestCase):
...
@@ -36,7 +39,8 @@ class TestStepMixin(unittest.TestCase):
step
=
Step
()
step
=
Step
()
block
.
_children
=
[
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
):
def
test_only_steps_are_returned
(
self
):
block
=
Parent
()
block
=
Parent
()
...
@@ -44,7 +48,8 @@ class TestStepMixin(unittest.TestCase):
...
@@ -44,7 +48,8 @@ class TestStepMixin(unittest.TestCase):
step2
=
Step
()
step2
=
Step
()
block
.
_set_children_for_test
(
step1
,
1
,
"2"
,
"Step"
,
NotAStep
(),
False
,
step2
,
NotAStep
())
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
):
def
test_proper_number_is_returned_for_step
(
self
):
block
=
Parent
()
block
=
Parent
()
...
@@ -79,37 +84,3 @@ class TestStepMixin(unittest.TestCase):
...
@@ -79,37 +84,3 @@ class TestStepMixin(unittest.TestCase):
self
.
assertFalse
(
step1
.
lonely_step
)
self
.
assertFalse
(
step1
.
lonely_step
)
self
.
assertFalse
(
step2
.
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment