Commit e7f8c7c6 by Will Daly

pep8 fixes

parent 39aa25c2
...@@ -7,6 +7,7 @@ import time ...@@ -7,6 +7,7 @@ import time
from logging import getLogger from logging import getLogger
logger = getLogger(__name__) logger = getLogger(__name__)
class MockXQueueRequestHandler(BaseHTTPRequestHandler): class MockXQueueRequestHandler(BaseHTTPRequestHandler):
''' '''
A handler for XQueue POST requests. A handler for XQueue POST requests.
...@@ -31,7 +32,7 @@ class MockXQueueRequestHandler(BaseHTTPRequestHandler): ...@@ -31,7 +32,7 @@ class MockXQueueRequestHandler(BaseHTTPRequestHandler):
post_dict = self._post_dict() post_dict = self._post_dict()
# Log the request # Log the request
logger.debug("XQueue received POST request %s to path %s" % logger.debug("XQueue received POST request %s to path %s" %
(str(post_dict), self.path)) (str(post_dict), self.path))
# Respond only to grading requests # Respond only to grading requests
...@@ -52,12 +53,12 @@ class MockXQueueRequestHandler(BaseHTTPRequestHandler): ...@@ -52,12 +53,12 @@ class MockXQueueRequestHandler(BaseHTTPRequestHandler):
except ValueError: except ValueError:
# If we could not decode the body or header, # If we could not decode the body or header,
# respond with failure # respond with failure
error_msg = "XQueue could not decode grade request" error_msg = "XQueue could not decode grade request"
self._send_immediate_response(False, message=error_msg) self._send_immediate_response(False, message=error_msg)
else: else:
# Send an immediate response of success # Send an immediate response of success
# The grade request is formed correctly # The grade request is formed correctly
self._send_immediate_response(True) self._send_immediate_response(True)
...@@ -66,7 +67,7 @@ class MockXQueueRequestHandler(BaseHTTPRequestHandler): ...@@ -66,7 +67,7 @@ class MockXQueueRequestHandler(BaseHTTPRequestHandler):
# Otherwise, the problem will not realize it's # Otherwise, the problem will not realize it's
# queued and it will keep waiting for a response # queued and it will keep waiting for a response
# indefinitely # indefinitely
delayed_grade_func = lambda: self._send_grade_response(callback_url, delayed_grade_func = lambda: self._send_grade_response(callback_url,
xqueue_header) xqueue_header)
timer = threading.Timer(2, delayed_grade_func) timer = threading.Timer(2, delayed_grade_func)
...@@ -166,8 +167,8 @@ class MockXQueueServer(HTTPServer): ...@@ -166,8 +167,8 @@ class MockXQueueServer(HTTPServer):
to POST requests to localhost. to POST requests to localhost.
''' '''
def __init__(self, port_num, def __init__(self, port_num,
grade_response_dict={'correct':True, 'score': 1, 'msg': ''}): grade_response_dict={'correct': True, 'score': 1, 'msg': ''}):
''' '''
Initialize the mock XQueue server instance. Initialize the mock XQueue server instance.
...@@ -251,7 +252,7 @@ class MockXQueueServerTest(unittest.TestCase): ...@@ -251,7 +252,7 @@ class MockXQueueServerTest(unittest.TestCase):
'lms_key': 'test_queuekey', 'lms_key': 'test_queuekey',
'queue_name': 'test_queue'}) 'queue_name': 'test_queue'})
grade_body = json.dumps({'student_info': 'test', grade_body = json.dumps({'student_info': 'test',
'grader_payload': 'test', 'grader_payload': 'test',
'student_response': 'test'}) 'student_response': 'test'})
...@@ -270,9 +271,9 @@ class MockXQueueServerTest(unittest.TestCase): ...@@ -270,9 +271,9 @@ class MockXQueueServerTest(unittest.TestCase):
time.sleep(3) time.sleep(3)
# Expect that the server tries to post back the grading info # Expect that the server tries to post back the grading info
xqueue_body = json.dumps({'correct': True, 'score': 1, xqueue_body = json.dumps({'correct': True, 'score': 1,
'msg': '<div></div>'}) 'msg': '<div></div>'})
expected_callback_dict = {'xqueue_header': grade_header, expected_callback_dict = {'xqueue_header': grade_header,
'xqueue_body': xqueue_body } 'xqueue_body': xqueue_body}
MockXQueueRequestHandler.post_to_url.assert_called_with(callback_url, MockXQueueRequestHandler.post_to_url.assert_called_with(callback_url,
expected_callback_dict) expected_callback_dict)
...@@ -4,7 +4,7 @@ Feature: Answer problems ...@@ -4,7 +4,7 @@ Feature: Answer problems
I want to answer problems I want to answer problems
Scenario: I can answer a problem correctly Scenario: I can answer a problem correctly
Given External graders respond "correct" Given External graders respond "correct"
And I am viewing a "<ProblemType>" problem And I am viewing a "<ProblemType>" problem
When I answer a "<ProblemType>" problem "correctly" When I answer a "<ProblemType>" problem "correctly"
Then My "<ProblemType>" answer is marked "correct" Then My "<ProblemType>" answer is marked "correct"
...@@ -21,7 +21,7 @@ Feature: Answer problems ...@@ -21,7 +21,7 @@ Feature: Answer problems
| code | | code |
Scenario: I can answer a problem incorrectly Scenario: I can answer a problem incorrectly
Given External graders respond "incorrect" Given External graders respond "incorrect"
And I am viewing a "<ProblemType>" problem And I am viewing a "<ProblemType>" problem
When I answer a "<ProblemType>" problem "incorrectly" When I answer a "<ProblemType>" problem "incorrectly"
Then My "<ProblemType>" answer is marked "incorrect" Then My "<ProblemType>" answer is marked "incorrect"
......
...@@ -80,7 +80,7 @@ PROBLEM_FACTORY_DICT = { ...@@ -80,7 +80,7 @@ PROBLEM_FACTORY_DICT = {
a1=0 a1=0
a2=0 a2=0
return (a1+a2)==int(expect) return (a1+a2)==int(expect)
""") }}, """)}},
'code': { 'code': {
'factory': CodeResponseXMLFactory(), 'factory': CodeResponseXMLFactory(),
'kwargs': { 'kwargs': {
...@@ -124,6 +124,7 @@ def view_problem(step, problem_type): ...@@ -124,6 +124,7 @@ def view_problem(step, problem_type):
world.browser.visit(url) world.browser.visit(url)
@step(u'External graders respond "([^"]*)"') @step(u'External graders respond "([^"]*)"')
def set_external_grader_response(step, correctness): def set_external_grader_response(step, correctness):
assert(correctness in ['correct', 'incorrect']) assert(correctness in ['correct', 'incorrect'])
...@@ -193,14 +194,14 @@ def answer_problem(step, problem_type, correctness): ...@@ -193,14 +194,14 @@ def answer_problem(step, problem_type, correctness):
elif problem_type == 'code': elif problem_type == 'code':
# The fake xqueue server is configured to respond # The fake xqueue server is configured to respond
# correct / incorrect no matter what we submit. # correct / incorrect no matter what we submit.
# Furthermore, since the inline code response uses # Furthermore, since the inline code response uses
# JavaScript to make the code display nicely, it's difficult # JavaScript to make the code display nicely, it's difficult
# to programatically input text # to programatically input text
# (there's not <textarea> we can just fill text into) # (there's not <textarea> we can just fill text into)
# For this reason, we submit the initial code in the response # For this reason, we submit the initial code in the response
# (configured in the problem XML above) # (configured in the problem XML above)
pass pass
# Submit the problem # Submit the problem
check_problem(step) check_problem(step)
...@@ -246,8 +247,8 @@ def assert_answer_mark(step, problem_type, correctness): ...@@ -246,8 +247,8 @@ def assert_answer_mark(step, problem_type, correctness):
'checkbox': ['span.correct'], 'checkbox': ['span.correct'],
'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_selectors = {'drop down': ['span.incorrect'], incorrect_selectors = {'drop down': ['span.incorrect'],
...@@ -256,7 +257,7 @@ def assert_answer_mark(step, problem_type, correctness): ...@@ -256,7 +257,7 @@ def assert_answer_mark(step, problem_type, correctness):
'checkbox': ['span.incorrect'], 'checkbox': ['span.incorrect'],
'string': ['div.incorrect'], 'string': ['div.incorrect'],
'numerical': ['div.incorrect'], 'numerical': ['div.incorrect'],
'formula': ['div.incorrect'], 'formula': ['div.incorrect'],
'script': ['div.incorrect'], 'script': ['div.incorrect'],
'code': ['span.incorrect'], } 'code': ['span.incorrect'], }
......
...@@ -3,6 +3,7 @@ from lettuce import before, after, world ...@@ -3,6 +3,7 @@ from lettuce import before, after, world
from django.conf import settings from django.conf import settings
import threading import threading
@before.all @before.all
def setup_mock_xqueue_server(): def setup_mock_xqueue_server():
...@@ -24,6 +25,7 @@ def setup_mock_xqueue_server(): ...@@ -24,6 +25,7 @@ def setup_mock_xqueue_server():
# (and we can shut it down later) # (and we can shut it down later)
world.xqueue_server = server world.xqueue_server = server
@after.all @after.all
def teardown_mock_xqueue_server(total): def teardown_mock_xqueue_server(total):
......
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