Commit b63aae22 by Jay Zoldak

small pep8 pylint and superclass fixes

parent 5bf839c9
...@@ -32,7 +32,7 @@ class ModuleStoreTestCase(TestCase): ...@@ -32,7 +32,7 @@ class ModuleStoreTestCase(TestCase):
# This query means: every item in the collection # This query means: every item in the collection
# that is not a template # that is not a template
query = { "_id.course": { "$ne": "templates" }} query = {"_id.course": {"$ne": "templates"}}
# Remove everything except templates # Remove everything except templates
modulestore.collection.remove(query) modulestore.collection.remove(query)
...@@ -47,7 +47,7 @@ class ModuleStoreTestCase(TestCase): ...@@ -47,7 +47,7 @@ class ModuleStoreTestCase(TestCase):
modulestore = xmodule.modulestore.django.modulestore() modulestore = xmodule.modulestore.django.modulestore()
# Count the number of templates # Count the number of templates
query = { "_id.course": "templates"} query = {"_id.course": "templates"}
num_templates = modulestore.collection.find(query).count() num_templates = modulestore.collection.find(query).count()
if num_templates < 1: if num_templates < 1:
...@@ -96,7 +96,7 @@ class ModuleStoreTestCase(TestCase): ...@@ -96,7 +96,7 @@ class ModuleStoreTestCase(TestCase):
ModuleStoreTestCase.load_templates_if_necessary() ModuleStoreTestCase.load_templates_if_necessary()
# Call superclass implementation # Call superclass implementation
TestCase._pre_setup(self) super(ModuleStoreTestCase, self)._pre_setup()
def _post_teardown(self): def _post_teardown(self):
''' '''
...@@ -106,7 +106,7 @@ class ModuleStoreTestCase(TestCase): ...@@ -106,7 +106,7 @@ class ModuleStoreTestCase(TestCase):
ModuleStoreTestCase.flush_mongo_except_templates() ModuleStoreTestCase.flush_mongo_except_templates()
# Call superclass implementation # Call superclass implementation
TestCase._post_teardown(self) super(ModuleStoreTestCase, self)._post_teardown()
def parse_json(response): def parse_json(response):
......
...@@ -3,7 +3,6 @@ import unittest ...@@ -3,7 +3,6 @@ import unittest
import threading import threading
import json import json
import urllib import urllib
import urlparse
import time import time
from mock_xqueue_server import MockXQueueServer, MockXQueueRequestHandler from mock_xqueue_server import MockXQueueServer, MockXQueueRequestHandler
...@@ -33,7 +32,7 @@ class MockXQueueServerTest(unittest.TestCase): ...@@ -33,7 +32,7 @@ class MockXQueueServerTest(unittest.TestCase):
server_port = 8034 server_port = 8034
self.server_url = 'http://127.0.0.1:%d' % server_port self.server_url = 'http://127.0.0.1:%d' % server_port
self.server = MockXQueueServer(server_port, self.server = MockXQueueServer(server_port,
{'correct': True, 'score': 1, 'msg': ''}) {'correct': True, 'score': 1, 'msg': ''})
# Start the server in a separate daemon thread # Start the server in a separate daemon thread
server_thread = threading.Thread(target=self.server.serve_forever) server_thread = threading.Thread(target=self.server.serve_forever)
...@@ -55,18 +54,18 @@ class MockXQueueServerTest(unittest.TestCase): ...@@ -55,18 +54,18 @@ class MockXQueueServerTest(unittest.TestCase):
callback_url = 'http://127.0.0.1:8000/test_callback' callback_url = 'http://127.0.0.1:8000/test_callback'
grade_header = json.dumps({'lms_callback_url': callback_url, grade_header = json.dumps({'lms_callback_url': callback_url,
'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'})
grade_request = {'xqueue_header': grade_header, grade_request = {'xqueue_header': grade_header,
'xqueue_body': grade_body} 'xqueue_body': grade_body}
response_handle = urllib.urlopen(self.server_url + '/xqueue/submit', response_handle = urllib.urlopen(self.server_url + '/xqueue/submit',
urllib.urlencode(grade_request)) urllib.urlencode(grade_request))
response_dict = json.loads(response_handle.read()) response_dict = json.loads(response_handle.read())
...@@ -78,8 +77,8 @@ class MockXQueueServerTest(unittest.TestCase): ...@@ -78,8 +77,8 @@ class MockXQueueServerTest(unittest.TestCase):
# 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)
...@@ -127,11 +127,11 @@ class LoginEnrollmentTestCase(TestCase): ...@@ -127,11 +127,11 @@ class LoginEnrollmentTestCase(TestCase):
e_scheme, e_netloc, e_path, e_query, e_fragment = urlsplit(expected_url) e_scheme, e_netloc, e_path, e_query, e_fragment = urlsplit(expected_url)
if not (e_scheme or e_netloc): if not (e_scheme or e_netloc):
expected_url = urlunsplit(('http', 'testserver', expected_url = urlunsplit(('http', 'testserver',
e_path, e_query, e_fragment)) e_path, e_query, e_fragment))
self.assertEqual(url, expected_url, self.assertEqual(url, expected_url,
"Response redirected to '%s', expected '%s'" % "Response redirected to '%s', expected '%s'" %
(url, expected_url)) (url, expected_url))
def setup_viewtest_user(self): def setup_viewtest_user(self):
'''create a user account, activate, and log in''' '''create a user account, activate, and log in'''
...@@ -219,7 +219,7 @@ class LoginEnrollmentTestCase(TestCase): ...@@ -219,7 +219,7 @@ class LoginEnrollmentTestCase(TestCase):
"""Try to enroll. Return bool success instead of asserting it.""" """Try to enroll. Return bool success instead of asserting it."""
data = self._enroll(course) data = self._enroll(course)
print ('Enrollment in %s result: %s' print ('Enrollment in %s result: %s'
% (course.location.url(), str(data))) % (course.location.url(), str(data)))
return data['success'] return data['success']
def enroll(self, course): def enroll(self, course):
...@@ -287,12 +287,11 @@ class PageLoaderTestCase(LoginEnrollmentTestCase): ...@@ -287,12 +287,11 @@ class PageLoaderTestCase(LoginEnrollmentTestCase):
self.enroll(course) self.enroll(course)
course_id = course.id course_id = course.id
# Search for items in the course # Search for items in the course
# None is treated as a wildcard # None is treated as a wildcard
course_loc = course.location course_loc = course.location
location_query = Location(course_loc.tag, course_loc.org, location_query = Location(course_loc.tag, course_loc.org,
course_loc.course, None, None, None) course_loc.course, None, None, None)
items = module_store.get_items(location_query) items = module_store.get_items(location_query)
...@@ -301,22 +300,21 @@ class PageLoaderTestCase(LoginEnrollmentTestCase): ...@@ -301,22 +300,21 @@ class PageLoaderTestCase(LoginEnrollmentTestCase):
else: else:
descriptor = random.choice(items) descriptor = random.choice(items)
# We have ancillary course information now as modules # We have ancillary course information now as modules
# and we can't simply use 'jump_to' to view them # and we can't simply use 'jump_to' to view them
if descriptor.location.category == 'about': if descriptor.location.category == 'about':
self._assert_loads('about_course', self._assert_loads('about_course',
{'course_id': course_id}, {'course_id': course_id},
descriptor) descriptor)
elif descriptor.location.category == 'static_tab': elif descriptor.location.category == 'static_tab':
kwargs = {'course_id': course_id, kwargs = {'course_id': course_id,
'tab_slug': descriptor.location.name} 'tab_slug': descriptor.location.name}
self._assert_loads('static_tab', kwargs, descriptor) self._assert_loads('static_tab', kwargs, descriptor)
elif descriptor.location.category == 'course_info': elif descriptor.location.category == 'course_info':
self._assert_loads('info', {'course_id': course_id}, self._assert_loads('info', {'course_id': course_id},
descriptor) descriptor)
elif descriptor.location.category == 'custom_tag_template': elif descriptor.location.category == 'custom_tag_template':
pass pass
...@@ -324,16 +322,15 @@ class PageLoaderTestCase(LoginEnrollmentTestCase): ...@@ -324,16 +322,15 @@ class PageLoaderTestCase(LoginEnrollmentTestCase):
else: else:
kwargs = {'course_id': course_id, kwargs = {'course_id': course_id,
'location': descriptor.location.url()} 'location': descriptor.location.url()}
self._assert_loads('jump_to', kwargs, descriptor, self._assert_loads('jump_to', kwargs, descriptor,
expect_redirect=True, expect_redirect=True,
check_content=True) check_content=True)
def _assert_loads(self, django_url, kwargs, descriptor, def _assert_loads(self, django_url, kwargs, descriptor,
expect_redirect=False, expect_redirect=False,
check_content=False): check_content=False):
''' '''
Assert that the url loads correctly. Assert that the url loads correctly.
If expect_redirect, then also check that we were redirected. If expect_redirect, then also check that we were redirected.
...@@ -346,7 +343,7 @@ class PageLoaderTestCase(LoginEnrollmentTestCase): ...@@ -346,7 +343,7 @@ class PageLoaderTestCase(LoginEnrollmentTestCase):
if response.status_code != 200: if response.status_code != 200:
self.fail('Status %d for page %s' % self.fail('Status %d for page %s' %
(response.status_code, descriptor.location.url())) (response.status_code, descriptor.location.url()))
if expect_redirect: if expect_redirect:
self.assertEqual(response.redirect_chain[0][1], 302) self.assertEqual(response.redirect_chain[0][1], 302)
...@@ -368,9 +365,9 @@ class TestCoursesLoadTestCase_XmlModulestore(PageLoaderTestCase): ...@@ -368,9 +365,9 @@ class TestCoursesLoadTestCase_XmlModulestore(PageLoaderTestCase):
def test_toy_course_loads(self): def test_toy_course_loads(self):
module_class = 'xmodule.hidden_module.HiddenDescriptor' module_class = 'xmodule.hidden_module.HiddenDescriptor'
module_store = XMLModuleStore(TEST_DATA_DIR, module_store = XMLModuleStore(TEST_DATA_DIR,
default_class=module_class, default_class=module_class,
course_dirs=['toy'], course_dirs=['toy'],
load_error_modules=True) load_error_modules=True)
self.check_random_page_loads(module_store) self.check_random_page_loads(module_store)
...@@ -390,7 +387,6 @@ class TestCoursesLoadTestCase_MongoModulestore(PageLoaderTestCase): ...@@ -390,7 +387,6 @@ class TestCoursesLoadTestCase_MongoModulestore(PageLoaderTestCase):
self.check_random_page_loads(module_store) self.check_random_page_loads(module_store)
@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE)
class TestNavigation(LoginEnrollmentTestCase): class TestNavigation(LoginEnrollmentTestCase):
"""Check that navigation state is saved properly""" """Check that navigation state is saved properly"""
...@@ -419,7 +415,7 @@ class TestNavigation(LoginEnrollmentTestCase): ...@@ -419,7 +415,7 @@ class TestNavigation(LoginEnrollmentTestCase):
# First request should redirect to ToyVideos # First request should redirect to ToyVideos
resp = self.client.get(reverse('courseware', resp = self.client.get(reverse('courseware',
kwargs={'course_id': self.toy.id})) kwargs={'course_id': self.toy.id}))
# Don't use no-follow, because state should # Don't use no-follow, because state should
# only be saved once we actually hit the section # only be saved once we actually hit the section
...@@ -431,11 +427,11 @@ class TestNavigation(LoginEnrollmentTestCase): ...@@ -431,11 +427,11 @@ class TestNavigation(LoginEnrollmentTestCase):
# Hitting the couseware tab again should # Hitting the couseware tab again should
# redirect to the first chapter: 'Overview' # redirect to the first chapter: 'Overview'
resp = self.client.get(reverse('courseware', resp = self.client.get(reverse('courseware',
kwargs={'course_id': self.toy.id})) kwargs={'course_id': self.toy.id}))
self.assertRedirectsNoFollow(resp, reverse('courseware_chapter', self.assertRedirectsNoFollow(resp, reverse('courseware_chapter',
kwargs={'course_id': self.toy.id, kwargs={'course_id': self.toy.id,
'chapter': 'Overview'})) 'chapter': 'Overview'}))
# Now we directly navigate to a section in a different chapter # Now we directly navigate to a section in a different chapter
self.check_for_get_code(200, reverse('courseware_section', self.check_for_get_code(200, reverse('courseware_section',
...@@ -445,11 +441,11 @@ class TestNavigation(LoginEnrollmentTestCase): ...@@ -445,11 +441,11 @@ class TestNavigation(LoginEnrollmentTestCase):
# And now hitting the courseware tab should redirect to 'secret:magic' # And now hitting the courseware tab should redirect to 'secret:magic'
resp = self.client.get(reverse('courseware', resp = self.client.get(reverse('courseware',
kwargs={'course_id': self.toy.id})) kwargs={'course_id': self.toy.id}))
self.assertRedirectsNoFollow(resp, reverse('courseware_chapter', self.assertRedirectsNoFollow(resp, reverse('courseware_chapter',
kwargs={'course_id': self.toy.id, kwargs={'course_id': self.toy.id,
'chapter': 'secret:magic'})) 'chapter': 'secret:magic'}))
@override_settings(MODULESTORE=TEST_DATA_DRAFT_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_DRAFT_MONGO_MODULESTORE)
...@@ -459,7 +455,7 @@ class TestDraftModuleStore(TestCase): ...@@ -459,7 +455,7 @@ class TestDraftModuleStore(TestCase):
# fix was to allow get_items() to take the course_id parameter # fix was to allow get_items() to take the course_id parameter
store.get_items(Location(None, None, 'vertical', None, None), store.get_items(Location(None, None, 'vertical', None, None),
course_id='abc', depth=0) course_id='abc', depth=0)
# test success is just getting through the above statement. # test success is just getting through the above statement.
# The bug was that 'course_id' argument was # The bug was that 'course_id' argument was
...@@ -497,21 +493,21 @@ class TestViewAuth(LoginEnrollmentTestCase): ...@@ -497,21 +493,21 @@ class TestViewAuth(LoginEnrollmentTestCase):
self.login(self.student, self.password) self.login(self.student, self.password)
# shouldn't work before enroll # shouldn't work before enroll
response = self.client.get(reverse('courseware', response = self.client.get(reverse('courseware',
kwargs={'course_id': self.toy.id})) kwargs={'course_id': self.toy.id}))
self.assertRedirectsNoFollow(response, self.assertRedirectsNoFollow(response,
reverse('about_course', reverse('about_course',
args=[self.toy.id])) args=[self.toy.id]))
self.enroll(self.toy) self.enroll(self.toy)
self.enroll(self.full) self.enroll(self.full)
# should work now -- redirect to first page # should work now -- redirect to first page
response = self.client.get(reverse('courseware', response = self.client.get(reverse('courseware',
kwargs={'course_id': self.toy.id})) kwargs={'course_id': self.toy.id}))
self.assertRedirectsNoFollow(response, self.assertRedirectsNoFollow(response,
reverse('courseware_section', reverse('courseware_section',
kwargs={'course_id': self.toy.id, kwargs={'course_id': self.toy.id,
'chapter': 'Overview', 'chapter': 'Overview',
'section': 'Toy_Videos'})) 'section': 'Toy_Videos'}))
def instructor_urls(course): def instructor_urls(course):
"list of urls that only instructors/staff should be able to see" "list of urls that only instructors/staff should be able to see"
...@@ -521,8 +517,8 @@ class TestViewAuth(LoginEnrollmentTestCase): ...@@ -521,8 +517,8 @@ class TestViewAuth(LoginEnrollmentTestCase):
'grade_summary',)] 'grade_summary',)]
urls.append(reverse('student_progress', urls.append(reverse('student_progress',
kwargs={'course_id': course.id, kwargs={'course_id': course.id,
'student_id': get_user(self.student).id})) 'student_id': get_user(self.student).id}))
return urls return urls
# Randomly sample an instructor page # Randomly sample an instructor page
...@@ -634,7 +630,7 @@ class TestViewAuth(LoginEnrollmentTestCase): ...@@ -634,7 +630,7 @@ class TestViewAuth(LoginEnrollmentTestCase):
def instructor_urls(course): def instructor_urls(course):
"""list of urls that only instructors/staff should be able to see""" """list of urls that only instructors/staff should be able to see"""
urls = reverse_urls(['instructor_dashboard', urls = reverse_urls(['instructor_dashboard',
'gradebook', 'grade_summary'], course) 'gradebook', 'grade_summary'], course)
return urls return urls
def check_non_staff(course): def check_non_staff(course):
...@@ -642,9 +638,9 @@ class TestViewAuth(LoginEnrollmentTestCase): ...@@ -642,9 +638,9 @@ class TestViewAuth(LoginEnrollmentTestCase):
print '=== Checking non-staff access for {0}'.format(course.id) print '=== Checking non-staff access for {0}'.format(course.id)
# Randomly sample a dark url # Randomly sample a dark url
url = random.choice( instructor_urls(course) + url = random.choice(instructor_urls(course) +
dark_student_urls(course) + dark_student_urls(course) +
reverse_urls(['courseware'], course)) reverse_urls(['courseware'], course))
print 'checking for 404 on {0}'.format(url) print 'checking for 404 on {0}'.format(url)
self.check_for_get_code(404, url) self.check_for_get_code(404, url)
...@@ -671,7 +667,7 @@ class TestViewAuth(LoginEnrollmentTestCase): ...@@ -671,7 +667,7 @@ class TestViewAuth(LoginEnrollmentTestCase):
# to make access checking smarter and understand both the effective # to make access checking smarter and understand both the effective
# user (the student), and the requesting user (the prof) # user (the student), and the requesting user (the prof)
url = reverse('student_progress', url = reverse('student_progress',
kwargs={'course_id': course.id, kwargs={'course_id': course.id,
'student_id': get_user(self.student).id}) 'student_id': get_user(self.student).id})
print 'checking for 404 on view-as-student: {0}'.format(url) print 'checking for 404 on view-as-student: {0}'.format(url)
self.check_for_get_code(404, url) self.check_for_get_code(404, url)
...@@ -828,7 +824,7 @@ class TestCourseGrader(LoginEnrollmentTestCase): ...@@ -828,7 +824,7 @@ class TestCourseGrader(LoginEnrollmentTestCase):
self.graded_course.id, self.student_user, self.graded_course) self.graded_course.id, self.student_user, self.graded_course)
fake_request = self.factory.get(reverse('progress', fake_request = self.factory.get(reverse('progress',
kwargs={'course_id': self.graded_course.id})) kwargs={'course_id': self.graded_course.id}))
return grades.grade(self.student_user, fake_request, return grades.grade(self.student_user, fake_request,
self.graded_course, model_data_cache) self.graded_course, model_data_cache)
...@@ -843,7 +839,7 @@ class TestCourseGrader(LoginEnrollmentTestCase): ...@@ -843,7 +839,7 @@ class TestCourseGrader(LoginEnrollmentTestCase):
self.graded_course.id, self.student_user, self.graded_course) self.graded_course.id, self.student_user, self.graded_course)
fake_request = self.factory.get(reverse('progress', fake_request = self.factory.get(reverse('progress',
kwargs={'course_id': self.graded_course.id})) kwargs={'course_id': self.graded_course.id}))
progress_summary = grades.progress_summary(self.student_user, progress_summary = grades.progress_summary(self.student_user,
fake_request, fake_request,
......
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