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
aab5e044
Commit
aab5e044
authored
Feb 28, 2014
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mixed modulestore handles most modulestore functions, cont.
parent
371ecb08
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
31 deletions
+21
-31
common/lib/xmodule/xmodule/modulestore/mixed.py
+4
-4
common/lib/xmodule/xmodule/modulestore/mongo/base.py
+1
-1
common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py
+16
-26
No files found.
common/lib/xmodule/xmodule/modulestore/mixed.py
View file @
aab5e044
...
...
@@ -125,7 +125,7 @@ class MixedModuleStore(ModuleStoreWriteBase):
# order the modulestores and ensure no dupes (default may be a dupe of a named store)
# remove 'draft' as we know it's a functional dupe of 'direct' (ugly hardcoding)
stores
=
set
([
value
for
key
,
value
in
self
.
modulestores
.
iteritems
()
if
key
!=
'draft'
])
stores
=
sorted
(
stores
,
_compare_stores
)
stores
=
sorted
(
stores
,
cmp
=
_compare_stores
)
courses
=
{}
# a dictionary of stringified course locations to course objects
has_locators
=
any
(
issubclass
(
CourseLocator
,
store
.
reference_type
)
for
store
in
stores
)
...
...
@@ -214,9 +214,9 @@ class MixedModuleStore(ModuleStoreWriteBase):
pass
try
:
course
=
store
.
_get_course_for_item
(
block
.
scope_ids
.
usage_id
)
if
course
:
if
course
is
not
None
:
return
course
.
scope_ids
.
usage_id
.
course_id
except
:
# sorry, that method just raises vanilla Exception if it doesn't find course
except
Exception
:
# sorry, that method just raises vanilla Exception if it doesn't find course
pass
def
_infer_course_id_try
(
self
,
location
):
...
...
@@ -436,7 +436,7 @@ class MixedModuleStore(ModuleStoreWriteBase):
"""
store
=
self
.
modulestores
[
store_name
]
if
store
.
reference_type
!=
Location
:
raise
NotImplemented
Error
(
u"Cannot create maps from
%
s"
%
store
.
reference_type
)
raise
Value
Error
(
u"Cannot create maps from
%
s"
%
store
.
reference_type
)
for
course
in
store
.
get_courses
():
loc_mapper
()
.
translate_location
(
course
.
location
.
course_id
,
course
.
location
)
...
...
common/lib/xmodule/xmodule/modulestore/mongo/base.py
View file @
aab5e044
...
...
@@ -681,7 +681,7 @@ class MongoModuleStore(ModuleStoreWriteBase):
dbmodel
,
)
for
key
,
value
in
fields
.
iteritems
():
xmodule
[
key
]
=
value
setattr
(
xmodule
,
key
,
value
)
# decache any pending field settings from init
xmodule
.
save
()
return
xmodule
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py
View file @
aab5e044
...
...
@@ -33,7 +33,7 @@ class TestMixedModuleStore(LocMapperSetupSansDjango):
DEFAULT_CLASS
=
'xmodule.raw_module.RawDescriptor'
RENDER_TEMPLATE
=
lambda
t_n
,
d
,
ctx
=
None
,
nsp
=
'main'
:
''
IMPORT
_COURSEID
=
'MITx/999/2013_Spring'
MONGO
_COURSEID
=
'MITx/999/2013_Spring'
XML_COURSEID1
=
'edX/toy/2012_Fall'
XML_COURSEID2
=
'edX/simple/2012_Fall'
...
...
@@ -51,7 +51,7 @@ class TestMixedModuleStore(LocMapperSetupSansDjango):
'mappings'
:
{
XML_COURSEID1
:
'xml'
,
XML_COURSEID2
:
'xml'
,
IMPORT
_COURSEID
:
'default'
MONGO
_COURSEID
:
'default'
},
'stores'
:
{
'xml'
:
{
...
...
@@ -124,17 +124,7 @@ class TestMixedModuleStore(LocMapperSetupSansDjango):
course
.
location
,
item_location
.
category
,
location
=
item_location
,
block_id
=
item_location
.
name
)
if
isinstance
(
course
.
location
,
CourseLocator
):
# add_entry is false b/c this is a test that the right thing happened w/o
# wanting any additional side effects
lookup_map
=
loc_mapper
()
.
translate_location
(
course_location
.
course_id
,
course_location
,
add_entry_if_missing
=
False
)
self
.
assertEqual
(
lookup_map
,
course
.
location
)
self
.
course_locations
[
self
.
IMPORT_COURSEID
]
=
course
.
location
.
version_agnostic
()
lookup_map
=
loc_mapper
()
.
translate_location
(
course_location
.
course_id
,
item_location
,
add_entry_if_missing
=
False
)
self
.
assertEqual
(
lookup_map
,
chapter
.
location
)
self
.
course_locations
[
self
.
MONGO_COURSEID
]
=
course
.
location
.
version_agnostic
()
self
.
import_chapter_location
=
chapter
.
location
.
version_agnostic
()
else
:
self
.
assertEqual
(
course
.
location
,
course_location
)
...
...
@@ -160,17 +150,17 @@ class TestMixedModuleStore(LocMapperSetupSansDjango):
self
.
course_locations
=
{
course_id
:
generate_location
(
course_id
)
for
course_id
in
[
self
.
IMPORT
_COURSEID
,
self
.
XML_COURSEID1
,
self
.
XML_COURSEID2
]
for
course_id
in
[
self
.
MONGO
_COURSEID
,
self
.
XML_COURSEID1
,
self
.
XML_COURSEID2
]
}
self
.
fake_location
=
Location
(
'i4x'
,
'foo'
,
'bar'
,
'vertical'
,
'baz'
)
self
.
import_chapter_location
=
self
.
course_locations
[
self
.
IMPORT
_COURSEID
]
.
replace
(
self
.
import_chapter_location
=
self
.
course_locations
[
self
.
MONGO
_COURSEID
]
.
replace
(
category
=
'chapter'
,
name
=
'Overview'
)
self
.
xml_chapter_location
=
self
.
course_locations
[
self
.
XML_COURSEID1
]
.
replace
(
category
=
'chapter'
,
name
=
'Overview'
)
# grab old style location b4 possibly converted
import_location
=
self
.
course_locations
[
self
.
IMPORT
_COURSEID
]
import_location
=
self
.
course_locations
[
self
.
MONGO
_COURSEID
]
# get Locators and set up the loc mapper if app is Locator based
if
default
==
'split'
:
self
.
fake_location
=
loc_mapper
()
.
translate_location
(
'foo/bar/2012_Fall'
,
self
.
fake_location
)
...
...
@@ -186,7 +176,7 @@ class TestMixedModuleStore(LocMapperSetupSansDjango):
self
.
assertEqual
(
self
.
store
.
get_modulestore_type
(
self
.
XML_COURSEID1
),
XML_MODULESTORE_TYPE
)
self
.
assertEqual
(
self
.
store
.
get_modulestore_type
(
self
.
XML_COURSEID2
),
XML_MODULESTORE_TYPE
)
mongo_ms_type
=
MONGO_MODULESTORE_TYPE
if
default_ms
==
'direct'
else
SPLIT_MONGO_MODULESTORE_TYPE
self
.
assertEqual
(
self
.
store
.
get_modulestore_type
(
self
.
IMPORT
_COURSEID
),
mongo_ms_type
)
self
.
assertEqual
(
self
.
store
.
get_modulestore_type
(
self
.
MONGO
_COURSEID
),
mongo_ms_type
)
# try an unknown mapping, it should be the 'default' store
self
.
assertEqual
(
self
.
store
.
get_modulestore_type
(
'foo/bar/2012_Fall'
),
mongo_ms_type
)
...
...
@@ -201,7 +191,7 @@ class TestMixedModuleStore(LocMapperSetupSansDjango):
self
.
XML_COURSEID1
,
self
.
course_locations
[
self
.
XML_COURSEID1
]
.
replace
(
name
=
'not_findable'
,
category
=
'problem'
)
))
self
.
assertFalse
(
self
.
store
.
has_item
(
self
.
IMPORT
_COURSEID
,
self
.
fake_location
))
self
.
assertFalse
(
self
.
store
.
has_item
(
self
.
MONGO
_COURSEID
,
self
.
fake_location
))
@ddt.data
(
'direct'
,
'split'
)
def
test_get_item
(
self
,
default_ms
):
...
...
@@ -222,7 +212,7 @@ class TestMixedModuleStore(LocMapperSetupSansDjango):
self
.
course_locations
[
self
.
XML_COURSEID1
]
.
replace
(
name
=
'not_findable'
,
category
=
'problem'
)
)
with
self
.
assertRaises
(
ItemNotFoundError
):
self
.
store
.
get_instance
(
self
.
IMPORT
_COURSEID
,
self
.
fake_location
)
self
.
store
.
get_instance
(
self
.
MONGO
_COURSEID
,
self
.
fake_location
)
@ddt.data
(
'direct'
,
'split'
)
def
test_get_items
(
self
,
default_ms
):
...
...
@@ -252,10 +242,10 @@ class TestMixedModuleStore(LocMapperSetupSansDjango):
self
.
store
.
update_item
(
course
,
None
)
# now do it for a r/w db
# get_course api's are inconsistent: one takes Locators the other an old style course id
if
hasattr
(
self
.
course_locations
[
self
.
IMPORT
_COURSEID
],
'as_course_locator'
):
locn
=
self
.
course_locations
[
self
.
IMPORT
_COURSEID
]
if
hasattr
(
self
.
course_locations
[
self
.
MONGO
_COURSEID
],
'as_course_locator'
):
locn
=
self
.
course_locations
[
self
.
MONGO
_COURSEID
]
else
:
locn
=
self
.
IMPORT
_COURSEID
locn
=
self
.
MONGO
_COURSEID
course
=
self
.
store
.
get_course
(
locn
)
# if following raised, then the test is really a noop, change it
self
.
assertFalse
(
course
.
show_calculator
,
"Default changed making test meaningless"
)
...
...
@@ -276,7 +266,7 @@ class TestMixedModuleStore(LocMapperSetupSansDjango):
self
.
store
.
delete_item
(
self
.
import_chapter_location
,
'**replace_user**'
)
# verify it's gone
with
self
.
assertRaises
(
ItemNotFoundError
):
self
.
store
.
get_instance
(
self
.
IMPORT
_COURSEID
,
self
.
import_chapter_location
)
self
.
store
.
get_instance
(
self
.
MONGO
_COURSEID
,
self
.
import_chapter_location
)
@ddt.data
(
'direct'
,
'split'
)
def
test_get_courses
(
self
,
default_ms
):
...
...
@@ -289,7 +279,7 @@ class TestMixedModuleStore(LocMapperSetupSansDjango):
if
hasattr
(
course
.
location
,
'version_agnostic'
)
else
course
.
location
for
course
in
courses
]
self
.
assertIn
(
self
.
course_locations
[
self
.
IMPORT
_COURSEID
],
course_ids
)
self
.
assertIn
(
self
.
course_locations
[
self
.
MONGO
_COURSEID
],
course_ids
)
self
.
assertIn
(
self
.
course_locations
[
self
.
XML_COURSEID1
],
course_ids
)
self
.
assertIn
(
self
.
course_locations
[
self
.
XML_COURSEID2
],
course_ids
)
...
...
@@ -325,10 +315,10 @@ class TestMixedModuleStore(LocMapperSetupSansDjango):
self
.
initdb
(
default_ms
)
parents
=
self
.
store
.
get_parent_locations
(
self
.
import_chapter_location
,
self
.
IMPORT
_COURSEID
self
.
MONGO
_COURSEID
)
self
.
assertEqual
(
len
(
parents
),
1
)
self
.
assertEqual
(
parents
[
0
],
self
.
course_locations
[
self
.
IMPORT
_COURSEID
])
self
.
assertEqual
(
parents
[
0
],
self
.
course_locations
[
self
.
MONGO
_COURSEID
])
parents
=
self
.
store
.
get_parent_locations
(
self
.
xml_chapter_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