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
05712da6
Commit
05712da6
authored
Aug 20, 2013
by
Christina Roberts
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #744 from edx/dhm/pep_pylint_cleanups
Add doc strings and fix spaces
parents
4129c1cf
20641bab
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
27 deletions
+45
-27
common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py
+25
-21
common/lib/xmodule/xmodule/modulestore/tests/test_location_mapper.py
+14
-6
common/lib/xmodule/xmodule/modulestore/tests/test_locators.py
+6
-0
No files found.
common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py
View file @
05712da6
...
...
@@ -10,6 +10,7 @@ from xmodule.modulestore.locator import BlockUsageLocator
from
xmodule.modulestore.mongo
import
draft
from
xmodule.modulestore
import
Location
class
LocMapperStore
(
object
):
'''
This store persists mappings among the addressing schemes. At this time, it's between the old i4x Location
...
...
@@ -25,26 +26,30 @@ class LocMapperStore(object):
or dominant store, but that's not a requirement. This store creates its own connection.
'''
# C0103: varnames and attrs must be >= 3 chars, but db defined by long time usage
# pylint: disable = C0103
def
__init__
(
self
,
host
,
db
,
collection
,
port
=
27017
,
user
=
None
,
password
=
None
,
**
kwargs
):
'''
Constructor
'''
self
.
db
=
pymongo
.
database
.
Database
(
pymongo
.
MongoClient
(
host
=
host
,
port
=
port
,
tz_aware
=
True
,
**
kwargs
),
db
)
self
.
db
=
pymongo
.
database
.
Database
(
pymongo
.
MongoClient
(
host
=
host
,
port
=
port
,
tz_aware
=
True
,
**
kwargs
),
db
)
if
user
is
not
None
and
password
is
not
None
:
self
.
db
.
authenticate
(
user
,
password
)
self
.
location_map
=
self
.
db
[
collection
+
'.location_map'
]
self
.
location_map
.
write_concern
=
{
'w'
:
1
}
# location_map functions
def
create_map_entry
(
self
,
course_location
,
course_id
=
None
,
draft_branch
=
'draft'
,
prod_branch
=
'published'
,
block_map
=
None
):
block_map
=
None
):
"""
Add a new entry to map this course_location to the new style CourseLocator.course_id. If course_id is not
provided, it creates the default map of using org.course.name from the location (just like course_id) if
...
...
@@ -89,13 +94,12 @@ class LocMapperStore(object):
location_id
[
'name'
]
=
course_location
.
name
self
.
location_map
.
insert
({
'_id'
:
location_id
,
'course_id'
:
course_id
,
'draft_branch'
:
draft_branch
,
'prod_branch'
:
prod_branch
,
'block_map'
:
block_map
or
{},
})
'_id'
:
location_id
,
'course_id'
:
course_id
,
'draft_branch'
:
draft_branch
,
'prod_branch'
:
prod_branch
,
'block_map'
:
block_map
or
{},
})
def
translate_location
(
self
,
old_style_course_id
,
location
,
published
=
True
,
add_entry_if_missing
=
True
):
"""
...
...
@@ -202,7 +206,6 @@ class LocMapperStore(object):
revision
)
return
None
def
add_block_location_translator
(
self
,
location
,
old_course_id
=
None
,
usage_id
=
None
):
"""
Similar to translate_location which adds an entry if none is found, but this cannot create a new
...
...
@@ -250,7 +253,7 @@ class LocMapperStore(object):
if
computed_usage_id
is
None
:
computed_usage_id
=
self
.
_add_to_block_map
(
location
,
location_id
,
map_entry
[
'block_map'
])
elif
(
location
.
name
not
in
map_entry
[
'block_map'
]
or
location
.
category
not
in
map_entry
[
'block_map'
][
location
.
name
]):
location
.
category
not
in
map_entry
[
'block_map'
][
location
.
name
]):
alt_usage_id
=
self
.
_verify_uniqueness
(
computed_usage_id
,
map_entry
[
'block_map'
])
if
alt_usage_id
!=
computed_usage_id
:
if
usage_id
is
not
None
:
...
...
@@ -269,7 +272,6 @@ class LocMapperStore(object):
return
computed_usage_id
def
update_block_location_translator
(
self
,
location
,
usage_id
,
old_course_id
=
None
,
autogenerated_usage_id
=
False
):
"""
Update all existing maps from location's block to the new usage_id. Used for changing the usage_id,
...
...
@@ -307,7 +309,6 @@ class LocMapperStore(object):
return
usage_id
def
delete_block_location_translator
(
self
,
location
,
old_course_id
=
None
):
"""
Remove all existing maps from location's block.
...
...
@@ -349,8 +350,8 @@ class LocMapperStore(object):
"""
if
course_id
:
# re doesn't allow ?P<_id.org> and ilk
m
=
re
.
match
(
r'([^/]+)/([^/]+)/([^/]+)'
,
course_id
)
return
dict
(
zip
([
'_id.org'
,
'_id.course'
,
'_id.name'
],
m
.
groups
()))
m
atched
=
re
.
match
(
r'([^/]+)/([^/]+)/([^/]+)'
,
course_id
)
return
dict
(
zip
([
'_id.org'
,
'_id.course'
,
'_id.name'
],
m
atched
.
groups
()))
location_id
=
{
'_id.org'
:
location
.
org
,
'_id.course'
:
location
.
course
}
if
location
.
category
==
'course'
:
...
...
@@ -358,6 +359,9 @@ class LocMapperStore(object):
return
location_id
def
_block_id_is_guid
(
self
,
name
):
"""
Does the given name look like it's a guid?
"""
return
len
(
name
)
==
32
and
re
.
search
(
r'[^0-9A-Fa-f]'
,
name
)
is
None
def
_verify_uniqueness
(
self
,
name
,
block_map
):
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_location_mapper.py
View file @
05712da6
...
...
@@ -12,6 +12,9 @@ from xmodule.modulestore.loc_mapper_store import LocMapperStore
class
TestLocationMapper
(
unittest
.
TestCase
):
"""
Test the location to locator mapper
"""
def
setUp
(
self
):
modulestore_options
=
{
...
...
@@ -23,11 +26,10 @@ class TestLocationMapper(unittest.TestCase):
# pylint: disable=W0142
TestLocationMapper
.
loc_store
=
LocMapperStore
(
**
modulestore_options
)
def
tearDown
(
self
):
db
=
TestLocationMapper
.
loc_store
.
db
db
.
drop_collection
(
TestLocationMapper
.
loc_store
.
location_map
)
db
.
connection
.
close
()
db
ref
=
TestLocationMapper
.
loc_store
.
db
db
ref
.
drop_collection
(
TestLocationMapper
.
loc_store
.
location_map
)
db
ref
.
connection
.
close
()
TestLocationMapper
.
loc_store
=
None
def
test_create_map
(
self
):
...
...
@@ -438,7 +440,6 @@ class TestLocationMapper(unittest.TestCase):
)
self
.
assertEqual
(
trans_loc
.
name
,
'1'
)
def
test_delete_block
(
self
):
"""
test delete_block_location_translator(location, old_course_id=None)
...
...
@@ -490,10 +491,17 @@ class TestLocationMapper(unittest.TestCase):
)
self
.
assertEqual
(
locator
.
usage_id
,
'problem3'
)
#==================================
# functions to mock existing services
def
loc_mapper
():
"""
Mocks the global location mapper.
"""
return
TestLocationMapper
.
loc_store
def
render_to_template_mock
(
*
_args
):
pass
"""
Mocks the mako render_to_template w/ a noop
"""
common/lib/xmodule/xmodule/modulestore/tests/test_locators.py
View file @
05712da6
...
...
@@ -252,12 +252,18 @@ class LocatorTest(TestCase):
def
check_course_locn_fields
(
self
,
testobj
,
msg
,
version_guid
=
None
,
course_id
=
None
,
branch
=
None
):
"""
Checks the version, course_id, and branch in testobj
"""
self
.
assertEqual
(
testobj
.
version_guid
,
version_guid
,
msg
)
self
.
assertEqual
(
testobj
.
course_id
,
course_id
,
msg
)
self
.
assertEqual
(
testobj
.
branch
,
branch
,
msg
)
def
check_block_locn_fields
(
self
,
testobj
,
msg
,
version_guid
=
None
,
course_id
=
None
,
branch
=
None
,
block
=
None
):
"""
Does adds a block id check over and above the check_course_locn_fields tests
"""
self
.
check_course_locn_fields
(
testobj
,
msg
,
version_guid
,
course_id
,
branch
)
self
.
assertEqual
(
testobj
.
usage_id
,
block
)
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