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
4ee8111c
Commit
4ee8111c
authored
Jul 16, 2013
by
Felix Sun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed monkey-patching persistent state bug.
parent
6b40c5cf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
15 deletions
+23
-15
common/lib/xmodule/xmodule/crowdsource_hinter.py
+2
-2
common/lib/xmodule/xmodule/tests/test_crowdsource_hinter.py
+15
-3
lms/djangoapps/instructor/tests/test_hint_manager.py
+6
-10
No files found.
common/lib/xmodule/xmodule/crowdsource_hinter.py
View file @
4ee8111c
...
...
@@ -126,7 +126,7 @@ class CrowdsourceHinterModule(CrowdsourceHinterFields, XModule):
-Lon-capa dependent.
-Assumes that the problem only has one part.
"""
return
str
(
float
(
answer
.
values
()[
0
])
)
return
str
(
answer
.
values
()[
0
]
)
def
formula_answer_to_str
(
self
,
answer
):
"""
...
...
@@ -207,7 +207,7 @@ class CrowdsourceHinterModule(CrowdsourceHinterFields, XModule):
"""
try
:
answer
=
self
.
answer_to_str
(
data
)
except
ValueError
:
except
(
ValueError
,
AttributeError
)
:
# Sometimes, we get an answer that's just not parsable. Do nothing.
log
.
exception
(
'Answer not parsable: '
+
str
(
data
))
return
...
...
common/lib/xmodule/xmodule/tests/test_crowdsource_hinter.py
View file @
4ee8111c
...
...
@@ -277,7 +277,7 @@ class CrowdsourceHinterTest(unittest.TestCase):
mock_module
=
CHModuleFactory
.
create
()
get
=
{
'response1'
:
'4'
}
parsed
=
mock_module
.
numerical_answer_to_str
(
get
)
self
.
assertTrue
(
parsed
==
'4
.0
'
)
self
.
assertTrue
(
parsed
==
'4'
)
def
test_formula_answer_to_str
(
self
):
"""
...
...
@@ -342,12 +342,24 @@ class CrowdsourceHinterTest(unittest.TestCase):
def
test_gethint_unparsable
(
self
):
"""
Someone submits a
hint that cannot be parsed into a flo
at.
Someone submits a
n answer that is in the wrong form
at.
- The answer should not be added to previous_answers.
"""
mock_module
=
CHModuleFactory
.
create
()
old_answers
=
copy
.
deepcopy
(
mock_module
.
previous_answers
)
json_in
=
{
'problem_name'
:
'fish'
}
json_in
=
'blah'
out
=
mock_module
.
get_hint
(
json_in
)
self
.
assertTrue
(
out
is
None
)
self
.
assertTrue
(
mock_module
.
previous_answers
==
old_answers
)
def
test_gethint_signature_error
(
self
):
"""
Someone submits an answer that cannot be calculated as a float.
Nothing should change.
"""
mock_module
=
CHModuleFactory
.
create
()
old_answers
=
copy
.
deepcopy
(
mock_module
.
previous_answers
)
json_in
=
{
'problem1'
:
'fish'
}
out
=
mock_module
.
get_hint
(
json_in
)
self
.
assertTrue
(
out
is
None
)
self
.
assertTrue
(
mock_module
.
previous_answers
==
old_answers
)
...
...
lms/djangoapps/instructor/tests/test_hint_manager.py
View file @
4ee8111c
...
...
@@ -2,7 +2,7 @@ import json
from
django.test.client
import
Client
,
RequestFactory
from
django.test.utils
import
override_settings
from
mock
import
MagicMock
from
mock
import
MagicMock
,
patch
from
courseware.models
import
XModuleContentField
from
courseware.tests.factories
import
ContentFactory
...
...
@@ -12,6 +12,8 @@ from student.tests.factories import UserFactory
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
import
unittest
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
class
HintManagerTest
(
ModuleStoreTestCase
):
...
...
@@ -140,12 +142,8 @@ class HintManagerTest(ModuleStoreTestCase):
"""
# Because add_hint accesses the xmodule, this test requires a bunch
# of monkey patching.
import
courseware.module_render
as
module_render
import
courseware.model_data
as
model_data
hinter
=
MagicMock
()
hinter
.
answer_signature
=
lambda
string
:
string
module_render
.
get_module
=
MagicMock
(
return_value
=
hinter
)
model_data
.
ModelDataCache
=
MagicMock
(
return_value
=
None
)
request
=
RequestFactory
()
post
=
request
.
post
(
self
.
url
,
{
'field'
:
'mod_queue'
,
...
...
@@ -154,14 +152,12 @@ class HintManagerTest(ModuleStoreTestCase):
'answer'
:
'3.14'
,
'hint'
:
'This is a new hint.'
})
post
.
user
=
'fake user'
view
.
add_hint
(
post
,
self
.
course_id
,
'mod_queue'
)
with
patch
(
'courseware.module_render.get_module'
,
MagicMock
(
return_value
=
hinter
)):
with
patch
(
'courseware.model_data.ModelDataCache'
,
MagicMock
(
return_value
=
None
)):
view
.
add_hint
(
post
,
self
.
course_id
,
'mod_queue'
)
problem_hints
=
XModuleContentField
.
objects
.
get
(
field_name
=
'mod_queue'
,
definition_id
=
self
.
problem_id
)
.
value
self
.
assertTrue
(
'3.14'
in
json
.
loads
(
problem_hints
))
# Reload the things we monkey-patched.
reload
(
module_render
)
reload
(
model_data
)
def
test_approve
(
self
):
"""
Check that instructors can approve hints. (Move them
...
...
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