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
46b1c850
Commit
46b1c850
authored
Aug 04, 2014
by
Usman Khalid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Catch InvalidKeyError in UserTagsEventContextMiddleware.
LMS-11189
parent
adaf2eb5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
3 deletions
+17
-3
common/djangoapps/user_api/middleware.py
+10
-3
common/djangoapps/user_api/tests/test_middleware.py
+7
-0
No files found.
common/djangoapps/user_api/middleware.py
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
=
{}
...
...
common/djangoapps/user_api/tests/test_middleware.py
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
()
...
...
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