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
e4b59c31
Commit
e4b59c31
authored
Feb 17, 2016
by
sanfordstudent
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11526 from edx/sstudent/MA-1882-update-api-regex
MA-1882 adding course api to regex
parents
d90c1a28
45f8e526
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
6 deletions
+21
-6
common/djangoapps/util/request.py
+2
-2
common/djangoapps/util/tests/test_request.py
+19
-4
No files found.
common/djangoapps/util/request.py
View file @
e4b59c31
...
...
@@ -7,8 +7,8 @@ from microsite_configuration import microsite
from
opaque_keys
import
InvalidKeyError
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
COURSE_REGEX
=
re
.
compile
(
r'^
.*?/courses/
{}'
.
format
(
settings
.
COURSE_ID_PATTERN
))
# accommodates course api urls, excluding any course api routes that do not fall under v*/courses, such as v1/blocks.
COURSE_REGEX
=
re
.
compile
(
r'^
(.*?/courses/)(?!v[0-9]+/[^/]+)
{}'
.
format
(
settings
.
COURSE_ID_PATTERN
))
def
safe_get_host
(
request
):
...
...
common/djangoapps/util/tests/test_request.py
View file @
e4b59c31
...
...
@@ -5,7 +5,6 @@ import unittest
from
django.conf
import
settings
from
django.core.exceptions
import
SuspiciousOperation
from
django.test.client
import
RequestFactory
from
util.request
import
course_id_from_url
,
safe_get_host
...
...
@@ -50,8 +49,24 @@ class ResponseTestCase(unittest.TestCase):
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/'
))
self
.
assertIsNone
(
course_id_from_url
(
'/api/courses/v1/blocks/edX/maths/2020'
))
self
.
assertIsNone
(
course_id_from_url
(
'/api/courses/v1/blocks/course-v1:incidental+courseid+formatting'
))
self
.
assertIsNone
(
course_id_from_url
(
'/api/courses/v41/notcourses/course-v1:incidental+courseid+formatting'
))
course_id
=
course_id_from_url
(
'/courses/course-v1:edX+maths+2020'
)
self
.
assertCourseIdFieldsMatch
(
course_id
=
course_id
,
org
=
"edX"
,
course
=
'maths'
,
run
=
'2020'
)
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'
)
self
.
assertCourseIdFieldsMatch
(
course_id
=
course_id
,
org
=
'edX'
,
course
=
'maths'
,
run
=
'2020'
)
course_id
=
course_id_from_url
(
'/api/courses/v1/courses/course-v1:edX+maths+2020'
)
self
.
assertCourseIdFieldsMatch
(
course_id
=
course_id
,
org
=
'edX'
,
course
=
'maths'
,
run
=
'2020'
)
course_id
=
course_id_from_url
(
'/api/courses/v1/courses/edX/maths/2020'
)
self
.
assertCourseIdFieldsMatch
(
course_id
=
course_id
,
org
=
'edX'
,
course
=
'maths'
,
run
=
'2020'
)
def
assertCourseIdFieldsMatch
(
self
,
course_id
,
org
,
course
,
run
):
""" Asserts that the passed-in course id matches the specified fields"""
self
.
assertEqual
(
course_id
.
org
,
org
)
self
.
assertEqual
(
course_id
.
course
,
course
)
self
.
assertEqual
(
course_id
.
run
,
run
)
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