Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
05c02f0d
Commit
05c02f0d
authored
Oct 05, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing tests from changes around draft mode
parent
1585286c
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
59 additions
and
43 deletions
+59
-43
cms/djangoapps/contentstore/tests/tests.py
+7
-9
cms/djangoapps/contentstore/views.py
+1
-0
cms/envs/test.py
+14
-8
common/lib/xmodule/xmodule/modulestore/__init__.py
+6
-2
common/lib/xmodule/xmodule/modulestore/mongo.py
+19
-12
common/lib/xmodule/xmodule/modulestore/search.py
+5
-4
common/lib/xmodule/xmodule/modulestore/xml.py
+7
-8
No files found.
cms/djangoapps/contentstore/tests/tests.py
View file @
05c02f0d
...
...
@@ -141,8 +141,6 @@ class AuthTestCase(ContentStoreTestCase):
"""Make sure pages that do require login work."""
auth_pages
=
(
reverse
(
'index'
),
reverse
(
'edit_item'
),
reverse
(
'save_item'
),
)
# These are pages that should just load when the user is logged in
...
...
@@ -195,17 +193,17 @@ class EditTestCase(ContentStoreTestCase):
xmodule
.
modulestore
.
django
.
_MODULESTORES
=
{}
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
])
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
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
)
def
test_edit_
item
_toy
(
self
):
self
.
check_edit_
item
(
'toy'
)
def
test_edit_
unit
_toy
(
self
):
self
.
check_edit_
unit
(
'toy'
)
def
test_edit_
item
_full
(
self
):
self
.
check_edit_
item
(
'full'
)
def
test_edit_
unit
_full
(
self
):
self
.
check_edit_
unit
(
'full'
)
cms/djangoapps/contentstore/views.py
View file @
05c02f0d
...
...
@@ -169,6 +169,7 @@ def edit_subsection(request, location):
'lms_link'
:
lms_link
})
@login_required
def
edit_unit
(
request
,
location
):
"""
...
...
cms/envs/test.py
View file @
05c02f0d
...
...
@@ -38,17 +38,23 @@ STATICFILES_DIRS += [
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
=
{
'default'
:
{
'ENGINE'
:
'xmodule.modulestore.mongo.MongoModuleStore'
,
'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'
,
}
'OPTIONS'
:
modulestore_options
},
'direct'
:
{
'ENGINE'
:
'xmodule.modulestore.mongo.MongoModuleStore'
,
'OPTIONS'
:
modulestore_options
}
}
...
...
common/lib/xmodule/xmodule/modulestore/__init__.py
View file @
05c02f0d
...
...
@@ -240,11 +240,15 @@ class ModuleStore(object):
An abstract interface for a database backend that stores XModuleDescriptor
instances
"""
def
has_item
(
self
,
location
):
"""
Returns True if location exists in this ModuleStore.
"""
raise
NotImplementedError
def
get_item
(
self
,
location
,
depth
=
0
):
"""
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
xmodule.modulestore.exceptions.InsufficientSpecificationError
...
...
common/lib/xmodule/xmodule/modulestore/mongo.py
View file @
05c02f0d
...
...
@@ -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.
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
()
# Location dict is ordered by specificity, and SON
# will preserve that order for queries
for
key
,
val
in
Location
(
location
)
.
dict
()
.
iteritems
():
if
val
is
not
None
:
query
[
'_id.{key}'
.
format
(
key
=
key
)]
=
val
if
wildcard
and
val
is
None
:
continue
query
[
'_id.{key}'
.
format
(
key
=
key
)]
=
val
return
query
...
...
@@ -203,18 +207,27 @@ class MongoModuleStore(ModuleStoreBase):
ItemNotFoundError.
'''
item
=
self
.
collection
.
find_one
(
location_to_query
(
location
),
location_to_query
(
location
,
wildcard
=
False
),
sort
=
[(
'revision'
,
pymongo
.
ASCENDING
)],
)
if
item
is
None
:
raise
ItemNotFoundError
(
location
)
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
):
"""
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
xmodule.modulestore.exceptions.InsufficientSpecificationError
...
...
@@ -322,16 +335,10 @@ class MongoModuleStore(ModuleStoreBase):
'''Find all locations that are the parents of this location. Needed
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
be empty if there are no parents.
'''
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
()},
{
'_id'
:
True
})
return
[
i
[
'_id'
]
for
i
in
items
]
...
...
common/lib/xmodule/xmodule/modulestore/search.py
View file @
05c02f0d
...
...
@@ -60,10 +60,8 @@ def path_to_location(modulestore, course_id, location):
(
loc
,
path
)
=
queue
.
pop
()
# Takes from the end
loc
=
Location
(
loc
)
# get_parent_locations should raise ItemNotFoundError if location
# isn't found so we don't have to do it explicitly. Call this
# first to make sure the location is there (even if it's a course, and
# we would otherwise immediately exit).
# Call get_parent_locations 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
)
# print 'Processing loc={0}, path={1}'.format(loc, path)
...
...
@@ -81,6 +79,9 @@ def path_to_location(modulestore, course_id, location):
# If we're here, there is no path
return
None
if
not
modulestore
.
has_item
(
location
):
raise
ItemNotFoundError
path
=
find_path_to_course
()
if
path
is
None
:
raise
NoPathToItem
(
location
)
...
...
common/lib/xmodule/xmodule/modulestore/xml.py
View file @
05c02f0d
...
...
@@ -477,11 +477,16 @@ class XMLModuleStore(ModuleStoreBase):
except
KeyError
:
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
):
"""
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
xmodule.modulestore.exceptions.InsufficientSpecificationError
...
...
@@ -545,14 +550,8 @@ class XMLModuleStore(ModuleStoreBase):
'''Find all locations that are the parents of this location. Needed
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
be empty if there are no parents.
'''
location
=
Location
.
ensure_fully_specified
(
location
)
if
not
self
.
parent_tracker
.
is_known
(
location
):
raise
ItemNotFoundError
(
location
)
return
self
.
parent_tracker
.
parents
(
location
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment