Skip to content

Commit

Permalink
Merge pull request #2015 from cpennington/image-response-acceptance-t…
Browse files Browse the repository at this point in the history
…ests

Add acceptance test of image response
  • Loading branch information
cpennington committed Dec 20, 2013
2 parents 32fa35c + 194e0e9 commit 8e98c8c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
8 changes: 8 additions & 0 deletions lms/djangoapps/courseware/features/problems.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Feature: LMS.Answer problems
| code |
| radio_text |
| checkbox_text |
| image |

Scenario: I can answer a problem incorrectly
Given External graders respond "incorrect"
Expand All @@ -47,6 +48,7 @@ Feature: LMS.Answer problems
| code |
| radio_text |
| checkbox_text |
| image |

Scenario: I can submit a blank answer
Given I am viewing a "<ProblemType>" problem
Expand All @@ -66,6 +68,7 @@ Feature: LMS.Answer problems
| script |
| radio_text |
| checkbox_text |
| image |


Scenario: I can reset a problem
Expand Down Expand Up @@ -97,6 +100,8 @@ Feature: LMS.Answer problems
| radio_text | incorrect |
| checkbox_text | correct |
| checkbox_text | incorrect |
| image | correct |
| image | incorrect |


Scenario: I can answer a problem with one attempt correctly and not reset
Expand Down Expand Up @@ -157,6 +162,8 @@ Feature: LMS.Answer problems
| formula | incorrect | 1 point possible | 1 point possible |
| script | correct | 2/2 points | 2 points possible |
| script | incorrect | 2 points possible | 2 points possible |
| image | correct | 1/1 points | 1 point possible |
| image | incorrect | 1 point possible | 1 point possible |

Scenario: I can see my score on a problem to which I submit a blank answer
Given I am viewing a "<ProblemType>" problem
Expand All @@ -173,6 +180,7 @@ Feature: LMS.Answer problems
| numerical | 1 point possible |
| formula | 1 point possible |
| script | 2 points possible |
| image | 1 point possible |


Scenario: I can reset the correctness of a problem after changing my answer
Expand Down
48 changes: 43 additions & 5 deletions lms/djangoapps/courseware/features/problems_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@
import random
import textwrap
from common import section_location
from capa.tests.response_xml_factory import OptionResponseXMLFactory, \
ChoiceResponseXMLFactory, MultipleChoiceResponseXMLFactory, \
StringResponseXMLFactory, NumericalResponseXMLFactory, \
FormulaResponseXMLFactory, CustomResponseXMLFactory, \
CodeResponseXMLFactory, ChoiceTextResponseXMLFactory
from capa.tests.response_xml_factory import (
ChoiceResponseXMLFactory,
ChoiceTextResponseXMLFactory,
CodeResponseXMLFactory,
CustomResponseXMLFactory,
FormulaResponseXMLFactory,
ImageResponseXMLFactory,
MultipleChoiceResponseXMLFactory,
NumericalResponseXMLFactory,
OptionResponseXMLFactory,
StringResponseXMLFactory,
)


# Factories from capa.tests.response_xml_factory that we will use
Expand Down Expand Up @@ -158,6 +165,16 @@ def test_add_to_ten(expect,ans):
},
'correct': ['span.correct'],
'incorrect': ['span.incorrect'],
'unanswered': ['span.unanswered']},

'image': {
'factory': ImageResponseXMLFactory(),
'kwargs': {
'src': '/static/images/mit_dome.jpg',
'rectangle': '(50,50)-(100,100)'
},
'correct': ['span.correct'],
'incorrect': ['span.incorrect'],
'unanswered': ['span.unanswered']}
}

Expand Down Expand Up @@ -242,6 +259,27 @@ def answer_problem(course, problem_type, correctness):
input_value
)
world.css_check(inputfield(course, problem_type, choice=choice))
elif problem_type == 'image':
offset = 25 if correctness == "correct" else -25

def try_click():
image_selector = "#imageinput_i4x-{0.org}-{0.course}-problem-image_2_1".format(section_loc)
input_selector = "#input_i4x-{0.org}-{0.course}-problem-image_2_1".format(section_loc)

world.browser.execute_script('$("body").on("click", function(event) {console.log(event);})')

initial_input = world.css_value(input_selector)
world.wait_for_visible(image_selector)
image = world.css_find(image_selector).first
(image.action_chains
.move_to_element(image._element)
.move_by_offset(offset, offset)
.click()
.perform())

world.wait_for(lambda _: world.css_value(input_selector) != initial_input)

world.retry_on_exception(try_click)


def problem_has_answer(course, problem_type, answer_class):
Expand Down

0 comments on commit 8e98c8c

Please sign in to comment.