From fd0c9d9a1b957bd3cd79bde2ea13bebd3cb2031e Mon Sep 17 00:00:00 2001 From: Nimisha Asthagiri Date: Wed, 3 Dec 2014 21:41:41 -0500 Subject: [PATCH] Move context back into properties. --- common/djangoapps/track/views/segmentio.py | 12 ++--------- .../track/views/tests/test_segmentio.py | 21 +++++++++---------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/common/djangoapps/track/views/segmentio.py b/common/djangoapps/track/views/segmentio.py index 59e1823af2d0..bdf897a9d59b 100644 --- a/common/djangoapps/track/views/segmentio.py +++ b/common/djangoapps/track/views/segmentio.py @@ -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] diff --git a/common/djangoapps/track/views/tests/test_segmentio.py b/common/djangoapps/track/views/tests/test_segmentio.py index 1a02dfb6f5e2..f3b7c204658b 100644 --- a/common/djangoapps/track/views/tests/test_segmentio.py +++ b/common/djangoapps/track/views/tests/test_segmentio.py @@ -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": { @@ -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", @@ -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 @@ -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', @@ -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"), },