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
c660229b
Commit
c660229b
authored
Mar 25, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added checking for problem answer state after a problem is checked
parent
30843610
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
5 deletions
+91
-5
lms/djangoapps/courseware/features/problems.feature
+4
-0
lms/djangoapps/courseware/features/problems.py
+87
-5
No files found.
lms/djangoapps/courseware/features/problems.feature
View file @
c660229b
...
...
@@ -8,6 +8,7 @@ Feature: Answer problems
And
I am viewing a
"<ProblemType>"
problem
When
I answer a
"<ProblemType>"
problem
"correctly"
Then
My
"<ProblemType>"
answer is marked
"correct"
And
The
"<ProblemType>"
problem displays a
"correct"
answer
Examples
:
|
ProblemType
|
...
...
@@ -25,6 +26,7 @@ Feature: Answer problems
And
I am viewing a
"<ProblemType>"
problem
When
I answer a
"<ProblemType>"
problem
"incorrectly"
Then
My
"<ProblemType>"
answer is marked
"incorrect"
And
The
"<ProblemType>"
problem displays a
"incorrect"
answer
Examples
:
|
ProblemType
|
...
...
@@ -41,6 +43,7 @@ Feature: Answer problems
Given
I am viewing a
"<ProblemType>"
problem
When
I check a problem
Then
My
"<ProblemType>"
answer is marked
"incorrect"
And
The
"<ProblemType>"
problem displays a
"blank"
answer
Examples
:
|
ProblemType
|
...
...
@@ -58,6 +61,7 @@ Feature: Answer problems
And
I answer a
"<ProblemType>"
problem
"<Correctness>ly"
When
I reset the problem
Then
My
"<ProblemType>"
answer is marked
"unanswered"
And
The
"<ProblemType>"
problem displays a
"blank"
answer
Examples
:
|
ProblemType
|
Correctness
|
...
...
lms/djangoapps/courseware/features/problems.py
View file @
c660229b
...
...
@@ -2,8 +2,8 @@ from lettuce import world, step
from
lettuce.django
import
django_url
import
random
import
textwrap
import
time
from
common
import
i_am_registered_for_the_course
,
TEST_SECTION_NAME
,
section_location
from
common
import
i_am_registered_for_the_course
,
\
TEST_SECTION_NAME
,
section_location
from
capa.tests.response_xml_factory
import
OptionResponseXMLFactory
,
\
ChoiceResponseXMLFactory
,
MultipleChoiceResponseXMLFactory
,
\
StringResponseXMLFactory
,
NumericalResponseXMLFactory
,
\
...
...
@@ -26,7 +26,7 @@ PROBLEM_FACTORY_DICT = {
'kwargs'
:
{
'question_text'
:
'The correct answer is Choice 3'
,
'choices'
:
[
False
,
False
,
True
,
False
],
'choice_names'
:
[
'choice_
1'
,
'choice_2'
,
'choice_3'
,
'choice_4
'
]}},
'choice_names'
:
[
'choice_
0'
,
'choice_1'
,
'choice_2'
,
'choice_3
'
]}},
'checkbox'
:
{
'factory'
:
ChoiceResponseXMLFactory
(),
...
...
@@ -152,9 +152,9 @@ def answer_problem(step, problem_type, correctness):
elif
problem_type
==
"multiple choice"
:
if
correctness
==
'correct'
:
inputfield
(
'multiple choice'
,
choice
=
'choice_3'
)
.
check
()
else
:
inputfield
(
'multiple choice'
,
choice
=
'choice_2'
)
.
check
()
else
:
inputfield
(
'multiple choice'
,
choice
=
'choice_1'
)
.
check
()
elif
problem_type
==
"checkbox"
:
if
correctness
==
'correct'
:
...
...
@@ -202,6 +202,65 @@ def answer_problem(step, problem_type, correctness):
# Submit the problem
check_problem
(
step
)
@step
(
u'The "([^"]*)" problem displays a "([^"]*)" answer'
)
def
assert_problem_has_answer
(
step
,
problem_type
,
answer_class
):
'''
Assert that the problem is displaying a particular answer.
These correspond to the same correct/incorrect
answers we set in answer_problem()
We can also check that a problem has been left blank
by setting answer_class='blank'
'''
assert
answer_class
in
[
'correct'
,
'incorrect'
,
'blank'
]
if
problem_type
==
"drop down"
:
if
answer_class
==
'blank'
:
assert
world
.
browser
.
is_element_not_present_by_css
(
'option[selected="true"]'
)
else
:
actual
=
world
.
browser
.
find_by_css
(
'option[selected="true"]'
)
.
value
expected
=
'Option 2'
if
answer_class
==
'correct'
else
'Option 3'
assert
actual
==
expected
elif
problem_type
==
"multiple choice"
:
if
answer_class
==
'correct'
:
assert_checked
(
'multiple choice'
,
[
'choice_2'
])
elif
answer_class
==
'incorrect'
:
assert_checked
(
'multiple choice'
,
[
'choice_1'
])
else
:
assert_checked
(
'multiple choice'
,
[])
elif
problem_type
==
"checkbox"
:
if
answer_class
==
'correct'
:
assert_checked
(
'checkbox'
,
[
'choice_0'
,
'choice_2'
])
elif
answer_class
==
'incorrect'
:
assert_checked
(
'checkbox'
,
[
'choice_3'
])
else
:
assert_checked
(
'checkbox'
,
[])
elif
problem_type
==
'string'
:
if
answer_class
==
'blank'
:
expected
=
''
else
:
expected
=
'correct string'
if
answer_class
==
'correct'
else
'incorrect'
assert_textfield
(
'string'
,
expected
)
elif
problem_type
==
'formula'
:
if
answer_class
==
'blank'
:
expected
=
''
else
:
expected
=
"x^2+2*x+y"
if
answer_class
==
'correct'
else
'x^2'
assert_textfield
(
'formula'
,
expected
)
else
:
# The other response types use random data,
# which would be difficult to check
# We trade input value coverage in the other tests for
# input type coverage in this test.
pass
@step
(
u'I check a problem'
)
def
check_problem
(
step
):
...
...
@@ -274,6 +333,7 @@ def assert_answer_mark(step, problem_type, correctness):
# Expect that we found the expected selector
assert
(
has_expected
)
def
inputfield
(
problem_type
,
choice
=
None
,
input_num
=
1
):
""" Return the <input> element for *problem_type*.
For example, if problem_type is 'string', return
...
...
@@ -289,8 +349,30 @@ def inputfield(problem_type, choice=None, input_num=1):
base
=
"_choice_"
if
problem_type
==
"multiple choice"
else
"_"
sel
=
sel
+
base
+
str
(
choice
)
# If the input element doesn't exist, fail immediately
assert
(
world
.
browser
.
is_element_present_by_css
(
sel
,
wait_time
=
4
))
# Retrieve the input element
return
world
.
browser
.
find_by_css
(
sel
)
def
assert_checked
(
problem_type
,
choices
):
'''
Assert that choice names given in *choices* are the only
ones checked.
Works for both radio and checkbox problems
'''
all_choices
=
[
'choice_0'
,
'choice_1'
,
'choice_2'
,
'choice_3'
]
for
ch
in
all_choices
:
el
=
inputfield
(
problem_type
,
choice
=
ch
)
if
ch
in
choices
:
assert
el
.
checked
else
:
assert
not
el
.
checked
def
assert_textfield
(
problem_type
,
expected_text
,
input_num
=
1
):
el
=
inputfield
(
problem_type
,
input_num
=
input_num
)
assert
el
.
value
==
expected_text
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