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
9a90579f
Commit
9a90579f
authored
Jul 28, 2014
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move test_path_to_location to mixed testing
parent
8268724e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
50 deletions
+59
-50
common/lib/xmodule/xmodule/modulestore/search.py
+1
-1
common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py
+57
-0
common/lib/xmodule/xmodule/modulestore/tests/test_modulestore.py
+1
-31
common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py
+0
-7
common/lib/xmodule/xmodule/modulestore/tests/test_xml.py
+0
-11
No files found.
common/lib/xmodule/xmodule/modulestore/search.py
View file @
9a90579f
...
...
@@ -95,7 +95,7 @@ def path_to_location(modulestore, usage_key):
category
=
path
[
path_index
]
.
block_type
if
category
==
'sequential'
or
category
==
'videosequence'
:
section_desc
=
modulestore
.
get_item
(
path
[
path_index
])
child_locs
=
[
c
.
location
for
c
in
section_desc
.
get_children
()]
child_locs
=
[
c
.
location
.
version_agnostic
()
for
c
in
section_desc
.
get_children
()]
# positions are 1-indexed, and should be strings to be consistent with
# url parsing.
position_list
.
append
(
str
(
child_locs
.
index
(
path
[
path_index
+
1
])
+
1
))
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py
View file @
9a90579f
...
...
@@ -20,6 +20,7 @@ from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator
# TODO remove this import and the configuration -- xmodule should not depend on django!
from
django.conf
import
settings
from
xmodule.modulestore.tests.factories
import
check_mongo_calls
from
xmodule.modulestore.search
import
path_to_location
if
not
settings
.
configured
:
settings
.
configure
()
from
xmodule.modulestore.mixed
import
MixedModuleStore
...
...
@@ -667,6 +668,62 @@ class TestMixedModuleStore(unittest.TestCase):
(
child_to_delete_location
,
None
,
ModuleStoreEnum
.
RevisionOption
.
published_only
),
])
@ddt.data
((
'draft'
,
[
10
,
3
],
0
),
(
'split'
,
[
14
,
6
],
0
))
@ddt.unpack
def
test_path_to_location
(
self
,
default_ms
,
num_finds
,
num_sends
):
"""
Make sure that path_to_location works
"""
self
.
initdb
(
default_ms
)
self
.
_create_block_hierarchy
()
course_key
=
self
.
course_locations
[
self
.
MONGO_COURSEID
]
.
course_key
should_work
=
(
(
self
.
problem_x1a_2
,
(
course_key
,
u"Chapter_x"
,
u"Sequential_x1"
,
'1'
)),
(
self
.
chapter_x
,
(
course_key
,
"Chapter_x"
,
None
,
None
)),
)
mongo_store
=
self
.
store
.
_get_modulestore_for_courseid
(
self
.
_course_key_from_string
(
self
.
MONGO_COURSEID
))
for
location
,
expected
in
should_work
:
with
check_mongo_calls
(
mongo_store
,
num_finds
.
pop
(
0
),
num_sends
):
self
.
assertEqual
(
path_to_location
(
self
.
store
,
location
),
expected
)
not_found
=
(
course_key
.
make_usage_key
(
'video'
,
'WelcomeX'
),
course_key
.
make_usage_key
(
'course'
,
'NotHome'
),
)
for
location
in
not_found
:
with
self
.
assertRaises
(
ItemNotFoundError
):
path_to_location
(
self
.
store
,
location
)
def
test_xml_path_to_location
(
self
):
"""
Make sure that path_to_location works: should be passed a modulestore
with the toy and simple courses loaded.
"""
# only needs course_locations set
self
.
initdb
(
'draft'
)
course_key
=
self
.
course_locations
[
self
.
XML_COURSEID1
]
.
course_key
should_work
=
(
(
course_key
.
make_usage_key
(
'video'
,
'Welcome'
),
(
course_key
,
"Overview"
,
"Welcome"
,
None
)),
(
course_key
.
make_usage_key
(
'chapter'
,
'Overview'
),
(
course_key
,
"Overview"
,
None
,
None
)),
)
for
location
,
expected
in
should_work
:
self
.
assertEqual
(
path_to_location
(
self
.
store
,
location
),
expected
)
not_found
=
(
course_key
.
make_usage_key
(
'video'
,
'WelcomeX'
),
course_key
.
make_usage_key
(
'course'
,
'NotHome'
),
)
for
location
in
not_found
:
with
self
.
assertRaises
(
ItemNotFoundError
):
path_to_location
(
self
.
store
,
location
)
@ddt.data
(
'draft'
)
def
test_revert_to_published_root_draft
(
self
,
default_ms
):
"""
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_modulestore.py
View file @
9a90579f
from
nose.tools
import
assert_equals
,
assert_raises
,
assert_true
,
assert_false
# pylint: disable=E0611
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
from
xmodule.modulestore.search
import
path_to_location
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
def
check_path_to_location
(
modulestore
):
"""
Make sure that path_to_location works: should be passed a modulestore
with the toy and simple courses loaded.
"""
course_id
=
SlashSeparatedCourseKey
(
"edX"
,
"toy"
,
"2012_Fall"
)
should_work
=
(
(
course_id
.
make_usage_key
(
'video'
,
'Welcome'
),
(
course_id
,
"Overview"
,
"Welcome"
,
None
)),
(
course_id
.
make_usage_key
(
'chapter'
,
'Overview'
),
(
course_id
,
"Overview"
,
None
,
None
)),
)
for
location
,
expected
in
should_work
:
assert_equals
(
path_to_location
(
modulestore
,
location
),
expected
)
not_found
=
(
course_id
.
make_usage_key
(
'video'
,
'WelcomeX'
),
course_id
.
make_usage_key
(
'course'
,
'NotHome'
),
)
for
location
in
not_found
:
with
assert_raises
(
ItemNotFoundError
):
path_to_location
(
modulestore
,
location
)
from
nose.tools
import
assert_equals
,
assert_true
,
assert_false
# pylint: disable=E0611
def
check_has_course_method
(
modulestore
,
locator
,
locator_key_fields
):
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py
View file @
9a90579f
...
...
@@ -31,13 +31,11 @@ from xmodule.modulestore.xml_exporter import export_to_xml
from
xmodule.modulestore.xml_importer
import
import_from_xml
,
perform_xlint
from
xmodule.contentstore.mongo
import
MongoContentStore
from
xmodule.modulestore.tests.test_modulestore
import
check_path_to_location
from
nose.tools
import
assert_in
from
xmodule.exceptions
import
NotFoundError
from
git.test.lib.asserts
import
assert_not_none
from
xmodule.x_module
import
XModuleMixin
from
xmodule.modulestore.mongo.base
import
as_draft
from
xmodule.modulestore.tests.factories
import
check_mongo_calls
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -245,11 +243,6 @@ class TestMongoModuleStore(unittest.TestCase):
self
.
draft_store
.
_find_one
(
Location
(
'edX'
,
'toy'
,
'2012_Fall'
,
'video'
,
'Welcome'
)),
)
def
test_path_to_location
(
self
):
'''Make sure that path_to_location works'''
with
check_mongo_calls
(
self
.
draft_store
,
9
):
check_path_to_location
(
self
.
draft_store
)
def
test_xlinter
(
self
):
'''
Run through the xlinter, we know the 'toy' course has violations, but the
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_xml.py
View file @
9a90579f
...
...
@@ -8,10 +8,8 @@ from glob import glob
from
mock
import
patch
from
xmodule.modulestore.xml
import
XMLModuleStore
from
opaque_keys.edx.locations
import
Location
from
xmodule.modulestore
import
ModuleStoreEnum
from
.test_modulestore
import
check_path_to_location
from
xmodule.tests
import
DATA_DIR
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
xmodule.modulestore.tests.test_modulestore
import
check_has_course_method
...
...
@@ -32,15 +30,6 @@ class TestXMLModuleStore(unittest.TestCase):
"""
Test around the XML modulestore
"""
def
test_path_to_location
(
self
):
"""Make sure that path_to_location works properly"""
print
"Starting import"
modulestore
=
XMLModuleStore
(
DATA_DIR
,
course_dirs
=
[
'toy'
,
'simple'
])
print
"finished import"
check_path_to_location
(
modulestore
)
def
test_xml_modulestore_type
(
self
):
store
=
XMLModuleStore
(
DATA_DIR
,
course_dirs
=
[
'toy'
,
'simple'
])
self
.
assertEqual
(
store
.
get_modulestore_type
(),
ModuleStoreEnum
.
Type
.
xml
)
...
...
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