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
131c8cbf
Commit
131c8cbf
authored
Aug 07, 2014
by
Usman Khalid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Catch InvalidKeyError in course_id_from_url().
LMS-9663
parent
dcee518d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
4 deletions
+25
-4
common/djangoapps/util/request.py
+6
-1
common/djangoapps/util/tests/test_request.py
+19
-3
No files found.
common/djangoapps/util/request.py
View file @
131c8cbf
...
...
@@ -2,7 +2,9 @@
import
re
from
django.conf
import
settings
from
microsite_configuration
import
microsite
from
opaque_keys
import
InvalidKeyError
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
...
...
@@ -41,4 +43,7 @@ def course_id_from_url(url):
if
course_id
is
None
:
return
None
return
SlashSeparatedCourseKey
.
from_deprecated_string
(
course_id
)
try
:
return
SlashSeparatedCourseKey
.
from_deprecated_string
(
course_id
)
except
InvalidKeyError
:
return
None
common/djangoapps/util/tests/test_request.py
View file @
131c8cbf
from
django.test.client
import
RequestFactory
"""Tests for util.request module."""
import
unittest
from
django.conf
import
settings
from
util.request
import
safe_get_host
from
django.core.exceptions
import
SuspiciousOperation
import
unittest
from
django.test.client
import
RequestFactory
from
util.request
import
course_id_from_url
,
safe_get_host
class
ResponseTestCase
(
unittest
.
TestCase
):
...
...
@@ -37,3 +41,15 @@ class ResponseTestCase(unittest.TestCase):
settings
.
ALLOWED_HOSTS
=
[
"the_valid_website.com"
]
with
self
.
assertRaises
(
SuspiciousOperation
):
safe_get_host
(
request
)
def
test_course_id_from_url
(
self
):
""" Test course_id_from_url(). """
self
.
assertIsNone
(
course_id_from_url
(
'/login'
))
self
.
assertIsNone
(
course_id_from_url
(
'/course/edX/maths/2020'
))
self
.
assertIsNone
(
course_id_from_url
(
'/courses/edX/maths/'
))
course_id
=
course_id_from_url
(
'/courses/edX/maths/2020'
)
self
.
assertEqual
(
course_id
.
org
,
'edX'
)
self
.
assertEqual
(
course_id
.
course
,
'maths'
)
self
.
assertEqual
(
course_id
.
run
,
'2020'
)
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