Commit 37e7d68c by Will Daly

pep8 and pylint fixes

parent c660229b
'''
Steps for problem.feature lettuce tests
'''
from lettuce import world, step from lettuce import world, step
from lettuce.django import django_url from lettuce.django import django_url
import random import random
...@@ -88,6 +93,9 @@ PROBLEM_FACTORY_DICT = { ...@@ -88,6 +93,9 @@ PROBLEM_FACTORY_DICT = {
def add_problem_to_course(course, problem_type): def add_problem_to_course(course, problem_type):
'''
Add a problem to the course we have created using factories.
'''
assert(problem_type in PROBLEM_FACTORY_DICT) assert(problem_type in PROBLEM_FACTORY_DICT)
...@@ -98,11 +106,12 @@ def add_problem_to_course(course, problem_type): ...@@ -98,11 +106,12 @@ def add_problem_to_course(course, problem_type):
# Create a problem item using our generated XML # Create a problem item using our generated XML
# We set rerandomize=always in the metadata so that the "Reset" button # We set rerandomize=always in the metadata so that the "Reset" button
# will appear. # will appear.
problem_item = world.ItemFactory.create(parent_location=section_location(course), template_name = "i4x://edx/templates/problem/Blank_Common_Problem"
template="i4x://edx/templates/problem/Blank_Common_Problem", world.ItemFactory.create(parent_location=section_location(course),
display_name=str(problem_type), template=template_name,
data=problem_xml, display_name=str(problem_type),
metadata={'rerandomize': 'always'}) data=problem_xml,
metadata={'rerandomize': 'always'})
@step(u'I am viewing a "([^"]*)" problem') @step(u'I am viewing a "([^"]*)" problem')
...@@ -164,11 +173,13 @@ def answer_problem(step, problem_type, correctness): ...@@ -164,11 +173,13 @@ def answer_problem(step, problem_type, correctness):
inputfield('checkbox', choice='choice_3').check() inputfield('checkbox', choice='choice_3').check()
elif problem_type == 'string': elif problem_type == 'string':
textvalue = 'correct string' if correctness == 'correct' else 'incorrect' textvalue = 'correct string' if correctness == 'correct' \
else 'incorrect'
inputfield('string').fill(textvalue) inputfield('string').fill(textvalue)
elif problem_type == 'numerical': elif problem_type == 'numerical':
textvalue = "pi + 1" if correctness == 'correct' else str(random.randint(-2, 2)) textvalue = "pi + 1" if correctness == 'correct' \
else str(random.randint(-2, 2))
inputfield('numerical').fill(textvalue) inputfield('numerical').fill(textvalue)
elif problem_type == 'formula': elif problem_type == 'formula':
...@@ -202,6 +213,7 @@ def answer_problem(step, problem_type, correctness): ...@@ -202,6 +213,7 @@ def answer_problem(step, problem_type, correctness):
# Submit the problem # Submit the problem
check_problem(step) check_problem(step)
@step(u'The "([^"]*)" problem displays a "([^"]*)" answer') @step(u'The "([^"]*)" problem displays a "([^"]*)" answer')
def assert_problem_has_answer(step, problem_type, answer_class): def assert_problem_has_answer(step, problem_type, answer_class):
''' '''
...@@ -242,7 +254,8 @@ def assert_problem_has_answer(step, problem_type, answer_class): ...@@ -242,7 +254,8 @@ def assert_problem_has_answer(step, problem_type, answer_class):
if answer_class == 'blank': if answer_class == 'blank':
expected = '' expected = ''
else: else:
expected = 'correct string' if answer_class == 'correct' else 'incorrect' expected = 'correct string' if answer_class == 'correct' \
else 'incorrect'
assert_textfield('string', expected) assert_textfield('string', expected)
...@@ -286,7 +299,7 @@ CORRECTNESS_SELECTORS = { ...@@ -286,7 +299,7 @@ CORRECTNESS_SELECTORS = {
'string': ['div.correct'], 'string': ['div.correct'],
'numerical': ['div.correct'], 'numerical': ['div.correct'],
'formula': ['div.correct'], 'formula': ['div.correct'],
'script': ['div.correct'], 'script': ['div.correct'],
'code': ['span.correct']}, 'code': ['span.correct']},
'incorrect': {'drop down': ['span.incorrect'], 'incorrect': {'drop down': ['span.incorrect'],
...@@ -306,12 +319,14 @@ CORRECTNESS_SELECTORS = { ...@@ -306,12 +319,14 @@ CORRECTNESS_SELECTORS = {
'numerical': ['div.unanswered'], 'numerical': ['div.unanswered'],
'formula': ['div.unanswered'], 'formula': ['div.unanswered'],
'script': ['div.unanswered'], 'script': ['div.unanswered'],
'code': ['span.unanswered'] }} 'code': ['span.unanswered']}}
@step(u'My "([^"]*)" answer is marked "([^"]*)"') @step(u'My "([^"]*)" answer is marked "([^"]*)"')
def assert_answer_mark(step, problem_type, correctness): def assert_answer_mark(step, problem_type, correctness):
""" Assert that the expected answer mark is visible for a given problem type. """
Assert that the expected answer mark is visible
for a given problem type.
*problem_type* is a string identifying the type of problem (e.g. 'drop down') *problem_type* is a string identifying the type of problem (e.g. 'drop down')
*correctness* is in ['correct', 'incorrect', 'unanswered'] *correctness* is in ['correct', 'incorrect', 'unanswered']
...@@ -349,13 +364,14 @@ def inputfield(problem_type, choice=None, input_num=1): ...@@ -349,13 +364,14 @@ def inputfield(problem_type, choice=None, input_num=1):
base = "_choice_" if problem_type == "multiple choice" else "_" base = "_choice_" if problem_type == "multiple choice" else "_"
sel = sel + base + str(choice) sel = sel + base + str(choice)
# If the input element doesn't exist, fail immediately # If the input element doesn't exist, fail immediately
assert(world.browser.is_element_present_by_css(sel, wait_time=4)) assert(world.browser.is_element_present_by_css(sel, wait_time=4))
# Retrieve the input element # Retrieve the input element
return world.browser.find_by_css(sel) return world.browser.find_by_css(sel)
def assert_checked(problem_type, choices): def assert_checked(problem_type, choices):
''' '''
Assert that choice names given in *choices* are the only Assert that choice names given in *choices* are the only
...@@ -365,14 +381,15 @@ def assert_checked(problem_type, choices): ...@@ -365,14 +381,15 @@ def assert_checked(problem_type, choices):
''' '''
all_choices = ['choice_0', 'choice_1', 'choice_2', 'choice_3'] all_choices = ['choice_0', 'choice_1', 'choice_2', 'choice_3']
for ch in all_choices: for this_choice in all_choices:
el = inputfield(problem_type, choice=ch) element = inputfield(problem_type, choice=this_choice)
if ch in choices: if this_choice in choices:
assert el.checked assert element.checked
else: else:
assert not el.checked assert not element.checked
def assert_textfield(problem_type, expected_text, input_num=1): def assert_textfield(problem_type, expected_text, input_num=1):
el = inputfield(problem_type, input_num=input_num) element = inputfield(problem_type, input_num=input_num)
assert el.value == expected_text assert element.value == expected_text
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment