Merge pull request #11522 from edx/gabe/remove-ga-fields
copy event on write
This commit is contained in:
@@ -177,7 +177,10 @@ class GoogleAnalyticsProcessor(object):
|
||||
context = event.get('context', {})
|
||||
course_id = context.get('course_id')
|
||||
|
||||
copied_event = event.copy()
|
||||
if course_id is not None:
|
||||
event['label'] = course_id
|
||||
copied_event['label'] = course_id
|
||||
|
||||
event['nonInteraction'] = 1
|
||||
copied_event['nonInteraction'] = 1
|
||||
|
||||
return copied_event
|
||||
|
||||
@@ -149,3 +149,70 @@ class GoogleAnalyticsProcessorTestCase(EventTrackingTestCase):
|
||||
'timestamp': FROZEN_TIME,
|
||||
}
|
||||
assert_events_equal(expected_event, emitted_event)
|
||||
|
||||
|
||||
@override_settings(
|
||||
EVENT_TRACKING_BACKENDS={
|
||||
'0': {
|
||||
'ENGINE': 'eventtracking.backends.routing.RoutingBackend',
|
||||
'OPTIONS': {
|
||||
'backends': {
|
||||
'first': {'ENGINE': 'track.tests.InMemoryBackend'}
|
||||
},
|
||||
'processors': [
|
||||
{
|
||||
'ENGINE': 'track.shim.GoogleAnalyticsProcessor'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
'1': {
|
||||
'ENGINE': 'eventtracking.backends.routing.RoutingBackend',
|
||||
'OPTIONS': {
|
||||
'backends': {
|
||||
'second': {
|
||||
'ENGINE': 'track.tests.InMemoryBackend'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
class MultipleShimGoogleAnalyticsProcessorTestCase(EventTrackingTestCase):
|
||||
"""Ensure changes don't impact other backends"""
|
||||
|
||||
def test_multiple_backends(self):
|
||||
data = {
|
||||
sentinel.key: sentinel.value,
|
||||
}
|
||||
|
||||
context = {
|
||||
'path': sentinel.path,
|
||||
'user_id': sentinel.user_id,
|
||||
'course_id': sentinel.course_id,
|
||||
'org_id': sentinel.org_id,
|
||||
'client_id': sentinel.client_id,
|
||||
}
|
||||
with self.tracker.context('test', context):
|
||||
self.tracker.emit(sentinel.name, data)
|
||||
|
||||
segment_emitted_event = self.tracker.backends['0'].backends['first'].events[0]
|
||||
log_emitted_event = self.tracker.backends['1'].backends['second'].events[0]
|
||||
|
||||
expected_event = {
|
||||
'context': context,
|
||||
'data': data,
|
||||
'label': sentinel.course_id,
|
||||
'name': sentinel.name,
|
||||
'nonInteraction': 1,
|
||||
'timestamp': FROZEN_TIME,
|
||||
}
|
||||
assert_events_equal(expected_event, segment_emitted_event)
|
||||
|
||||
expected_event = {
|
||||
'context': context,
|
||||
'data': data,
|
||||
'name': sentinel.name,
|
||||
'timestamp': FROZEN_TIME,
|
||||
}
|
||||
assert_events_equal(expected_event, log_emitted_event)
|
||||
|
||||
Reference in New Issue
Block a user