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
37c7b470
Commit
37c7b470
authored
Jan 24, 2013
by
Diana Huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update comments and add new OpenEndedChild tests
parent
1f8db189
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
27 deletions
+78
-27
common/lib/xmodule/xmodule/openendedchild.py
+2
-2
common/lib/xmodule/xmodule/tests/test_combined_open_ended.py
+76
-25
No files found.
common/lib/xmodule/xmodule/openendedchild.py
View file @
37c7b470
...
@@ -112,7 +112,7 @@ class OpenEndedChild(object):
...
@@ -112,7 +112,7 @@ class OpenEndedChild(object):
pass
pass
def
latest_answer
(
self
):
def
latest_answer
(
self
):
"""
None
if not available"""
"""
Empty string
if not available"""
if
not
self
.
history
:
if
not
self
.
history
:
return
""
return
""
return
self
.
history
[
-
1
]
.
get
(
'answer'
,
""
)
return
self
.
history
[
-
1
]
.
get
(
'answer'
,
""
)
...
@@ -124,7 +124,7 @@ class OpenEndedChild(object):
...
@@ -124,7 +124,7 @@ class OpenEndedChild(object):
return
self
.
history
[
-
1
]
.
get
(
'score'
)
return
self
.
history
[
-
1
]
.
get
(
'score'
)
def
latest_post_assessment
(
self
,
system
):
def
latest_post_assessment
(
self
,
system
):
"""
None
if not available"""
"""
Empty string
if not available"""
if
not
self
.
history
:
if
not
self
.
history
:
return
""
return
""
return
self
.
history
[
-
1
]
.
get
(
'post_assessment'
,
""
)
return
self
.
history
[
-
1
]
.
get
(
'post_assessment'
,
""
)
...
...
common/lib/xmodule/xmodule/tests/test_combined_open_ended.py
View file @
37c7b470
...
@@ -31,43 +31,94 @@ class OpenEndedChildTest(unittest.TestCase):
...
@@ -31,43 +31,94 @@ class OpenEndedChildTest(unittest.TestCase):
definition
=
Mock
()
definition
=
Mock
()
descriptor
=
Mock
()
descriptor
=
Mock
()
def
setUp
(
self
):
self
.
openendedchild
=
OpenEndedChild
(
test_system
,
self
.
location
,
self
.
definition
,
self
.
descriptor
,
self
.
static_data
,
self
.
metadata
)
def
test_latest_answer_empty
(
self
):
def
test_latest_answer_empty
(
self
):
openendedchild
=
OpenEndedChild
(
test_system
,
self
.
location
,
answer
=
self
.
openendedchild
.
latest_answer
()
self
.
definition
,
self
.
descriptor
,
self
.
static_data
,
self
.
metadata
)
answer
=
openendedchild
.
latest_answer
()
self
.
assertEqual
(
answer
,
""
)
self
.
assertEqual
(
answer
,
""
)
def
test_latest_answer_nonempty
(
self
):
metadata
=
json
.
dumps
({
'attempts'
:
10
,
'history'
:
[{
'answer'
:
"Two"
},
{
'answer'
:
"Three"
}]})
openendedchild
=
OpenEndedChild
(
test_system
,
self
.
location
,
self
.
definition
,
self
.
descriptor
,
self
.
static_data
,
metadata
)
answer
=
openendedchild
.
latest_answer
()
self
.
assertEqual
(
answer
,
"Three"
)
def
test_latest_score_empty
(
self
):
def
test_latest_score_empty
(
self
):
openendedchild
=
OpenEndedChild
(
test_system
,
self
.
location
,
answer
=
self
.
openendedchild
.
latest_score
()
self
.
definition
,
self
.
descriptor
,
self
.
static_data
,
self
.
metadata
)
answer
=
openendedchild
.
latest_score
()
self
.
assertEqual
(
answer
,
None
)
self
.
assertEqual
(
answer
,
None
)
def
test_latest_score_nonempty
(
self
):
def
test_latest_post_assessment_empty
(
self
):
metadata
=
json
.
dumps
({
'attempts'
:
10
,
answer
=
self
.
openendedchild
.
latest_post_assessment
(
test_system
)
'history'
:
[{
'score'
:
3
},
{
'score'
:
2
}]})
self
.
assertEqual
(
answer
,
""
)
openendedchild
=
OpenEndedChild
(
test_system
,
self
.
location
,
self
.
definition
,
self
.
descriptor
,
self
.
static_data
,
metadata
)
answer
=
openendedchild
.
latest_score
()
self
.
assertEqual
(
answer
,
2
)
def
test_new_history_entry
(
self
):
def
test_new_history_entry
(
self
):
openendedchild
=
OpenEndedChild
(
test_system
,
self
.
location
,
self
.
definition
,
self
.
descriptor
,
self
.
static_data
,
self
.
metadata
)
new_answer
=
"New Answer"
new_answer
=
"New Answer"
openendedchild
.
new_history_entry
(
new_answer
)
self
.
openendedchild
.
new_history_entry
(
new_answer
)
answer
=
openendedchild
.
latest_answer
()
answer
=
self
.
openendedchild
.
latest_answer
()
self
.
assertEqual
(
answer
,
new_answer
)
self
.
assertEqual
(
answer
,
new_answer
)
#def test_record_latest_score(self):
new_answer
=
"Newer Answer"
self
.
openendedchild
.
new_history_entry
(
new_answer
)
answer
=
self
.
openendedchild
.
latest_answer
()
self
.
assertEqual
(
new_answer
,
answer
)
def
test_record_latest_score
(
self
):
new_answer
=
"New Answer"
self
.
openendedchild
.
new_history_entry
(
new_answer
)
new_score
=
3
self
.
openendedchild
.
record_latest_score
(
new_score
)
score
=
self
.
openendedchild
.
latest_score
()
self
.
assertEqual
(
score
,
3
)
new_score
=
4
self
.
openendedchild
.
new_history_entry
(
new_answer
)
self
.
openendedchild
.
record_latest_score
(
new_score
)
score
=
self
.
openendedchild
.
latest_score
()
self
.
assertEqual
(
score
,
4
)
def
test_record_latest_post_assessment
(
self
):
new_answer
=
"New Answer"
self
.
openendedchild
.
new_history_entry
(
new_answer
)
post_assessment
=
"Post assessment"
self
.
openendedchild
.
record_latest_post_assessment
(
post_assessment
)
self
.
assertEqual
(
post_assessment
,
self
.
openendedchild
.
latest_post_assessment
(
test_system
))
def
test_get_score
(
self
):
new_answer
=
"New Answer"
self
.
openendedchild
.
new_history_entry
(
new_answer
)
score
=
self
.
openendedchild
.
get_score
()
self
.
assertEqual
(
score
[
'score'
],
0
)
self
.
assertEqual
(
score
[
'total'
],
self
.
static_data
[
'max_score'
])
new_score
=
4
self
.
openendedchild
.
new_history_entry
(
new_answer
)
self
.
openendedchild
.
record_latest_score
(
new_score
)
score
=
self
.
openendedchild
.
get_score
()
self
.
assertEqual
(
score
[
'score'
],
new_score
)
self
.
assertEqual
(
score
[
'total'
],
self
.
static_data
[
'max_score'
])
def
test_reset
(
self
):
self
.
openendedchild
.
reset
(
test_system
)
state
=
json
.
loads
(
self
.
openendedchild
.
get_instance_state
())
self
.
assertEqual
(
state
[
'state'
],
OpenEndedChild
.
INITIAL
)
def
test_is_last_response_correct
(
self
):
new_answer
=
"New Answer"
self
.
openendedchild
.
new_history_entry
(
new_answer
)
self
.
openendedchild
.
record_latest_score
(
self
.
static_data
[
'max_score'
])
self
.
assertEqual
(
self
.
openendedchild
.
is_last_response_correct
(),
'correct'
)
self
.
openendedchild
.
new_history_entry
(
new_answer
)
self
.
openendedchild
.
record_latest_score
(
0
)
self
.
assertEqual
(
self
.
openendedchild
.
is_last_response_correct
(),
'incorrect'
)
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