Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx
edx-platform
Commits
3ced4bee
Commit
3ced4bee
authored
Feb 12, 2013
by
Vasyl Nakvasiuk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add `ConditionalDescriptor.definition_to_xml`, test_ajax_request, import_test, export_test
parent
4b612bd5
Hide whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
62 additions
and
13 deletions
+62
-13
common/lib/xmodule/xmodule/conditional_module.py
+20
-6
common/lib/xmodule/xmodule/poll_module.py
+1
-1
common/lib/xmodule/xmodule/tests/test_export.py
+2
-2
common/lib/xmodule/xmodule/tests/test_import.py
+2
-2
common/lib/xmodule/xmodule/tests/test_logic.py
+17
-0
common/test/data/conditional_and_poll/README
+0
-0
common/test/data/conditional_and_poll/README.md
+0
-0
common/test/data/conditional_and_poll/about/2013_Spring/overview.html
+0
-0
common/test/data/conditional_and_poll/about/2013_Spring/prerequisites.html
+0
-0
common/test/data/conditional_and_poll/about/2013_Spring/short_description.html
+0
-0
common/test/data/conditional_and_poll/about/2013_Spring/video.html
+0
-0
common/test/data/conditional_and_poll/chapter/Staff.xml
+0
-0
common/test/data/conditional_and_poll/course.xml
+2
-0
common/test/data/conditional_and_poll/course/2013_Spring.xml
+0
-0
common/test/data/conditional_and_poll/creating_course.xml
+0
-0
common/test/data/conditional_and_poll/info/2013_Spring/handouts.html
+0
-0
common/test/data/conditional_and_poll/info/2013_Spring/updates.html
+0
-0
common/test/data/conditional_and_poll/policies/2013_Spring/policy.json
+0
-0
common/test/data/conditional_and_poll/roots/2013_Spring.xml
+0
-0
common/test/data/conditional_and_poll/sequential/Problem_Demos.xml
+18
-0
common/test/data/conditional_and_poll/static/README
+0
-0
common/test/data/conditional_and_poll/static/images/course_image.jpg
+0
-0
common/test/data/conditional_and_poll/static/images/professor-sandel.jpg
+0
-0
common/test/data/poll/course.xml
+0
-2
No files found.
common/lib/xmodule/xmodule/conditional_module.py
View file @
3ced4bee
...
...
@@ -10,9 +10,10 @@ from pkg_resources import resource_string
from
xmodule.x_module
import
XModule
from
xmodule.modulestore
import
Location
from
xmodule.seq_module
import
SequenceDescriptor
from
xblock.core
import
String
,
Scope
from
xblock.core
import
String
,
Scope
,
List
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
log
=
logging
.
getLogger
(
'mitx.'
+
__name__
)
...
...
@@ -109,6 +110,8 @@ class ConditionalModule(XModule):
class
ConditionalDescriptor
(
SequenceDescriptor
):
"""Descriptor for conditional xmodule."""
_tag_name
=
'conditional'
module_class
=
ConditionalModule
filename_extension
=
"xml"
...
...
@@ -116,6 +119,8 @@ class ConditionalDescriptor(SequenceDescriptor):
stores_state
=
True
has_score
=
False
show_tag_list
=
List
(
help
=
"Poll answers"
,
scope
=
Scope
.
content
)
def
get_required_module_descriptors
(
self
):
"""TODO: Returns a list of XModuleDescritpor instances upon which this module depends, but are
not children of this module"""
...
...
@@ -152,9 +157,12 @@ class ConditionalDescriptor(SequenceDescriptor):
return
urls
children
=
[]
show_tag_list
=
[]
for
child
in
xml_object
:
if
child
.
tag
==
'show'
:
children
.
extend
(
parse_show_tag
(
child
))
location
=
parse_show_tag
(
child
)
children
.
extend
(
location
)
show_tag_list
.
extend
(
location
)
else
:
try
:
descriptor
=
system
.
process_xml
(
etree
.
tostring
(
child
))
...
...
@@ -162,11 +170,17 @@ class ConditionalDescriptor(SequenceDescriptor):
children
.
append
(
module_url
)
except
:
log
.
exception
(
"Unable to load child when parsing Conditional."
)
return
{},
children
return
{
'show_tag_list'
:
show_tag_list
},
children
def
definition_to_xml
(
self
,
resource_fs
):
xml_object
=
etree
.
Element
(
'sequential'
)
xml_object
=
etree
.
Element
(
self
.
_tag_name
)
for
child
in
self
.
get_children
():
xml_object
.
append
(
etree
.
fromstring
(
child
.
export_to_xml
(
resource_fs
)))
location
=
str
(
child
.
location
)
if
location
in
self
.
show_tag_list
:
show_str
=
'<{tag_name} sources="{sources}" />'
.
format
(
tag_name
=
'show'
,
sources
=
location
)
xml_object
.
append
(
etree
.
fromstring
(
show_str
))
else
:
xml_object
.
append
(
etree
.
fromstring
(
child
.
export_to_xml
(
resource_fs
)))
return
xml_object
common/lib/xmodule/xmodule/poll_module.py
View file @
3ced4bee
...
...
@@ -75,7 +75,7 @@ class PollModule(XModule):
'poll_answers'
:
self
.
poll_answers
,
'total'
:
sum
(
self
.
poll_answers
.
values
())
})
else
:
# return error message
else
:
# return error message
return
json
.
dumps
({
'error'
:
'Unknown Command!'
})
def
get_html
(
self
):
...
...
common/lib/xmodule/xmodule/tests/test_export.py
View file @
3ced4bee
...
...
@@ -98,8 +98,8 @@ class RoundTripTestCase(unittest.TestCase):
def
test_full_roundtrip
(
self
):
self
.
check_export_roundtrip
(
DATA_DIR
,
"full"
)
def
test_poll_roundtrip
(
self
):
self
.
check_export_roundtrip
(
DATA_DIR
,
"poll"
)
def
test_
conditional_and_
poll_roundtrip
(
self
):
self
.
check_export_roundtrip
(
DATA_DIR
,
"
conditional_and_
poll"
)
def
test_selfassessment_roundtrip
(
self
):
#Test selfassessment xmodule to see if it exports correctly
...
...
common/lib/xmodule/xmodule/tests/test_import.py
View file @
3ced4bee
...
...
@@ -319,7 +319,7 @@ class ImportTestCase(unittest.TestCase):
self
.
assertEqual
(
len
(
video
.
url_name
),
len
(
'video_'
)
+
12
)
def
test_poll_xmodule
(
self
):
modulestore
=
XMLModuleStore
(
DATA_DIR
,
course_dirs
=
[
'poll'
])
modulestore
=
XMLModuleStore
(
DATA_DIR
,
course_dirs
=
[
'
conditional_and_
poll'
])
course
=
modulestore
.
get_courses
()[
0
]
chapters
=
course
.
get_children
()
...
...
@@ -332,7 +332,7 @@ class ImportTestCase(unittest.TestCase):
location
=
Location
(
location
.
tag
,
location
.
org
,
location
.
course
,
'sequential'
,
'Problem_Demos'
)
module
=
modulestore
.
get_instance
(
course
.
id
,
location
)
self
.
assertEqual
(
len
(
module
.
children
),
1
)
self
.
assertEqual
(
len
(
module
.
children
),
2
)
def
test_error_on_import
(
self
):
'''Check that when load_error_module is false, an exception is raised, rather than returning an ErrorModule'''
...
...
common/lib/xmodule/xmodule/tests/test_logic.py
View file @
3ced4bee
...
...
@@ -4,6 +4,7 @@ import json
import
unittest
from
xmodule.poll_module
import
PollModule
from
xmodule.conditional_module
import
ConditionalModule
class
LogicTest
(
unittest
.
TestCase
):
...
...
@@ -46,3 +47,19 @@ class PollModuleTest(LogicTest):
self
.
assertEqual
(
total
,
2
)
self
.
assertDictEqual
(
callback
,
{
'objectName'
:
'Conditional'
})
self
.
assertEqual
(
self
.
xmodule
.
poll_answer
,
'No'
)
class
ConditionalModuleTest
(
LogicTest
):
xmodule_class
=
ConditionalModule
raw_model_data
=
{
'contents'
:
'Some content'
}
def
test_ajax_request
(
self
):
# Mock is_condition_satisfied
self
.
xmodule
.
is_condition_satisfied
=
lambda
:
True
response
=
self
.
ajax_request
(
'No'
,
{})
html
=
response
[
'html'
]
self
.
assertEqual
(
html
,
'Some content'
)
common/test/data/poll/README
→
common/test/data/
conditional_and_
poll/README
View file @
3ced4bee
File moved
common/test/data/poll/README.md
→
common/test/data/
conditional_and_
poll/README.md
View file @
3ced4bee
File moved
common/test/data/poll/about/2013_Spring/overview.html
→
common/test/data/
conditional_and_
poll/about/2013_Spring/overview.html
View file @
3ced4bee
File moved
common/test/data/poll/about/2013_Spring/prerequisites.html
→
common/test/data/
conditional_and_
poll/about/2013_Spring/prerequisites.html
View file @
3ced4bee
File moved
common/test/data/poll/about/2013_Spring/short_description.html
→
common/test/data/
conditional_and_
poll/about/2013_Spring/short_description.html
View file @
3ced4bee
File moved
common/test/data/poll/about/2013_Spring/video.html
→
common/test/data/
conditional_and_
poll/about/2013_Spring/video.html
View file @
3ced4bee
File moved
common/test/data/poll/chapter/Staff.xml
→
common/test/data/
conditional_and_
poll/chapter/Staff.xml
View file @
3ced4bee
File moved
common/test/data/conditional_and_poll/course.xml
0 → 120000
View file @
3ced4bee
roots/2013_Spring.xml
\ No newline at end of file
common/test/data/poll/course/2013_Spring.xml
→
common/test/data/
conditional_and_
poll/course/2013_Spring.xml
View file @
3ced4bee
File moved
common/test/data/poll/creating_course.xml
→
common/test/data/
conditional_and_
poll/creating_course.xml
View file @
3ced4bee
File moved
common/test/data/poll/info/2013_Spring/handouts.html
→
common/test/data/
conditional_and_
poll/info/2013_Spring/handouts.html
View file @
3ced4bee
File moved
common/test/data/poll/info/2013_Spring/updates.html
→
common/test/data/
conditional_and_
poll/info/2013_Spring/updates.html
View file @
3ced4bee
File moved
common/test/data/poll/policies/2013_Spring/policy.json
→
common/test/data/
conditional_and_
poll/policies/2013_Spring/policy.json
View file @
3ced4bee
File moved
common/test/data/poll/roots/2013_Spring.xml
→
common/test/data/
conditional_and_
poll/roots/2013_Spring.xml
View file @
3ced4bee
File moved
common/test/data/poll/sequential/Problem_Demos.xml
→
common/test/data/
conditional_and_
poll/sequential/Problem_Demos.xml
View file @
3ced4bee
...
...
@@ -9,5 +9,23 @@
<answer
id=
"No"
>
No
</answer>
<answer
id=
"Dont_know"
>
Don't know
</answer>
</poll_question>
<poll_question
id=
"second_poll"
display_name=
"second poll"
>
<h3>
What's the Right Thing to Do?
</h3>
<p>
Suppose four shipwrecked sailors are stranded at sea in a lifeboat, without
food or water. Would it be wrong for three of them to kill and eat the cabin
boy, in order to save their own lives?
</p>
<answer
id=
"Yes"
>
Yes
</answer>
<answer
id=
"No"
>
No
</answer>
<answer
id=
"Dont_know"
>
Don't know
</answer>
</poll_question>
</vertical>
<wrapper>
<!-- Test many show tags -->
<html>
Condition: first_poll - Yes
</html>
<conditional
sources=
"i4x://HarvardX/ER22x/poll_question/first_poll"
poll_answer=
"Yes"
>
<html>
In first condition.
</html>
<show
sources=
"i4x://HarvardX/ER22x/poll_question/second_poll"
/>
</conditional>
</wrapper>
</sequential>
common/test/data/poll/static/README
→
common/test/data/
conditional_and_
poll/static/README
View file @
3ced4bee
File moved
common/test/data/poll/static/images/course_image.jpg
→
common/test/data/
conditional_and_
poll/static/images/course_image.jpg
View file @
3ced4bee
File moved
common/test/data/poll/static/images/professor-sandel.jpg
→
common/test/data/
conditional_and_
poll/static/images/professor-sandel.jpg
View file @
3ced4bee
File moved
common/test/data/poll/course.xml
deleted
120000 → 0
View file @
4b612bd5
roots/2013_Spring.xml
\ No newline at end of file
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