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
ae99a170
Commit
ae99a170
authored
May 09, 2014
by
Don Mitchell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3659 from edx/opaque-keys-validate
Opaque keys validate
parents
a558980e
69a2d988
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
46 deletions
+12
-46
cms/djangoapps/contentstore/management/commands/edit_course_tabs.py
+1
-0
lms/djangoapps/courseware/courses.py
+9
-17
lms/djangoapps/courseware/tests/test_courses.py
+2
-29
No files found.
cms/djangoapps/contentstore/management/commands/edit_course_tabs.py
View file @
ae99a170
...
@@ -71,6 +71,7 @@ command again, adding --insert or --delete to edit the list.
...
@@ -71,6 +71,7 @@ command again, adding --insert or --delete to edit the list.
course_key
=
CourseKey
.
from_string
(
options
[
'course'
])
course_key
=
CourseKey
.
from_string
(
options
[
'course'
])
except
InvalidKeyError
:
except
InvalidKeyError
:
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
options
[
'course'
])
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
options
[
'course'
])
print
u'Warning: you are using a deprecated format. Please use {} in the future'
.
format
(
course_key
)
course
=
get_course_by_id
(
course_key
)
course
=
get_course_by_id
(
course_key
)
print
'Warning: this command directly edits the list of course tabs in mongo.'
print
'Warning: this command directly edits the list of course tabs in mongo.'
...
...
lms/djangoapps/courseware/courses.py
View file @
ae99a170
...
@@ -12,7 +12,7 @@ from xmodule.modulestore import XML_MODULESTORE_TYPE
...
@@ -12,7 +12,7 @@ from xmodule.modulestore import XML_MODULESTORE_TYPE
from
xmodule.modulestore.keys
import
CourseKey
from
xmodule.modulestore.keys
import
CourseKey
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
from
xmodule.contentstore.content
import
StaticContent
from
xmodule.contentstore.content
import
StaticContent
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
,
InvalidLocationError
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
from
static_replace
import
replace_static_urls
from
static_replace
import
replace_static_urls
from
xmodule.modulestore
import
MONGO_MODULESTORE_TYPE
from
xmodule.modulestore
import
MONGO_MODULESTORE_TYPE
...
@@ -43,18 +43,15 @@ def get_course(course_id, depth=0):
...
@@ -43,18 +43,15 @@ def get_course(course_id, depth=0):
"""
"""
Given a course id, return the corresponding course descriptor.
Given a course id, return the corresponding course descriptor.
If
course_id is not valid
, raises a ValueError. This is appropriate
If
the course does not exist
, raises a ValueError. This is appropriate
for internal use.
for internal use.
depth: The number of levels of children for the modulestore to cache.
depth: The number of levels of children for the modulestore to cache.
None means infinite depth. Default is to fetch no children.
None means infinite depth. Default is to fetch no children.
"""
"""
try
:
course
=
modulestore
()
.
get_course
(
course_id
,
depth
=
depth
)
return
modulestore
()
.
get_course
(
course_id
,
depth
=
depth
)
if
course
is
None
:
except
(
KeyError
,
ItemNotFoundError
):
raise
ValueError
(
u"Course not found: {0}"
.
format
(
course_id
))
raise
ValueError
(
u"Course not found: {0}"
.
format
(
course_id
))
except
InvalidLocationError
:
raise
ValueError
(
u"Invalid location: {0}"
.
format
(
course_id
))
return
course
return
course
...
@@ -63,20 +60,15 @@ def get_course_by_id(course_key, depth=0):
...
@@ -63,20 +60,15 @@ def get_course_by_id(course_key, depth=0):
"""
"""
Given a course id, return the corresponding course descriptor.
Given a course id, return the corresponding course descriptor.
If
course_id is not valid
, raises a 404.
If
such a course does not exist
, raises a 404.
depth: The number of levels of children for the modulestore to cache. None means infinite depth
depth: The number of levels of children for the modulestore to cache. None means infinite depth
"""
"""
try
:
course
=
modulestore
()
.
get_course
(
course_key
,
depth
=
depth
)
course
=
modulestore
()
.
get_course
(
course_key
,
depth
=
depth
)
if
course
:
if
course
:
return
course
return
course
else
:
else
:
raise
Http404
(
"Course not found."
)
except
(
KeyError
,
ItemNotFoundError
):
raise
Http404
(
"Course not found."
)
raise
Http404
(
"Course not found."
)
except
InvalidLocationError
:
raise
Http404
(
"Invalid location"
)
def
get_course_with_access
(
user
,
action
,
course_key
,
depth
=
0
):
def
get_course_with_access
(
user
,
action
,
course_key
,
depth
=
0
):
...
...
lms/djangoapps/courseware/tests/test_courses.py
View file @
ae99a170
...
@@ -14,7 +14,7 @@ from xmodule.tests.xml import XModuleXmlImportTest
...
@@ -14,7 +14,7 @@ from xmodule.tests.xml import XModuleXmlImportTest
from
courseware.courses
import
(
from
courseware.courses
import
(
get_course_by_id
,
get_cms_course_link
,
course_image_url
,
get_course_by_id
,
get_cms_course_link
,
course_image_url
,
get_course_info_section
,
get_course_about_section
,
get_c
ourse
get_course_info_section
,
get_course_about_section
,
get_c
ms_block_link
)
)
from
courseware.tests.helpers
import
get_request_for_user
from
courseware.tests.helpers
import
get_request_for_user
from
courseware.tests.tests
import
TEST_DATA_MONGO_MODULESTORE
,
TEST_DATA_MIXED_MODULESTORE
from
courseware.tests.tests
import
TEST_DATA_MONGO_MODULESTORE
,
TEST_DATA_MIXED_MODULESTORE
...
@@ -27,32 +27,6 @@ CMS_BASE_TEST = 'testcms'
...
@@ -27,32 +27,6 @@ CMS_BASE_TEST = 'testcms'
class
CoursesTest
(
ModuleStoreTestCase
):
class
CoursesTest
(
ModuleStoreTestCase
):
"""Test methods related to fetching courses."""
"""Test methods related to fetching courses."""
def
test_get_course_by_id_invalid_chars
(
self
):
"""
Test that `get_course` throws a 404, rather than an exception,
when faced with unexpected characters (such as unicode characters,
and symbols such as = and ' ')
"""
with
self
.
assertRaises
(
Http404
):
get_course_by_id
(
SlashSeparatedCourseKey
(
'MITx'
,
'foobar'
,
'business and management'
))
with
self
.
assertRaises
(
Http404
):
get_course_by_id
(
SlashSeparatedCourseKey
(
'MITx'
,
'foobar'
'statistics=introduction'
))
with
self
.
assertRaises
(
Http404
):
get_course_by_id
(
SlashSeparatedCourseKey
(
'MITx'
,
'foobar'
,
'NiñøJoséMaríáßç'
))
def
test_get_course_invalid_chars
(
self
):
"""
Test that `get_course` throws a ValueError, rather than a 404,
when faced with unexpected characters (such as unicode characters,
and symbols such as = and ' ')
"""
with
self
.
assertRaises
(
ValueError
):
get_course
(
SlashSeparatedCourseKey
(
'MITx'
,
'foobar'
,
'business and management'
))
with
self
.
assertRaises
(
ValueError
):
get_course
(
SlashSeparatedCourseKey
(
'MITx'
,
'foobar'
,
'statistics=introduction'
))
with
self
.
assertRaises
(
ValueError
):
get_course
(
SlashSeparatedCourseKey
(
'MITx'
,
'foobar'
,
'NiñøJoséMaríáßç'
))
@override_settings
(
@override_settings
(
MODULESTORE
=
TEST_DATA_MONGO_MODULESTORE
,
CMS_BASE
=
CMS_BASE_TEST
MODULESTORE
=
TEST_DATA_MONGO_MODULESTORE
,
CMS_BASE
=
CMS_BASE_TEST
)
)
...
@@ -60,14 +34,13 @@ class CoursesTest(ModuleStoreTestCase):
...
@@ -60,14 +34,13 @@ class CoursesTest(ModuleStoreTestCase):
"""
"""
Tests that get_cms_course_link_by_id and get_cms_block_link_by_id return the right thing
Tests that get_cms_course_link_by_id and get_cms_block_link_by_id return the right thing
"""
"""
cms_url
=
u"//{}/course/org.num.name/branch/draft/block/name"
.
format
(
CMS_BASE_TEST
)
self
.
course
=
CourseFactory
.
create
(
self
.
course
=
CourseFactory
.
create
(
org
=
'org'
,
number
=
'num'
,
display_name
=
'name'
org
=
'org'
,
number
=
'num'
,
display_name
=
'name'
)
)
cms_url
=
u"//{}/course/slashes:org+num+name"
.
format
(
CMS_BASE_TEST
)
cms_url
=
u"//{}/course/slashes:org+num+name"
.
format
(
CMS_BASE_TEST
)
self
.
assertEqual
(
cms_url
,
get_cms_course_link
(
self
.
course
))
self
.
assertEqual
(
cms_url
,
get_cms_course_link
(
self
.
course
))
cms_url
=
u"//{}/course/location:org+num+name+course+name"
.
format
(
CMS_BASE_TEST
)
self
.
assertEqual
(
cms_url
,
get_cms_block_link
(
self
.
course
,
'course'
))
self
.
assertEqual
(
cms_url
,
get_cms_block_link
(
self
.
course
,
'course'
))
@mock.patch
(
@mock.patch
(
...
...
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