Skip to content

Commit

Permalink
Move context back into properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
nasthagiri committed Dec 8, 2014
1 parent 3c99912 commit fd0c9d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
12 changes: 2 additions & 10 deletions common/djangoapps/track/views/segmentio.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,12 @@ def track_segmentio_event(request): # pylint: disable=too-many-statements
raise EventValidationError(WARNING_IGNORED_TYPE)

if segment_context:
# copy required fields from segment's context dict to our custom context dict
for context_field_name, segment_context_field_name in [
('course_id', 'course_id'),
('open_in_browser_url', 'open_in_browser_url'),
('agent', 'userAgent')
]:
if segment_context_field_name in segment_context:
context[context_field_name] = segment_context[segment_context_field_name]

# copy the entire segment's context dict as a sub-field of our custom context dict
context['client'] = dict(segment_context)
context['agent'] = segment_context.get('userAgent', '')

# remove duplicate and unnecessary fields from our copy
for field in ('traits', 'integrations', 'userAgent', 'course_id', 'open_in_browser_url'):
for field in ('traits', 'integrations', 'userAgent'):
if field in context['client']:
del context['client'][field]

Expand Down
21 changes: 10 additions & 11 deletions common/djangoapps/track/views/tests/test_segmentio.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def create_segmentio_event(self, **kwargs):
"properties": {
'name': kwargs.get('name', str(sentinel.name)),
'data': kwargs.get('data', {}),
'context': {
'course_id': kwargs.get('course_id') or '',
}
},
"channel": 'server',
"context": {
Expand All @@ -122,7 +125,6 @@ def create_segmentio_event(self, **kwargs):
"version": "unknown"
},
'userAgent': str(sentinel.user_agent),
'course_id': kwargs.get('course_id') or '',
},
"receivedAt": "2014-08-27T16:33:39.100Z",
"timestamp": "2014-08-27T16:33:39.215Z",
Expand All @@ -139,10 +141,7 @@ def create_segmentio_event(self, **kwargs):
}

if 'context' in kwargs:
sample_event['context'].update(kwargs['context'])

if 'open_in_browser_url' in kwargs:
sample_event['context']['open_in_browser_url'] = kwargs['open_in_browser_url']
sample_event['properties']['context'].update(kwargs['context'])

return sample_event

Expand Down Expand Up @@ -305,8 +304,8 @@ def test_video_event(self, name, event_type):
data=self.create_segmentio_event_json(
name=name,
data=input_payload,
open_in_browser_url='https://testserver/courses/foo/bar/baz/courseware/Week_1/Activity/2',
context={
'open_in_browser_url':'https://testserver/courses/foo/bar/baz/courseware/Week_1/Activity/2',
'course_id': course_id,
'application': {
'name': 'edx.mobileapp.android',
Expand Down Expand Up @@ -344,11 +343,11 @@ def test_video_event(self, name, event_type):
'name': 'test-app',
'version': 'unknown'
},
'application': {
'name': 'edx.mobileapp.android',
'version': '29',
'component': 'videoplayer'
}
},
'application': {
'name': 'edx.mobileapp.android',
'version': '29',
'component': 'videoplayer'
},
'received_at': datetime.strptime("2014-08-27T16:33:39.100Z", "%Y-%m-%dT%H:%M:%S.%fZ"),
},
Expand Down

0 comments on commit fd0c9d9

Please sign in to comment.