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
a5574792
Commit
a5574792
authored
Feb 08, 2016
by
Nimisha Asthagiri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix mobile Warning errors in tracking logs.
parent
b858644c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
19 deletions
+18
-19
common/djangoapps/track/views/segmentio.py
+15
-16
common/djangoapps/track/views/tests/test_segmentio.py
+3
-3
No files found.
common/djangoapps/track/views/segmentio.py
View file @
a5574792
...
...
@@ -19,8 +19,6 @@ log = logging.getLogger(__name__)
ERROR_UNAUTHORIZED
=
'Unauthorized'
WARNING_IGNORED_SOURCE
=
'Source ignored'
WARNING_IGNORED_TYPE
=
'Type ignored'
ERROR_MISSING_USER_ID
=
'Required user_id missing from context'
ERROR_USER_NOT_EXIST
=
'Specified user does not exist'
ERROR_INVALID_USER_ID
=
'Unable to parse userId as an integer'
...
...
@@ -67,7 +65,7 @@ def segmentio_event(request):
try
:
track_segmentio_event
(
request
)
except
EventValidationError
as
err
:
log
.
warnin
g
(
log
.
debu
g
(
'Unable to process event received from Segment: message="
%
s" event="
%
s"'
,
str
(
err
),
request
.
body
...
...
@@ -133,29 +131,30 @@ def track_segmentio_event(request): # pylint: disable=too-many-statements
source_map
=
getattr
(
settings
,
'TRACKING_SEGMENTIO_SOURCE_MAP'
,
{})
event_source
=
source_map
.
get
(
library_name
)
if
not
event_source
:
r
aise
EventValidationError
(
WARNING_IGNORED_SOURCE
)
r
eturn
else
:
context
[
'event_source'
]
=
event_source
# Ignore event types that are unsupported
segment_event_type
=
full_segment_event
.
get
(
'type'
)
allowed_types
=
[
a
.
lower
()
for
a
in
getattr
(
settings
,
'TRACKING_SEGMENTIO_ALLOWED_TYPES'
,
[])]
if
not
segment_event_type
or
(
segment_event_type
.
lower
()
not
in
allowed_types
):
return
if
'name'
not
in
segment_properties
:
raise
EventValidationError
(
ERROR_MISSING_NAME
)
if
'data'
not
in
segment_properties
:
raise
EventValidationError
(
ERROR_MISSING_DATA
)
# Ignore event types and names that are unsupported
segment_event_type
=
full_segment_event
.
get
(
'type'
)
# Ignore event names that are unsupported
segment_event_name
=
segment_properties
[
'name'
]
allowed_types
=
[
a
.
lower
()
for
a
in
getattr
(
settings
,
'TRACKING_SEGMENTIO_ALLOWED_TYPES'
,
[])]
disallowed_substring_names
=
[
a
.
lower
()
for
a
in
getattr
(
settings
,
'TRACKING_SEGMENTIO_DISALLOWED_SUBSTRING_NAMES'
,
[])
]
if
(
not
segment_event_type
or
(
segment_event_type
.
lower
()
not
in
allowed_types
)
or
any
(
disallowed_subs_name
in
segment_event_name
.
lower
()
for
disallowed_subs_name
in
disallowed_substring_names
)
)
:
raise
EventValidationError
(
WARNING_IGNORED_TYPE
)
if
any
(
disallowed_subs_name
in
segment_event_name
.
lower
()
for
disallowed_subs_name
in
disallowed_substring_names
):
return
if
'data'
not
in
segment_properties
:
raise
EventValidationError
(
ERROR_MISSING_DATA
)
# create and populate application field if it doesn't exist
app_context
=
segment_properties
.
get
(
'context'
,
{})
...
...
common/djangoapps/track/views/tests/test_segmentio.py
View file @
a5574792
...
...
@@ -96,14 +96,14 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase):
return
request
@data
(
'identify'
,
'Group'
,
'Alias'
,
'Page'
,
'identify'
,
'screen'
)
@expect_failure_with_message
(
segmentio
.
WARNING_IGNORED_TYPE
)
def
test_segmentio_ignore_actions
(
self
,
action
):
self
.
post_segmentio_event
(
action
=
action
)
self
.
assert_no_events_emitted
()
@data
(
'edx.bi.some_name'
,
'EDX.BI.CAPITAL_NAME'
)
@expect_failure_with_message
(
segmentio
.
WARNING_IGNORED_TYPE
)
def
test_segmentio_ignore_names
(
self
,
name
):
self
.
post_segmentio_event
(
name
=
name
)
self
.
assert_no_events_emitted
()
def
post_segmentio_event
(
self
,
**
kwargs
):
"""Post a fake Segment event to the view that processes it"""
...
...
@@ -161,9 +161,9 @@ class SegmentIOTrackingTestCase(EventTrackingTestCase):
"""Return a json string containing a fake Segment event"""
return
json
.
dumps
(
self
.
create_segmentio_event
(
**
kwargs
))
@expect_failure_with_message
(
segmentio
.
WARNING_IGNORED_SOURCE
)
def
test_segmentio_ignore_unknown_libraries
(
self
):
self
.
post_segmentio_event
(
library_name
=
'foo'
)
self
.
assert_no_events_emitted
()
@expect_failure_with_message
(
segmentio
.
ERROR_USER_NOT_EXIST
)
def
test_no_user_for_user_id
(
self
):
...
...
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