Merge pull request #2015 from cpennington/image-response-acceptance-tests
Add acceptance test of image response
This commit is contained in:
@@ -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"
|
||||
@@ -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
|
||||
@@ -66,6 +68,7 @@ Feature: LMS.Answer problems
|
||||
| script |
|
||||
| radio_text |
|
||||
| checkbox_text |
|
||||
| image |
|
||||
|
||||
|
||||
Scenario: I can reset a problem
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -14,11 +14,18 @@ from lettuce import world
|
||||
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
|
||||
@@ -158,6 +165,16 @@ PROBLEM_DICT = {
|
||||
},
|
||||
'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']}
|
||||
}
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user