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
2f03b976
Commit
2f03b976
authored
Mar 17, 2015
by
E. Kolpakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Index dictionary for CapaDescriptor + extending tests to cover it
parent
b3ab7fce
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
4 deletions
+42
-4
common/lib/xmodule/xmodule/capa_module.py
+16
-0
common/lib/xmodule/xmodule/tests/test_capa_module.py
+26
-4
No files found.
common/lib/xmodule/xmodule/capa_module.py
View file @
2f03b976
...
@@ -113,6 +113,7 @@ class CapaDescriptor(CapaFields, RawDescriptor):
...
@@ -113,6 +113,7 @@ class CapaDescriptor(CapaFields, RawDescriptor):
Module implementing problems in the LON-CAPA format,
Module implementing problems in the LON-CAPA format,
as implemented by capa.capa_problem
as implemented by capa.capa_problem
"""
"""
INDEX_CONTENT_TYPE
=
'CAPA'
module_class
=
CapaModule
module_class
=
CapaModule
...
@@ -186,6 +187,21 @@ class CapaDescriptor(CapaFields, RawDescriptor):
...
@@ -186,6 +187,21 @@ class CapaDescriptor(CapaFields, RawDescriptor):
registered_tags
=
responsetypes
.
registry
.
registered_tags
()
registered_tags
=
responsetypes
.
registry
.
registered_tags
()
return
set
([
node
.
tag
for
node
in
tree
.
iter
()
if
node
.
tag
in
registered_tags
])
return
set
([
node
.
tag
for
node
in
tree
.
iter
()
if
node
.
tag
in
registered_tags
])
def
index_dictionary
(
self
):
"""
Return dictionary prepared with module content and type for indexing.
"""
result
=
super
(
CapaDescriptor
,
self
)
.
index_dictionary
()
if
not
result
:
result
=
{}
index
=
{
'content_type'
:
self
.
INDEX_CONTENT_TYPE
,
'problem_types'
:
list
(
self
.
problem_types
),
"display_name"
:
self
.
display_name
}
result
.
update
(
index
)
return
result
# Proxy to CapaModule for access to any of its attributes
# Proxy to CapaModule for access to any of its attributes
answer_available
=
module_attr
(
'answer_available'
)
answer_available
=
module_attr
(
'answer_available'
)
check_button_name
=
module_attr
(
'check_button_name'
)
check_button_name
=
module_attr
(
'check_button_name'
)
...
...
common/lib/xmodule/xmodule/tests/test_capa_module.py
View file @
2f03b976
...
@@ -1659,18 +1659,26 @@ class CapaModuleTest(unittest.TestCase):
...
@@ -1659,18 +1659,26 @@ class CapaModuleTest(unittest.TestCase):
@ddt.ddt
@ddt.ddt
class
CapaDescriptorTest
(
unittest
.
TestCase
):
class
CapaDescriptorTest
(
unittest
.
TestCase
):
def
_create_descriptor
(
self
,
xml
):
def
_create_descriptor
(
self
,
xml
,
name
=
None
):
""" Creates a CapaDescriptor to run test against """
""" Creates a CapaDescriptor to run test against """
descriptor
=
CapaDescriptor
(
get_test_system
(),
scope_ids
=
1
)
descriptor
=
CapaDescriptor
(
get_test_system
(),
scope_ids
=
1
)
descriptor
.
data
=
xml
descriptor
.
data
=
xml
if
name
:
descriptor
.
display_name
=
name
return
descriptor
return
descriptor
@ddt.data
(
*
responsetypes
.
registry
.
registered_tags
())
@ddt.data
(
*
responsetypes
.
registry
.
registered_tags
())
def
test_all_response_types
(
self
,
response_tag
):
def
test_all_response_types
(
self
,
response_tag
):
""" Tests that every registered response tag is correctly returned """
""" Tests that every registered response tag is correctly returned """
xml
=
"<problem><{response_tag}></{response_tag}></problem>"
.
format
(
response_tag
=
response_tag
)
xml
=
"<problem><{response_tag}></{response_tag}></problem>"
.
format
(
response_tag
=
response_tag
)
descriptor
=
self
.
_create_descriptor
(
xml
)
name
=
"Some Capa Problem"
descriptor
=
self
.
_create_descriptor
(
xml
,
name
=
name
)
self
.
assertEquals
(
descriptor
.
problem_types
,
{
response_tag
})
self
.
assertEquals
(
descriptor
.
problem_types
,
{
response_tag
})
self
.
assertEquals
(
descriptor
.
index_dictionary
(),
{
'content_type'
:
CapaDescriptor
.
INDEX_CONTENT_TYPE
,
'display_name'
:
name
,
'problem_types'
:
[
response_tag
]
})
def
test_response_types_ignores_non_response_tags
(
self
):
def
test_response_types_ignores_non_response_tags
(
self
):
xml
=
textwrap
.
dedent
(
"""
xml
=
textwrap
.
dedent
(
"""
...
@@ -1687,8 +1695,14 @@ class CapaDescriptorTest(unittest.TestCase):
...
@@ -1687,8 +1695,14 @@ class CapaDescriptorTest(unittest.TestCase):
</multiplechoiceresponse>
</multiplechoiceresponse>
</problem>
</problem>
"""
)
"""
)
descriptor
=
self
.
_create_descriptor
(
xml
)
name
=
"Test Capa Problem"
descriptor
=
self
.
_create_descriptor
(
xml
,
name
=
name
)
self
.
assertEquals
(
descriptor
.
problem_types
,
{
"multiplechoiceresponse"
})
self
.
assertEquals
(
descriptor
.
problem_types
,
{
"multiplechoiceresponse"
})
self
.
assertEquals
(
descriptor
.
index_dictionary
(),
{
'content_type'
:
CapaDescriptor
.
INDEX_CONTENT_TYPE
,
'display_name'
:
name
,
'problem_types'
:
[
"multiplechoiceresponse"
]
})
def
test_response_types_multiple_tags
(
self
):
def
test_response_types_multiple_tags
(
self
):
xml
=
textwrap
.
dedent
(
"""
xml
=
textwrap
.
dedent
(
"""
...
@@ -1710,8 +1724,16 @@ class CapaDescriptorTest(unittest.TestCase):
...
@@ -1710,8 +1724,16 @@ class CapaDescriptorTest(unittest.TestCase):
</optionresponse>
</optionresponse>
</problem>
</problem>
"""
)
"""
)
descriptor
=
self
.
_create_descriptor
(
xml
)
name
=
"Other Test Capa Problem"
descriptor
=
self
.
_create_descriptor
(
xml
,
name
=
name
)
self
.
assertEquals
(
descriptor
.
problem_types
,
{
"multiplechoiceresponse"
,
"optionresponse"
})
self
.
assertEquals
(
descriptor
.
problem_types
,
{
"multiplechoiceresponse"
,
"optionresponse"
})
self
.
assertEquals
(
descriptor
.
index_dictionary
(),
{
'content_type'
:
CapaDescriptor
.
INDEX_CONTENT_TYPE
,
'display_name'
:
name
,
'problem_types'
:
[
"optionresponse"
,
"multiplechoiceresponse"
]
}
)
class
ComplexEncoderTest
(
unittest
.
TestCase
):
class
ComplexEncoderTest
(
unittest
.
TestCase
):
...
...
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