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
ef78c99f
Commit
ef78c99f
authored
May 14, 2013
by
Chris Dodge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pep8/pylint violations fixes
parent
5d2b8879
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
37 deletions
+31
-37
cms/djangoapps/contentstore/tests/test_contentstore.py
+18
-18
common/lib/xmodule/xmodule/modulestore/__init__.py
+11
-17
common/lib/xmodule/xmodule/modulestore/draft.py
+2
-1
common/lib/xmodule/xmodule/modulestore/tests/factories.py
+0
-1
No files found.
cms/djangoapps/contentstore/tests/test_contentstore.py
View file @
ef78c99f
...
...
@@ -47,7 +47,7 @@ class MongoCollectionFindWrapper(object):
self
.
counter
=
0
def
find
(
self
,
query
,
*
args
,
**
kwargs
):
self
.
counter
=
self
.
counter
+
1
self
.
counter
=
self
.
counter
+
1
return
self
.
original
(
query
,
*
args
,
**
kwargs
)
...
...
@@ -357,7 +357,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
clone_items
=
module_store
.
get_items
(
Location
([
'i4x'
,
'MITx'
,
'999'
,
'vertical'
,
None
]))
self
.
assertGreater
(
len
(
clone_items
),
0
)
for
descriptor
in
items
:
new_loc
=
descriptor
.
location
.
_
replace
(
org
=
'MITx'
,
course
=
'999'
)
new_loc
=
descriptor
.
location
.
replace
(
org
=
'MITx'
,
course
=
'999'
)
print
"Checking {0} should now also be at {1}"
.
format
(
descriptor
.
location
.
url
(),
new_loc
.
url
())
resp
=
self
.
client
.
get
(
reverse
(
'edit_unit'
,
kwargs
=
{
'location'
:
new_loc
.
url
()}))
self
.
assertEqual
(
resp
.
status_code
,
200
)
...
...
@@ -380,15 +380,15 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self
.
assertEqual
(
len
(
items
),
0
)
def
verify_content_existence
(
self
,
modulestore
,
root_dir
,
location
,
dirname
,
category_name
,
filename_suffix
=
''
):
f
s
=
OSFS
(
root_dir
/
'test_export'
)
self
.
assertTrue
(
f
s
.
exists
(
dirname
))
f
ilesystem
=
OSFS
(
root_dir
/
'test_export'
)
self
.
assertTrue
(
f
ilesystem
.
exists
(
dirname
))
query_loc
=
Location
(
'i4x'
,
location
.
org
,
location
.
course
,
category_name
,
None
)
items
=
modulestore
.
get_items
(
query_loc
)
for
item
in
items
:
f
s
=
OSFS
(
root_dir
/
(
'test_export/'
+
dirname
))
self
.
assertTrue
(
f
s
.
exists
(
item
.
location
.
name
+
filename_suffix
))
f
ilesystem
=
OSFS
(
root_dir
/
(
'test_export/'
+
dirname
))
self
.
assertTrue
(
f
ilesystem
.
exists
(
item
.
location
.
name
+
filename_suffix
))
def
test_export_course
(
self
):
module_store
=
modulestore
(
'direct'
)
...
...
@@ -420,7 +420,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
# add private to list of children
sequential
=
module_store
.
get_item
(
Location
([
'i4x'
,
'edX'
,
'full'
,
'sequential'
,
'Administrivia_and_Circuit_Elements'
,
None
]))
private_location_no_draft
=
private_vertical
.
location
.
_
replace
(
revision
=
None
)
private_location_no_draft
=
private_vertical
.
location
.
replace
(
revision
=
None
)
module_store
.
update_children
(
sequential
.
location
,
sequential
.
children
+
[
private_location_no_draft
.
url
()])
...
...
@@ -445,20 +445,20 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self
.
verify_content_existence
(
module_store
,
root_dir
,
location
,
'custom_tags'
,
'custom_tag_template'
)
# check for graiding_policy.json
f
s
=
OSFS
(
root_dir
/
'test_export/policies/6.002_Spring_2012'
)
self
.
assertTrue
(
f
s
.
exists
(
'grading_policy.json'
))
f
ilesystem
=
OSFS
(
root_dir
/
'test_export/policies/6.002_Spring_2012'
)
self
.
assertTrue
(
f
ilesystem
.
exists
(
'grading_policy.json'
))
course
=
module_store
.
get_item
(
location
)
# compare what's on disk compared to what we have in our course
with
f
s
.
open
(
'grading_policy.json'
,
'r'
)
as
grading_policy
:
with
f
ilesystem
.
open
(
'grading_policy.json'
,
'r'
)
as
grading_policy
:
on_disk
=
loads
(
grading_policy
.
read
())
self
.
assertEqual
(
on_disk
,
course
.
grading_policy
)
#check for policy.json
self
.
assertTrue
(
f
s
.
exists
(
'policy.json'
))
self
.
assertTrue
(
f
ilesystem
.
exists
(
'policy.json'
))
# compare what's on disk to what we have in the course module
with
f
s
.
open
(
'policy.json'
,
'r'
)
as
course_policy
:
with
f
ilesystem
.
open
(
'policy.json'
,
'r'
)
as
course_policy
:
on_disk
=
loads
(
course_policy
.
read
())
self
.
assertIn
(
'course/6.002_Spring_2012'
,
on_disk
)
self
.
assertEqual
(
on_disk
[
'course/6.002_Spring_2012'
],
own_metadata
(
course
))
...
...
@@ -813,37 +813,37 @@ class ContentStoreTest(ModuleStoreTestCase):
self
.
assertEqual
(
200
,
resp
.
status_code
)
# go look at a subsection page
subsection_location
=
loc
.
_
replace
(
category
=
'sequential'
,
name
=
'test_sequence'
)
subsection_location
=
loc
.
replace
(
category
=
'sequential'
,
name
=
'test_sequence'
)
resp
=
self
.
client
.
get
(
reverse
(
'edit_subsection'
,
kwargs
=
{
'location'
:
subsection_location
.
url
()}))
self
.
assertEqual
(
200
,
resp
.
status_code
)
# go look at the Edit page
unit_location
=
loc
.
_
replace
(
category
=
'vertical'
,
name
=
'test_vertical'
)
unit_location
=
loc
.
replace
(
category
=
'vertical'
,
name
=
'test_vertical'
)
resp
=
self
.
client
.
get
(
reverse
(
'edit_unit'
,
kwargs
=
{
'location'
:
unit_location
.
url
()}))
self
.
assertEqual
(
200
,
resp
.
status_code
)
# delete a component
del_loc
=
loc
.
_
replace
(
category
=
'html'
,
name
=
'test_html'
)
del_loc
=
loc
.
replace
(
category
=
'html'
,
name
=
'test_html'
)
resp
=
self
.
client
.
post
(
reverse
(
'delete_item'
),
json
.
dumps
({
'id'
:
del_loc
.
url
()}),
"application/json"
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
# delete a unit
del_loc
=
loc
.
_
replace
(
category
=
'vertical'
,
name
=
'test_vertical'
)
del_loc
=
loc
.
replace
(
category
=
'vertical'
,
name
=
'test_vertical'
)
resp
=
self
.
client
.
post
(
reverse
(
'delete_item'
),
json
.
dumps
({
'id'
:
del_loc
.
url
()}),
"application/json"
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
# delete a unit
del_loc
=
loc
.
_
replace
(
category
=
'sequential'
,
name
=
'test_sequence'
)
del_loc
=
loc
.
replace
(
category
=
'sequential'
,
name
=
'test_sequence'
)
resp
=
self
.
client
.
post
(
reverse
(
'delete_item'
),
json
.
dumps
({
'id'
:
del_loc
.
url
()}),
"application/json"
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
# delete a chapter
del_loc
=
loc
.
_
replace
(
category
=
'chapter'
,
name
=
'chapter_2'
)
del_loc
=
loc
.
replace
(
category
=
'chapter'
,
name
=
'chapter_2'
)
resp
=
self
.
client
.
post
(
reverse
(
'delete_item'
),
json
.
dumps
({
'id'
:
del_loc
.
url
()}),
"application/json"
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
...
...
common/lib/xmodule/xmodule/modulestore/__init__.py
View file @
ef78c99f
...
...
@@ -9,7 +9,7 @@ import re
from
collections
import
namedtuple
from
.exceptions
import
InvalidLocationError
,
InsufficientSpecificationError
from
xmodule.errortracker
import
ErrorLog
,
make_error_tracker
from
xmodule.errortracker
import
make_error_tracker
from
bson.son
import
SON
log
=
logging
.
getLogger
(
'mitx.'
+
'modulestore'
)
...
...
@@ -64,7 +64,6 @@ class Location(_LocationBase):
"""
return
re
.
sub
(
'_+'
,
'_'
,
invalid
.
sub
(
'_'
,
value
))
@staticmethod
def
clean
(
value
):
"""
...
...
@@ -72,7 +71,6 @@ class Location(_LocationBase):
"""
return
Location
.
_clean
(
value
,
INVALID_CHARS
)
@staticmethod
def
clean_keeping_underscores
(
value
):
"""
...
...
@@ -82,7 +80,6 @@ class Location(_LocationBase):
"""
return
INVALID_CHARS
.
sub
(
'_'
,
value
)
@staticmethod
def
clean_for_url_name
(
value
):
"""
...
...
@@ -154,9 +151,7 @@ class Location(_LocationBase):
to mean wildcard selection.
"""
if
(
org
is
None
and
course
is
None
and
category
is
None
and
name
is
None
and
revision
is
None
):
if
(
org
is
None
and
course
is
None
and
category
is
None
and
name
is
None
and
revision
is
None
):
location
=
loc_or_tag
else
:
location
=
(
loc_or_tag
,
org
,
course
,
category
,
name
,
revision
)
...
...
@@ -191,7 +186,7 @@ class Location(_LocationBase):
match
=
MISSING_SLASH_URL_RE
.
match
(
location
)
if
match
is
None
:
log
.
debug
(
'location is instance of
%
s but no URL match'
%
basestring
)
raise
InvalidLocationError
(
location
)
raise
InvalidLocationError
(
location
)
groups
=
match
.
groupdict
()
check_dict
(
groups
)
return
_LocationBase
.
__new__
(
_cls
,
**
groups
)
...
...
@@ -233,7 +228,7 @@ class Location(_LocationBase):
html id attributes
"""
s
=
"-"
.
join
(
str
(
v
)
for
v
in
self
.
list
()
if
v
is
not
None
)
if
v
is
not
None
)
return
Location
.
clean_for_html
(
s
)
def
dict
(
self
):
...
...
@@ -258,6 +253,12 @@ class Location(_LocationBase):
at the location URL hierachy"""
return
"/"
.
join
([
self
.
org
,
self
.
course
,
self
.
name
])
def
replace
(
self
,
**
kwargs
):
'''
Expose a public method for replacing location elements
'''
return
self
.
_replace
(
**
kwargs
)
class
ModuleStore
(
object
):
"""
...
...
@@ -382,12 +383,6 @@ class ModuleStore(object):
'''
raise
NotImplementedError
def
get_course
(
self
,
course_id
):
'''
Look for a specific course id. Returns the course descriptor, or None if not found.
'''
raise
NotImplementedError
def
get_parent_locations
(
self
,
location
,
course_id
):
'''Find all locations that are the parents of this location in this
course. Needed for path_to_location().
...
...
@@ -406,8 +401,7 @@ class ModuleStore(object):
courses
=
[
course
for
course
in
self
.
get_courses
()
if
course
.
location
.
org
==
location
.
org
and
course
.
location
.
course
==
location
.
course
if
course
.
location
.
org
==
location
.
org
and
course
.
location
.
course
==
location
.
course
]
return
courses
...
...
common/lib/xmodule/xmodule/modulestore/draft.py
View file @
ef78c99f
...
...
@@ -13,11 +13,12 @@ def as_draft(location):
"""
return
Location
(
location
)
.
_replace
(
revision
=
DRAFT
)
def
as_published
(
location
):
"""
Returns the Location that is the published version for `location`
"""
return
Location
(
location
)
.
_replace
(
revision
=
None
)
return
Location
(
location
)
.
_replace
(
revision
=
None
)
def
wrap_draft
(
item
):
...
...
common/lib/xmodule/xmodule/modulestore/tests/factories.py
View file @
ef78c99f
...
...
@@ -3,7 +3,6 @@ from time import gmtime
from
uuid
import
uuid4
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.django
import
modulestore
from
xmodule.timeparse
import
stringify_time
from
xmodule.modulestore.inheritance
import
own_metadata
...
...
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