Commit ef78c99f by Chris Dodge

pep8/pylint violations fixes

parent 5d2b8879
...@@ -47,7 +47,7 @@ class MongoCollectionFindWrapper(object): ...@@ -47,7 +47,7 @@ class MongoCollectionFindWrapper(object):
self.counter = 0 self.counter = 0
def find(self, query, *args, **kwargs): def find(self, query, *args, **kwargs):
self.counter = self.counter+1 self.counter = self.counter + 1
return self.original(query, *args, **kwargs) return self.original(query, *args, **kwargs)
...@@ -357,7 +357,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -357,7 +357,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
clone_items = module_store.get_items(Location(['i4x', 'MITx', '999', 'vertical', None])) clone_items = module_store.get_items(Location(['i4x', 'MITx', '999', 'vertical', None]))
self.assertGreater(len(clone_items), 0) self.assertGreater(len(clone_items), 0)
for descriptor in items: for descriptor in items:
new_loc = descriptor.location._replace(org='MITx', course='999') new_loc = descriptor.location.replace(org='MITx', course='999')
print "Checking {0} should now also be at {1}".format(descriptor.location.url(), new_loc.url()) print "Checking {0} should now also be at {1}".format(descriptor.location.url(), new_loc.url())
resp = self.client.get(reverse('edit_unit', kwargs={'location': new_loc.url()})) resp = self.client.get(reverse('edit_unit', kwargs={'location': new_loc.url()}))
self.assertEqual(resp.status_code, 200) self.assertEqual(resp.status_code, 200)
...@@ -380,15 +380,15 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -380,15 +380,15 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.assertEqual(len(items), 0) self.assertEqual(len(items), 0)
def verify_content_existence(self, modulestore, root_dir, location, dirname, category_name, filename_suffix=''): def verify_content_existence(self, modulestore, root_dir, location, dirname, category_name, filename_suffix=''):
fs = OSFS(root_dir / 'test_export') filesystem = OSFS(root_dir / 'test_export')
self.assertTrue(fs.exists(dirname)) self.assertTrue(filesystem.exists(dirname))
query_loc = Location('i4x', location.org, location.course, category_name, None) query_loc = Location('i4x', location.org, location.course, category_name, None)
items = modulestore.get_items(query_loc) items = modulestore.get_items(query_loc)
for item in items: for item in items:
fs = OSFS(root_dir / ('test_export/' + dirname)) filesystem = OSFS(root_dir / ('test_export/' + dirname))
self.assertTrue(fs.exists(item.location.name + filename_suffix)) self.assertTrue(filesystem.exists(item.location.name + filename_suffix))
def test_export_course(self): def test_export_course(self):
module_store = modulestore('direct') module_store = modulestore('direct')
...@@ -420,7 +420,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -420,7 +420,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
# add private to list of children # add private to list of children
sequential = module_store.get_item(Location(['i4x', 'edX', 'full', sequential = module_store.get_item(Location(['i4x', 'edX', 'full',
'sequential', 'Administrivia_and_Circuit_Elements', None])) 'sequential', 'Administrivia_and_Circuit_Elements', None]))
private_location_no_draft = private_vertical.location._replace(revision=None) private_location_no_draft = private_vertical.location.replace(revision=None)
module_store.update_children(sequential.location, sequential.children + module_store.update_children(sequential.location, sequential.children +
[private_location_no_draft.url()]) [private_location_no_draft.url()])
...@@ -445,20 +445,20 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -445,20 +445,20 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.verify_content_existence(module_store, root_dir, location, 'custom_tags', 'custom_tag_template') self.verify_content_existence(module_store, root_dir, location, 'custom_tags', 'custom_tag_template')
# check for graiding_policy.json # check for graiding_policy.json
fs = OSFS(root_dir / 'test_export/policies/6.002_Spring_2012') filesystem = OSFS(root_dir / 'test_export/policies/6.002_Spring_2012')
self.assertTrue(fs.exists('grading_policy.json')) self.assertTrue(filesystem.exists('grading_policy.json'))
course = module_store.get_item(location) course = module_store.get_item(location)
# compare what's on disk compared to what we have in our course # compare what's on disk compared to what we have in our course
with fs.open('grading_policy.json', 'r') as grading_policy: with filesystem.open('grading_policy.json', 'r') as grading_policy:
on_disk = loads(grading_policy.read()) on_disk = loads(grading_policy.read())
self.assertEqual(on_disk, course.grading_policy) self.assertEqual(on_disk, course.grading_policy)
#check for policy.json #check for policy.json
self.assertTrue(fs.exists('policy.json')) self.assertTrue(filesystem.exists('policy.json'))
# compare what's on disk to what we have in the course module # compare what's on disk to what we have in the course module
with fs.open('policy.json', 'r') as course_policy: with filesystem.open('policy.json', 'r') as course_policy:
on_disk = loads(course_policy.read()) on_disk = loads(course_policy.read())
self.assertIn('course/6.002_Spring_2012', on_disk) self.assertIn('course/6.002_Spring_2012', on_disk)
self.assertEqual(on_disk['course/6.002_Spring_2012'], own_metadata(course)) self.assertEqual(on_disk['course/6.002_Spring_2012'], own_metadata(course))
...@@ -813,37 +813,37 @@ class ContentStoreTest(ModuleStoreTestCase): ...@@ -813,37 +813,37 @@ class ContentStoreTest(ModuleStoreTestCase):
self.assertEqual(200, resp.status_code) self.assertEqual(200, resp.status_code)
# go look at a subsection page # go look at a subsection page
subsection_location = loc._replace(category='sequential', name='test_sequence') subsection_location = loc.replace(category='sequential', name='test_sequence')
resp = self.client.get(reverse('edit_subsection', resp = self.client.get(reverse('edit_subsection',
kwargs={'location': subsection_location.url()})) kwargs={'location': subsection_location.url()}))
self.assertEqual(200, resp.status_code) self.assertEqual(200, resp.status_code)
# go look at the Edit page # go look at the Edit page
unit_location = loc._replace(category='vertical', name='test_vertical') unit_location = loc.replace(category='vertical', name='test_vertical')
resp = self.client.get(reverse('edit_unit', resp = self.client.get(reverse('edit_unit',
kwargs={'location': unit_location.url()})) kwargs={'location': unit_location.url()}))
self.assertEqual(200, resp.status_code) self.assertEqual(200, resp.status_code)
# delete a component # delete a component
del_loc = loc._replace(category='html', name='test_html') del_loc = loc.replace(category='html', name='test_html')
resp = self.client.post(reverse('delete_item'), resp = self.client.post(reverse('delete_item'),
json.dumps({'id': del_loc.url()}), "application/json") json.dumps({'id': del_loc.url()}), "application/json")
self.assertEqual(200, resp.status_code) self.assertEqual(200, resp.status_code)
# delete a unit # delete a unit
del_loc = loc._replace(category='vertical', name='test_vertical') del_loc = loc.replace(category='vertical', name='test_vertical')
resp = self.client.post(reverse('delete_item'), resp = self.client.post(reverse('delete_item'),
json.dumps({'id': del_loc.url()}), "application/json") json.dumps({'id': del_loc.url()}), "application/json")
self.assertEqual(200, resp.status_code) self.assertEqual(200, resp.status_code)
# delete a unit # delete a unit
del_loc = loc._replace(category='sequential', name='test_sequence') del_loc = loc.replace(category='sequential', name='test_sequence')
resp = self.client.post(reverse('delete_item'), resp = self.client.post(reverse('delete_item'),
json.dumps({'id': del_loc.url()}), "application/json") json.dumps({'id': del_loc.url()}), "application/json")
self.assertEqual(200, resp.status_code) self.assertEqual(200, resp.status_code)
# delete a chapter # delete a chapter
del_loc = loc._replace(category='chapter', name='chapter_2') del_loc = loc.replace(category='chapter', name='chapter_2')
resp = self.client.post(reverse('delete_item'), resp = self.client.post(reverse('delete_item'),
json.dumps({'id': del_loc.url()}), "application/json") json.dumps({'id': del_loc.url()}), "application/json")
self.assertEqual(200, resp.status_code) self.assertEqual(200, resp.status_code)
......
...@@ -9,7 +9,7 @@ import re ...@@ -9,7 +9,7 @@ import re
from collections import namedtuple from collections import namedtuple
from .exceptions import InvalidLocationError, InsufficientSpecificationError from .exceptions import InvalidLocationError, InsufficientSpecificationError
from xmodule.errortracker import ErrorLog, make_error_tracker from xmodule.errortracker import make_error_tracker
from bson.son import SON from bson.son import SON
log = logging.getLogger('mitx.' + 'modulestore') log = logging.getLogger('mitx.' + 'modulestore')
...@@ -64,7 +64,6 @@ class Location(_LocationBase): ...@@ -64,7 +64,6 @@ class Location(_LocationBase):
""" """
return re.sub('_+', '_', invalid.sub('_', value)) return re.sub('_+', '_', invalid.sub('_', value))
@staticmethod @staticmethod
def clean(value): def clean(value):
""" """
...@@ -72,7 +71,6 @@ class Location(_LocationBase): ...@@ -72,7 +71,6 @@ class Location(_LocationBase):
""" """
return Location._clean(value, INVALID_CHARS) return Location._clean(value, INVALID_CHARS)
@staticmethod @staticmethod
def clean_keeping_underscores(value): def clean_keeping_underscores(value):
""" """
...@@ -82,7 +80,6 @@ class Location(_LocationBase): ...@@ -82,7 +80,6 @@ class Location(_LocationBase):
""" """
return INVALID_CHARS.sub('_', value) return INVALID_CHARS.sub('_', value)
@staticmethod @staticmethod
def clean_for_url_name(value): def clean_for_url_name(value):
""" """
...@@ -154,9 +151,7 @@ class Location(_LocationBase): ...@@ -154,9 +151,7 @@ class Location(_LocationBase):
to mean wildcard selection. to mean wildcard selection.
""" """
if (org is None and course is None and category is None and name is None and revision is None):
if (org is None and course is None and category is None and
name is None and revision is None):
location = loc_or_tag location = loc_or_tag
else: else:
location = (loc_or_tag, org, course, category, name, revision) location = (loc_or_tag, org, course, category, name, revision)
...@@ -191,7 +186,7 @@ class Location(_LocationBase): ...@@ -191,7 +186,7 @@ class Location(_LocationBase):
match = MISSING_SLASH_URL_RE.match(location) match = MISSING_SLASH_URL_RE.match(location)
if match is None: if match is None:
log.debug('location is instance of %s but no URL match' % basestring) log.debug('location is instance of %s but no URL match' % basestring)
raise InvalidLocationError(location) raise InvalidLocationError(location)
groups = match.groupdict() groups = match.groupdict()
check_dict(groups) check_dict(groups)
return _LocationBase.__new__(_cls, **groups) return _LocationBase.__new__(_cls, **groups)
...@@ -233,7 +228,7 @@ class Location(_LocationBase): ...@@ -233,7 +228,7 @@ class Location(_LocationBase):
html id attributes html id attributes
""" """
s = "-".join(str(v) for v in self.list() s = "-".join(str(v) for v in self.list()
if v is not None) if v is not None)
return Location.clean_for_html(s) return Location.clean_for_html(s)
def dict(self): def dict(self):
...@@ -258,6 +253,12 @@ class Location(_LocationBase): ...@@ -258,6 +253,12 @@ class Location(_LocationBase):
at the location URL hierachy""" at the location URL hierachy"""
return "/".join([self.org, self.course, self.name]) return "/".join([self.org, self.course, self.name])
def replace(self, **kwargs):
'''
Expose a public method for replacing location elements
'''
return self._replace(**kwargs)
class ModuleStore(object): class ModuleStore(object):
""" """
...@@ -382,12 +383,6 @@ class ModuleStore(object): ...@@ -382,12 +383,6 @@ class ModuleStore(object):
''' '''
raise NotImplementedError raise NotImplementedError
def get_course(self, course_id):
'''
Look for a specific course id. Returns the course descriptor, or None if not found.
'''
raise NotImplementedError
def get_parent_locations(self, location, course_id): def get_parent_locations(self, location, course_id):
'''Find all locations that are the parents of this location in this '''Find all locations that are the parents of this location in this
course. Needed for path_to_location(). course. Needed for path_to_location().
...@@ -406,8 +401,7 @@ class ModuleStore(object): ...@@ -406,8 +401,7 @@ class ModuleStore(object):
courses = [ courses = [
course course
for course in self.get_courses() for course in self.get_courses()
if course.location.org == location.org if course.location.org == location.org and course.location.course == location.course
and course.location.course == location.course
] ]
return courses return courses
......
...@@ -13,11 +13,12 @@ def as_draft(location): ...@@ -13,11 +13,12 @@ def as_draft(location):
""" """
return Location(location)._replace(revision=DRAFT) return Location(location)._replace(revision=DRAFT)
def as_published(location): def as_published(location):
""" """
Returns the Location that is the published version for `location` Returns the Location that is the published version for `location`
""" """
return Location(location)._replace(revision=None) return Location(location)._replace(revision=None)
def wrap_draft(item): def wrap_draft(item):
......
...@@ -3,7 +3,6 @@ from time import gmtime ...@@ -3,7 +3,6 @@ from time import gmtime
from uuid import uuid4 from uuid import uuid4
from xmodule.modulestore import Location from xmodule.modulestore import Location
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.timeparse import stringify_time
from xmodule.modulestore.inheritance import own_metadata from xmodule.modulestore.inheritance import own_metadata
......
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