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
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
15 deletions
+33
-15
common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py
+13
-9
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
...
@@ -10,6 +10,7 @@ from xmodule.modulestore.locator import BlockUsageLocator
from
xmodule.modulestore.mongo
import
draft
from
xmodule.modulestore.mongo
import
draft
from
xmodule.modulestore
import
Location
from
xmodule.modulestore
import
Location
class
LocMapperStore
(
object
):
class
LocMapperStore
(
object
):
'''
'''
This store persists mappings among the addressing schemes. At this time, it's between the old i4x Location
This store persists mappings among the addressing schemes. At this time, it's between the old i4x Location
...
@@ -25,23 +26,27 @@ class LocMapperStore(object):
...
@@ -25,23 +26,27 @@ class LocMapperStore(object):
or dominant store, but that's not a requirement. This store creates its own connection.
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
):
def
__init__
(
self
,
host
,
db
,
collection
,
port
=
27017
,
user
=
None
,
password
=
None
,
**
kwargs
):
'''
'''
Constructor
Constructor
'''
'''
self
.
db
=
pymongo
.
database
.
Database
(
pymongo
.
MongoClient
(
self
.
db
=
pymongo
.
database
.
Database
(
pymongo
.
MongoClient
(
host
=
host
,
host
=
host
,
port
=
port
,
port
=
port
,
tz_aware
=
True
,
tz_aware
=
True
,
**
kwargs
**
kwargs
),
db
)
),
db
)
if
user
is
not
None
and
password
is
not
None
:
if
user
is
not
None
and
password
is
not
None
:
self
.
db
.
authenticate
(
user
,
password
)
self
.
db
.
authenticate
(
user
,
password
)
self
.
location_map
=
self
.
db
[
collection
+
'.location_map'
]
self
.
location_map
=
self
.
db
[
collection
+
'.location_map'
]
self
.
location_map
.
write_concern
=
{
'w'
:
1
}
self
.
location_map
.
write_concern
=
{
'w'
:
1
}
# location_map functions
# location_map functions
def
create_map_entry
(
self
,
course_location
,
course_id
=
None
,
draft_branch
=
'draft'
,
prod_branch
=
'published'
,
def
create_map_entry
(
self
,
course_location
,
course_id
=
None
,
draft_branch
=
'draft'
,
prod_branch
=
'published'
,
block_map
=
None
):
block_map
=
None
):
...
@@ -96,7 +101,6 @@ class LocMapperStore(object):
...
@@ -96,7 +101,6 @@ class LocMapperStore(object):
'block_map'
:
block_map
or
{},
'block_map'
:
block_map
or
{},
})
})
def
translate_location
(
self
,
old_style_course_id
,
location
,
published
=
True
,
add_entry_if_missing
=
True
):
def
translate_location
(
self
,
old_style_course_id
,
location
,
published
=
True
,
add_entry_if_missing
=
True
):
"""
"""
Translate the given module location to a Locator. If the mapping has the run id in it, then you
Translate the given module location to a Locator. If the mapping has the run id in it, then you
...
@@ -202,7 +206,6 @@ class LocMapperStore(object):
...
@@ -202,7 +206,6 @@ class LocMapperStore(object):
revision
)
revision
)
return
None
return
None
def
add_block_location_translator
(
self
,
location
,
old_course_id
=
None
,
usage_id
=
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
Similar to translate_location which adds an entry if none is found, but this cannot create a new
...
@@ -269,7 +272,6 @@ class LocMapperStore(object):
...
@@ -269,7 +272,6 @@ class LocMapperStore(object):
return
computed_usage_id
return
computed_usage_id
def
update_block_location_translator
(
self
,
location
,
usage_id
,
old_course_id
=
None
,
autogenerated_usage_id
=
False
):
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,
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):
...
@@ -307,7 +309,6 @@ class LocMapperStore(object):
return
usage_id
return
usage_id
def
delete_block_location_translator
(
self
,
location
,
old_course_id
=
None
):
def
delete_block_location_translator
(
self
,
location
,
old_course_id
=
None
):
"""
"""
Remove all existing maps from location's block.
Remove all existing maps from location's block.
...
@@ -349,8 +350,8 @@ class LocMapperStore(object):
...
@@ -349,8 +350,8 @@ class LocMapperStore(object):
"""
"""
if
course_id
:
if
course_id
:
# re doesn't allow ?P<_id.org> and ilk
# re doesn't allow ?P<_id.org> and ilk
m
=
re
.
match
(
r'([^/]+)/([^/]+)/([^/]+)'
,
course_id
)
m
atched
=
re
.
match
(
r'([^/]+)/([^/]+)/([^/]+)'
,
course_id
)
return
dict
(
zip
([
'_id.org'
,
'_id.course'
,
'_id.name'
],
m
.
groups
()))
return
dict
(
zip
([
'_id.org'
,
'_id.course'
,
'_id.name'
],
m
atched
.
groups
()))
location_id
=
{
'_id.org'
:
location
.
org
,
'_id.course'
:
location
.
course
}
location_id
=
{
'_id.org'
:
location
.
org
,
'_id.course'
:
location
.
course
}
if
location
.
category
==
'course'
:
if
location
.
category
==
'course'
:
...
@@ -358,6 +359,9 @@ class LocMapperStore(object):
...
@@ -358,6 +359,9 @@ class LocMapperStore(object):
return
location_id
return
location_id
def
_block_id_is_guid
(
self
,
name
):
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
return
len
(
name
)
==
32
and
re
.
search
(
r'[^0-9A-Fa-f]'
,
name
)
is
None
def
_verify_uniqueness
(
self
,
name
,
block_map
):
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
...
@@ -12,6 +12,9 @@ from xmodule.modulestore.loc_mapper_store import LocMapperStore
class
TestLocationMapper
(
unittest
.
TestCase
):
class
TestLocationMapper
(
unittest
.
TestCase
):
"""
Test the location to locator mapper
"""
def
setUp
(
self
):
def
setUp
(
self
):
modulestore_options
=
{
modulestore_options
=
{
...
@@ -23,11 +26,10 @@ class TestLocationMapper(unittest.TestCase):
...
@@ -23,11 +26,10 @@ class TestLocationMapper(unittest.TestCase):
# pylint: disable=W0142
# pylint: disable=W0142
TestLocationMapper
.
loc_store
=
LocMapperStore
(
**
modulestore_options
)
TestLocationMapper
.
loc_store
=
LocMapperStore
(
**
modulestore_options
)
def
tearDown
(
self
):
def
tearDown
(
self
):
db
=
TestLocationMapper
.
loc_store
.
db
db
ref
=
TestLocationMapper
.
loc_store
.
db
db
.
drop_collection
(
TestLocationMapper
.
loc_store
.
location_map
)
db
ref
.
drop_collection
(
TestLocationMapper
.
loc_store
.
location_map
)
db
.
connection
.
close
()
db
ref
.
connection
.
close
()
TestLocationMapper
.
loc_store
=
None
TestLocationMapper
.
loc_store
=
None
def
test_create_map
(
self
):
def
test_create_map
(
self
):
...
@@ -438,7 +440,6 @@ class TestLocationMapper(unittest.TestCase):
...
@@ -438,7 +440,6 @@ class TestLocationMapper(unittest.TestCase):
)
)
self
.
assertEqual
(
trans_loc
.
name
,
'1'
)
self
.
assertEqual
(
trans_loc
.
name
,
'1'
)
def
test_delete_block
(
self
):
def
test_delete_block
(
self
):
"""
"""
test delete_block_location_translator(location, old_course_id=None)
test delete_block_location_translator(location, old_course_id=None)
...
@@ -490,10 +491,17 @@ class TestLocationMapper(unittest.TestCase):
...
@@ -490,10 +491,17 @@ class TestLocationMapper(unittest.TestCase):
)
)
self
.
assertEqual
(
locator
.
usage_id
,
'problem3'
)
self
.
assertEqual
(
locator
.
usage_id
,
'problem3'
)
#==================================
#==================================
# functions to mock existing services
# functions to mock existing services
def
loc_mapper
():
def
loc_mapper
():
"""
Mocks the global location mapper.
"""
return
TestLocationMapper
.
loc_store
return
TestLocationMapper
.
loc_store
def
render_to_template_mock
(
*
_args
):
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):
...
@@ -252,12 +252,18 @@ class LocatorTest(TestCase):
def
check_course_locn_fields
(
self
,
testobj
,
msg
,
version_guid
=
None
,
def
check_course_locn_fields
(
self
,
testobj
,
msg
,
version_guid
=
None
,
course_id
=
None
,
branch
=
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
.
version_guid
,
version_guid
,
msg
)
self
.
assertEqual
(
testobj
.
course_id
,
course_id
,
msg
)
self
.
assertEqual
(
testobj
.
course_id
,
course_id
,
msg
)
self
.
assertEqual
(
testobj
.
branch
,
branch
,
msg
)
self
.
assertEqual
(
testobj
.
branch
,
branch
,
msg
)
def
check_block_locn_fields
(
self
,
testobj
,
msg
,
version_guid
=
None
,
def
check_block_locn_fields
(
self
,
testobj
,
msg
,
version_guid
=
None
,
course_id
=
None
,
branch
=
None
,
block
=
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
,
self
.
check_course_locn_fields
(
testobj
,
msg
,
version_guid
,
course_id
,
branch
)
branch
)
self
.
assertEqual
(
testobj
.
usage_id
,
block
)
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