Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
46b1c850
Commit
46b1c850
authored
10 years ago
by
Usman Khalid
Browse files
Options
Downloads
Patches
Plain Diff
Catch InvalidKeyError in UserTagsEventContextMiddleware.
LMS-11189
parent
adaf2eb5
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
common/djangoapps/user_api/middleware.py
+10
-3
10 additions, 3 deletions
common/djangoapps/user_api/middleware.py
common/djangoapps/user_api/tests/test_middleware.py
+7
-0
7 additions, 0 deletions
common/djangoapps/user_api/tests/test_middleware.py
with
17 additions
and
3 deletions
common/djangoapps/user_api/middleware.py
+
10
−
3
View file @
46b1c850
...
...
@@ -2,11 +2,14 @@
Middleware for user api.
Adds user
'
s tags to tracking event context.
"""
from
track.contexts
import
COURSE_REGEX
from
eventtracking
import
tracker
from
user_api.models
import
UserCourseTag
from
opaque_keys
import
InvalidKeyError
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
track.contexts
import
COURSE_REGEX
from
user_api.models
import
UserCourseTag
class
UserTagsEventContextMiddleware
(
object
):
"""
Middleware that adds a user
'
s tags to tracking event context.
"""
...
...
@@ -20,7 +23,11 @@ class UserTagsEventContextMiddleware(object):
course_id
=
None
if
match
:
course_id
=
match
.
group
(
'
course_id
'
)
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
course_id
)
try
:
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
course_id
)
except
InvalidKeyError
:
course_id
=
None
course_key
=
None
context
=
{}
...
...
This diff is collapsed.
Click to expand it.
common/djangoapps/user_api/tests/test_middleware.py
+
7
−
0
View file @
46b1c850
...
...
@@ -92,6 +92,13 @@ class TagsMiddlewareTest(TestCase):
self
.
assertContextSetTo
({})
def
test_invalid_course_id
(
self
):
self
.
request
=
self
.
request_factory
.
get
(
'
/courses/edX/101/
'
)
self
.
request
.
user
=
self
.
user
self
.
process_request
()
self
.
assertContextSetTo
({})
def
test_anonymous_user
(
self
):
self
.
request
.
user
=
AnonymousUserFactory
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment