Commit 05c02f0d by Calen Pennington

Fixing tests from changes around draft mode

parent 1585286c
...@@ -141,8 +141,6 @@ class AuthTestCase(ContentStoreTestCase): ...@@ -141,8 +141,6 @@ class AuthTestCase(ContentStoreTestCase):
"""Make sure pages that do require login work.""" """Make sure pages that do require login work."""
auth_pages = ( auth_pages = (
reverse('index'), reverse('index'),
reverse('edit_item'),
reverse('save_item'),
) )
# These are pages that should just load when the user is logged in # These are pages that should just load when the user is logged in
...@@ -195,17 +193,17 @@ class EditTestCase(ContentStoreTestCase): ...@@ -195,17 +193,17 @@ class EditTestCase(ContentStoreTestCase):
xmodule.modulestore.django._MODULESTORES = {} xmodule.modulestore.django._MODULESTORES = {}
xmodule.modulestore.django.modulestore().collection.drop() xmodule.modulestore.django.modulestore().collection.drop()
def check_edit_item(self, test_course_name): def check_edit_unit(self, test_course_name):
import_from_xml(modulestore(), 'common/test/data/', [test_course_name]) import_from_xml(modulestore(), 'common/test/data/', [test_course_name])
for descriptor in modulestore().get_items(Location(None, None, None, None, None)): for descriptor in modulestore().get_items(Location(None, None, 'vertical', None, None)):
print "Checking ", descriptor.location.url() print "Checking ", descriptor.location.url()
print descriptor.__class__, descriptor.location print descriptor.__class__, descriptor.location
resp = self.client.get(reverse('edit_item'), {'id': descriptor.location.url()}) resp = self.client.get(reverse('edit_unit', kwargs={'location': descriptor.location.url()}))
self.assertEqual(resp.status_code, 200) self.assertEqual(resp.status_code, 200)
def test_edit_item_toy(self): def test_edit_unit_toy(self):
self.check_edit_item('toy') self.check_edit_unit('toy')
def test_edit_item_full(self): def test_edit_unit_full(self):
self.check_edit_item('full') self.check_edit_unit('full')
...@@ -169,6 +169,7 @@ def edit_subsection(request, location): ...@@ -169,6 +169,7 @@ def edit_subsection(request, location):
'lms_link': lms_link 'lms_link': lms_link
}) })
@login_required @login_required
def edit_unit(request, location): def edit_unit(request, location):
""" """
......
...@@ -38,17 +38,23 @@ STATICFILES_DIRS += [ ...@@ -38,17 +38,23 @@ STATICFILES_DIRS += [
if os.path.isdir(COMMON_TEST_DATA_ROOT / course_dir) if os.path.isdir(COMMON_TEST_DATA_ROOT / course_dir)
] ]
modulestore_options = {
'default_class': 'xmodule.raw_module.RawDescriptor',
'host': 'localhost',
'db': 'test_xmodule',
'collection': 'modulestore',
'fs_root': GITHUB_REPO_ROOT,
'render_template': 'mitxmako.shortcuts.render_to_string',
}
MODULESTORE = { MODULESTORE = {
'default': { 'default': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'OPTIONS': { 'OPTIONS': modulestore_options
'default_class': 'xmodule.raw_module.RawDescriptor', },
'host': 'localhost', 'direct': {
'db': 'test_xmodule', 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'collection': 'modulestore', 'OPTIONS': modulestore_options
'fs_root': GITHUB_REPO_ROOT,
'render_template': 'mitxmako.shortcuts.render_to_string',
}
} }
} }
......
...@@ -240,11 +240,15 @@ class ModuleStore(object): ...@@ -240,11 +240,15 @@ class ModuleStore(object):
An abstract interface for a database backend that stores XModuleDescriptor An abstract interface for a database backend that stores XModuleDescriptor
instances instances
""" """
def has_item(self, location):
"""
Returns True if location exists in this ModuleStore.
"""
raise NotImplementedError
def get_item(self, location, depth=0): def get_item(self, location, depth=0):
""" """
Returns an XModuleDescriptor instance for the item at location. Returns an XModuleDescriptor instance for the item at location.
If location.revision is None, returns the item with the most
recent revision
If any segment of the location is None except revision, raises If any segment of the location is None except revision, raises
xmodule.modulestore.exceptions.InsufficientSpecificationError xmodule.modulestore.exceptions.InsufficientSpecificationError
......
...@@ -70,17 +70,21 @@ class CachingDescriptorSystem(MakoDescriptorSystem): ...@@ -70,17 +70,21 @@ class CachingDescriptorSystem(MakoDescriptorSystem):
) )
def location_to_query(location): def location_to_query(location, wildcard=True):
""" """
Takes a Location and returns a SON object that will query for that location. Takes a Location and returns a SON object that will query for that location.
Fields in location that are None are ignored in the query Fields in location that are None are ignored in the query
If `wildcard` is True, then a None in a location is treated as a wildcard
query. Otherwise, it is searched for literally
""" """
query = SON() query = SON()
# Location dict is ordered by specificity, and SON # Location dict is ordered by specificity, and SON
# will preserve that order for queries # will preserve that order for queries
for key, val in Location(location).dict().iteritems(): for key, val in Location(location).dict().iteritems():
if val is not None: if wildcard and val is None:
query['_id.{key}'.format(key=key)] = val continue
query['_id.{key}'.format(key=key)] = val
return query return query
...@@ -203,18 +207,27 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -203,18 +207,27 @@ class MongoModuleStore(ModuleStoreBase):
ItemNotFoundError. ItemNotFoundError.
''' '''
item = self.collection.find_one( item = self.collection.find_one(
location_to_query(location), location_to_query(location, wildcard=False),
sort=[('revision', pymongo.ASCENDING)], sort=[('revision', pymongo.ASCENDING)],
) )
if item is None: if item is None:
raise ItemNotFoundError(location) raise ItemNotFoundError(location)
return item return item
def has_item(self, location):
"""
Returns True if location exists in this ModuleStore.
"""
location = Location.ensure_fully_specified(location)
try:
self._find_one(location)
return True
except ItemNotFoundError:
return False
def get_item(self, location, depth=0): def get_item(self, location, depth=0):
""" """
Returns an XModuleDescriptor instance for the item at location. Returns an XModuleDescriptor instance for the item at location.
If location.revision is None, returns the item with the most
recent revision.
If any segment of the location is None except revision, raises If any segment of the location is None except revision, raises
xmodule.modulestore.exceptions.InsufficientSpecificationError xmodule.modulestore.exceptions.InsufficientSpecificationError
...@@ -322,16 +335,10 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -322,16 +335,10 @@ class MongoModuleStore(ModuleStoreBase):
'''Find all locations that are the parents of this location. Needed '''Find all locations that are the parents of this location. Needed
for path_to_location(). for path_to_location().
If there is no data at location in this modulestore, raise
ItemNotFoundError.
returns an iterable of things that can be passed to Location. This may returns an iterable of things that can be passed to Location. This may
be empty if there are no parents. be empty if there are no parents.
''' '''
location = Location.ensure_fully_specified(location) location = Location.ensure_fully_specified(location)
# Check that it's actually in this modulestore.
self._find_one(location)
# now get the parents
items = self.collection.find({'definition.children': location.url()}, items = self.collection.find({'definition.children': location.url()},
{'_id': True}) {'_id': True})
return [i['_id'] for i in items] return [i['_id'] for i in items]
......
...@@ -60,10 +60,8 @@ def path_to_location(modulestore, course_id, location): ...@@ -60,10 +60,8 @@ def path_to_location(modulestore, course_id, location):
(loc, path) = queue.pop() # Takes from the end (loc, path) = queue.pop() # Takes from the end
loc = Location(loc) loc = Location(loc)
# get_parent_locations should raise ItemNotFoundError if location # Call get_parent_locations first to make sure the location is there
# isn't found so we don't have to do it explicitly. Call this # (even if it's a course, and we would otherwise immediately exit).
# first to make sure the location is there (even if it's a course, and
# we would otherwise immediately exit).
parents = modulestore.get_parent_locations(loc) parents = modulestore.get_parent_locations(loc)
# print 'Processing loc={0}, path={1}'.format(loc, path) # print 'Processing loc={0}, path={1}'.format(loc, path)
...@@ -81,6 +79,9 @@ def path_to_location(modulestore, course_id, location): ...@@ -81,6 +79,9 @@ def path_to_location(modulestore, course_id, location):
# If we're here, there is no path # If we're here, there is no path
return None return None
if not modulestore.has_item(location):
raise ItemNotFoundError
path = find_path_to_course() path = find_path_to_course()
if path is None: if path is None:
raise NoPathToItem(location) raise NoPathToItem(location)
......
...@@ -477,11 +477,16 @@ class XMLModuleStore(ModuleStoreBase): ...@@ -477,11 +477,16 @@ class XMLModuleStore(ModuleStoreBase):
except KeyError: except KeyError:
raise ItemNotFoundError(location) raise ItemNotFoundError(location)
def has_item(self, location):
"""
Returns True if location exists in this ModuleStore.
"""
location = Location(location)
return any(location in course_modules for course_modules in self.modules.values())
def get_item(self, location, depth=0): def get_item(self, location, depth=0):
""" """
Returns an XModuleDescriptor instance for the item at location. Returns an XModuleDescriptor instance for the item at location.
If location.revision is None, returns the most item with the most
recent revision
If any segment of the location is None except revision, raises If any segment of the location is None except revision, raises
xmodule.modulestore.exceptions.InsufficientSpecificationError xmodule.modulestore.exceptions.InsufficientSpecificationError
...@@ -545,14 +550,8 @@ class XMLModuleStore(ModuleStoreBase): ...@@ -545,14 +550,8 @@ class XMLModuleStore(ModuleStoreBase):
'''Find all locations that are the parents of this location. Needed '''Find all locations that are the parents of this location. Needed
for path_to_location(). for path_to_location().
If there is no data at location in this modulestore, raise
ItemNotFoundError.
returns an iterable of things that can be passed to Location. This may returns an iterable of things that can be passed to Location. This may
be empty if there are no parents. be empty if there are no parents.
''' '''
location = Location.ensure_fully_specified(location) location = Location.ensure_fully_specified(location)
if not self.parent_tracker.is_known(location):
raise ItemNotFoundError(location)
return self.parent_tracker.parents(location) return self.parent_tracker.parents(location)
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