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
d6dab577
Commit
d6dab577
authored
Aug 11, 2015
by
Waheed Ahmed
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9202 from edx/waheed/plat776-fix-course-id-regex
Fixed course_id pattern regex.
parents
1ba82819
5e2c2b1e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
10 deletions
+34
-10
common/djangoapps/track/tests/test_contexts.py
+33
-9
lms/envs/common.py
+1
-1
No files found.
common/djangoapps/track/tests/test_contexts.py
View file @
d6dab577
# pylint: disable=missing-docstring
import
ddt
from
unittest
import
TestCase
from
track
import
contexts
@ddt.ddt
class
TestContexts
(
TestCase
):
COURSE_ID
=
'test/course_name/course_run'
SPLIT_COURSE_ID
=
'course-v1:test+course_name+course_run'
ORG_ID
=
'test'
def
test_course_id_from_url
(
self
):
self
.
assert_parses_course_id_from_url
(
'http://foo.bar.com/courses/{course_id}/more/stuff'
)
@ddt.data
(
(
COURSE_ID
,
''
),
(
COURSE_ID
,
'/more/stuff'
),
(
COURSE_ID
,
'?format=json'
),
(
SPLIT_COURSE_ID
,
''
),
(
SPLIT_COURSE_ID
,
'/more/stuff'
),
(
SPLIT_COURSE_ID
,
'?format=json'
)
)
@ddt.unpack
def
test_course_id_from_url
(
self
,
course_id
,
postfix
):
url
=
'http://foo.bar.com/courses/{}{}'
.
format
(
course_id
,
postfix
)
self
.
assert_parses_course_id_from_url
(
url
,
course_id
)
def
assert_parses_course_id_from_url
(
self
,
format_string
):
def
assert_parses_course_id_from_url
(
self
,
format_string
,
course_id
):
self
.
assertEquals
(
contexts
.
course_context_from_url
(
format_string
.
format
(
course_id
=
self
.
COURSE_ID
)),
contexts
.
course_context_from_url
(
format_string
.
format
(
course_id
=
course_id
)),
{
'course_id'
:
self
.
COURSE_ID
,
'course_id'
:
course_id
,
'org_id'
:
self
.
ORG_ID
}
)
...
...
@@ -34,11 +47,22 @@ class TestContexts(TestCase):
}
)
def
test_malformed_course_id
(
self
):
self
.
assert_empty_context_for_url
(
'http://foo.bar.com/courses/test'
)
@ddt.data
(
''
,
'/'
,
'/?'
,
'?format=json'
)
def
test_malformed_course_id
(
self
,
postfix
):
self
.
assert_empty_context_for_url
(
'http://foo.bar.com/courses/test/course_name{}'
.
format
(
postfix
))
def
test_course_id_later_in_url
(
self
):
self
.
assert_parses_course_id_from_url
(
'http://foo.bar.com/x/y/z/courses/{course_id}'
)
@ddt.data
(
(
COURSE_ID
,
''
),
(
COURSE_ID
,
'/more/stuff'
),
(
COURSE_ID
,
'?format=json'
),
(
SPLIT_COURSE_ID
,
''
),
(
SPLIT_COURSE_ID
,
'/more/stuff'
),
(
SPLIT_COURSE_ID
,
'?format=json'
)
)
@ddt.unpack
def
test_course_id_later_in_url
(
self
,
course_id
,
postfix
):
url
=
'http://foo.bar.com/x/y/z/courses/{}{}'
.
format
(
course_id
,
postfix
)
self
.
assert_parses_course_id_from_url
(
url
,
course_id
)
def
test_no_url
(
self
):
self
.
assert_empty_context_for_url
(
None
)
lms/envs/common.py
View file @
d6dab577
...
...
@@ -593,7 +593,7 @@ LMS_MIGRATION_ALLOWED_IPS = []
# Note: these intentionally greedily grab all chars up to the next slash including any pluses
# DHM: I really wanted to ensure the separators were the same (+ or /) but all patts I tried had
# too many inadvertent side effects :-(
COURSE_KEY_PATTERN
=
r'(?P<course_key_string>[^/+]+(/|\+)[^/+]+(/|\+)[^/]+)'
COURSE_KEY_PATTERN
=
r'(?P<course_key_string>[^/+]+(/|\+)[^/+]+(/|\+)[^/
?
]+)'
COURSE_ID_PATTERN
=
COURSE_KEY_PATTERN
.
replace
(
'course_key_string'
,
'course_id'
)
COURSE_KEY_REGEX
=
COURSE_KEY_PATTERN
.
replace
(
'P<course_key_string>'
,
':'
)
...
...
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