From e41bb8462cc1796ad07eb5fbc24381665b9701f4 Mon Sep 17 00:00:00 2001 From: Will Daly Date: Fri, 15 Mar 2013 12:13:07 -0400 Subject: [PATCH] Added lettuce tests for script (customresponse) problems. Increased wait time for login screen to reduce false positives. --- common/djangoapps/terrain/steps.py | 2 +- .../courseware/features/problems.feature | 5 ++++ .../courseware/features/problems.py | 24 +++++++++++++++---- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/common/djangoapps/terrain/steps.py b/common/djangoapps/terrain/steps.py index 1f90113f46..50fe0faf39 100644 --- a/common/djangoapps/terrain/steps.py +++ b/common/djangoapps/terrain/steps.py @@ -136,7 +136,7 @@ def log_in(email, password): # This is complicated by the fact that sometimes a second #login_form # dialog loads, while the first one remains hidden. # We give them both time to load, starting with the second one. - world.browser.is_element_present_by_css('section.content-wrapper form#login_form', wait_time=2) + world.browser.is_element_present_by_css('section.content-wrapper form#login_form', wait_time=4) world.browser.is_element_present_by_css('form#login_form', wait_time=2) # For some reason, the page sometimes includes two #login_form diff --git a/lms/djangoapps/courseware/features/problems.feature b/lms/djangoapps/courseware/features/problems.feature index 12458537d0..8828ebc699 100644 --- a/lms/djangoapps/courseware/features/problems.feature +++ b/lms/djangoapps/courseware/features/problems.feature @@ -16,6 +16,7 @@ Feature: Answer choice problems | string | | numerical | | formula | + | script | Scenario: I can answer a problem incorrectly Given I am viewing a "" problem @@ -30,6 +31,7 @@ Feature: Answer choice problems | string | | numerical | | formula | + | script | Scenario: I can submit a blank answer Given I am viewing a "" problem @@ -44,6 +46,7 @@ Feature: Answer choice problems | string | | numerical | | formula | + | script | Scenario: I can reset a problem @@ -66,3 +69,5 @@ Feature: Answer choice problems | numerical | incorrect | | formula | correct | | formula | incorrect | + | script | correct | + | script | incorrect | diff --git a/lms/djangoapps/courseware/features/problems.py b/lms/djangoapps/courseware/features/problems.py index 3af4843c3c..0b5ecbe20a 100644 --- a/lms/djangoapps/courseware/features/problems.py +++ b/lms/djangoapps/courseware/features/problems.py @@ -154,6 +154,19 @@ def answer_problem(step, problem_type, correctness): textvalue = "x^2+2*x+y" if correctness == 'correct' else 'x^2' inputfield('formula').fill(textvalue) + elif problem_type == 'script': + # Correct answer is any two integers that sum to 10 + first_addend = random.randint(-100, 100) + second_addend = 10 - first_addend + + # If we want an incorrect answer, then change + # the second addend so they no longer sum to 10 + if correctness == 'incorrect': + second_addend += random.randint(1, 10) + + inputfield('script', input_num=1).fill(str(first_addend)) + inputfield('script', input_num=2).fill(str(second_addend)) + # Submit the problem check_problem(step) @@ -188,7 +201,8 @@ def assert_answer_mark(step, problem_type, correctness): 'checkbox': ['span.correct'], 'string': ['div.correct'], 'numerical': ['div.correct'], - 'formula': ['div.correct'], } + 'formula': ['div.correct'], + 'script': ['div.correct'], } incorrect_selectors = { 'drop down': ['span.incorrect'], 'multiple choice': ['label.choicegroup_incorrect', @@ -196,7 +210,8 @@ def assert_answer_mark(step, problem_type, correctness): 'checkbox': ['span.incorrect'], 'string': ['div.incorrect'], 'numerical': ['div.incorrect'], - 'formula': ['div.incorrect'], } + 'formula': ['div.incorrect'], + 'script': ['div.incorrect'] } assert(correctness in ['correct', 'incorrect', 'unanswered']) assert(problem_type in correct_selectors and problem_type in incorrect_selectors) @@ -229,7 +244,7 @@ def assert_answer_mark(step, problem_type, correctness): assert(world.browser.is_element_not_present_by_css(sel, wait_time=4)) -def inputfield(problem_type, choice=None): +def inputfield(problem_type, choice=None, input_num=1): """ Return the element for *problem_type*. For example, if problem_type is 'string', return the text field for the string problem in the test course. @@ -237,7 +252,8 @@ def inputfield(problem_type, choice=None): *choice* is the name of the checkbox input in a group of checkboxes. """ - sel = "input#input_i4x-edx-model_course-problem-%s_2_1" % problem_type.replace(" ", "_") + sel = ("input#input_i4x-edx-model_course-problem-%s_2_%s" % + (problem_type.replace(" ", "_"), str(input_num))) if choice is not None: base = "_choice_" if problem_type == "multiple choice" else "_"