Skip to content

Event builder: adds revision #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions optimizely/event_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ def _get_project_id(self):

return self.config.get_project_id()

def _get_revision(self):
""" Get revision.

Returns:
Revision of the datafile.
"""

return self.config.get_revision()

def _get_account_id(self):
""" Get account ID.

Expand Down Expand Up @@ -112,6 +121,7 @@ def _get_common_params(self, user_id, attributes):
commonParams[self.EventParams.SOURCE_SDK_TYPE] = 'python-sdk'
commonParams[self.EventParams.SOURCE_SDK_VERSION] = version.__version__
commonParams[self.EventParams.ANONYMIZE_IP] = self._get_anonymize_ip()
commonParams[self.EventParams.REVISION] = self._get_revision()

return commonParams

Expand Down Expand Up @@ -145,6 +155,7 @@ class EventParams(object):
SOURCE_SDK_VERSION = 'client_version'
CUSTOM = 'custom'
ANONYMIZE_IP = 'anonymize_ip'
REVISION = 'revision'

def _get_attributes(self, attributes):
""" Get attribute(s) information.
Expand Down
19 changes: 13 additions & 6 deletions tests/test_event_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def test_create_impression_event(self):
'client_name': 'python-sdk',
'client_version': version.__version__,
'anonymize_ip': False,
'revision': '42'
}

with mock.patch('time.time', return_value=42.123), \
Expand Down Expand Up @@ -125,7 +126,8 @@ def test_create_impression_event__with_attributes(self):
}],
'client_name': 'python-sdk',
'client_version': version.__version__,
'anonymize_ip': False
'anonymize_ip': False,
'revision': '42'
}

with mock.patch('time.time', return_value=42.123), \
Expand Down Expand Up @@ -166,7 +168,8 @@ def test_create_impression_event_when_attribute_is_not_in_datafile(self):
}],
'client_name': 'python-sdk',
'client_version': version.__version__,
'anonymize_ip': False
'anonymize_ip': False,
'revision': '42'
}

with mock.patch('time.time', return_value=42.123), \
Expand Down Expand Up @@ -207,7 +210,8 @@ def test_create_conversion_event(self):
}],
'client_name': 'python-sdk',
'client_version': version.__version__,
'anonymize_ip': False
'anonymize_ip': False,
'revision': '42'
}

with mock.patch('time.time', return_value=42.123), \
Expand Down Expand Up @@ -252,7 +256,8 @@ def test_create_conversion_event__with_attributes(self):
}],
'client_name': 'python-sdk',
'client_version': version.__version__,
'anonymize_ip': False
'anonymize_ip': False,
'revision': '42'
}

with mock.patch('time.time', return_value=42.123), \
Expand Down Expand Up @@ -304,7 +309,8 @@ def test_create_conversion_event__with_event_tags(self):
}],
'account_id': '12001',
'client_name': 'python-sdk',
'anonymize_ip': False
'anonymize_ip': False,
'revision': '42'
}

with mock.patch('time.time', return_value=42.123), \
Expand Down Expand Up @@ -358,7 +364,8 @@ def test_create_conversion_event__with_invalid_event_tags(self):
}],
'account_id': '12001',
'client_name': 'python-sdk',
'anonymize_ip': False
'anonymize_ip': False,
'revision': '42'
}

with mock.patch('time.time', return_value=42.123), \
Expand Down
31 changes: 21 additions & 10 deletions tests/test_optimizely.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ def test_activate(self):
}],
'client_version': version.__version__,
'client_name': 'python-sdk',
'anonymize_ip': False
'anonymize_ip': False,
'revision': '42'
}
mock_decision.assert_called_once_with(
self.project_config.get_experiment_from_key('test_experiment'), 'test_user', None
Expand Down Expand Up @@ -535,7 +536,8 @@ def test_activate__with_attributes__audience_match(self):
}],
'client_version': version.__version__,
'client_name': 'python-sdk',
'anonymize_ip': False
'anonymize_ip': False,
'revision': '42'
}
mock_get_variation.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'),
'test_user', {'test_attribute': 'test_value'})
Expand Down Expand Up @@ -582,7 +584,8 @@ def test_activate__with_attributes__audience_match__forced_bucketing(self):
}],
'client_version': version.__version__,
'client_name': 'python-sdk',
'anonymize_ip': False
'anonymize_ip': False,
'revision': '42'
}

self.assertEqual(1, mock_dispatch_event.call_count)
Expand Down Expand Up @@ -630,7 +633,8 @@ def test_activate__with_attributes__audience_match__bucketing_id_provided(self):
}],
'client_version': version.__version__,
'client_name': 'python-sdk',
'anonymize_ip': False
'anonymize_ip': False,
'revision': '42'
}
mock_get_variation.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'),
'test_user', {'test_attribute': 'test_value',
Expand Down Expand Up @@ -747,7 +751,8 @@ def test_track__with_attributes(self):
}],
'client_version': version.__version__,
'client_name': 'python-sdk',
'anonymize_ip': False
'anonymize_ip': False,
'revision': '42'
}
mock_get_variation.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'),
'test_user', {'test_attribute': 'test_value'})
Expand Down Expand Up @@ -796,7 +801,8 @@ def test_track__with_attributes__bucketing_id_provided(self):
}],
'client_version': version.__version__,
'client_name': 'python-sdk',
'anonymize_ip': False
'anonymize_ip': False,
'revision': '42'
}
mock_get_variation.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'),
'test_user', {'test_attribute': 'test_value',
Expand Down Expand Up @@ -876,7 +882,8 @@ def test_track__with_event_tags(self):
}],
'client_version': version.__version__,
'client_name': 'python-sdk',
'anonymize_ip': False
'anonymize_ip': False,
'revision': '42'
}
mock_get_variation.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'),
'test_user', {'test_attribute': 'test_value'})
Expand Down Expand Up @@ -930,7 +937,8 @@ def test_track__with_event_tags_revenue(self):
'project_id': '111001',
'client_version': version.__version__,
'account_id': '12001',
'anonymize_ip': False
'anonymize_ip': False,
'revision': '42'
}
mock_get_variation.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'),
'test_user', {'test_attribute': 'test_value'})
Expand Down Expand Up @@ -1014,7 +1022,8 @@ def test_track__with_event_tags__forced_bucketing(self):
}],
'client_version': version.__version__,
'client_name': 'python-sdk',
'anonymize_ip': False
'anonymize_ip': False,
'revision': '42'
}

self.assertEqual(1, mock_dispatch_event.call_count)
Expand Down Expand Up @@ -1066,7 +1075,8 @@ def test_track__with_invalid_event_tags(self):
'project_id': '111001',
'client_version': version.__version__,
'account_id': '12001',
'anonymize_ip': False
'anonymize_ip': False,
'revision': '42'
}
mock_get_variation.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'),
'test_user', {'test_attribute': 'test_value'})
Expand Down Expand Up @@ -1207,6 +1217,7 @@ def test_is_feature_enabled__returns_true_for_feature_experiment_if_property_fea
'client_version': version.__version__,
'client_name': 'python-sdk',
'anonymize_ip': False,
'revision': '1'
}
# Check that impression event is sent
self.assertEqual(1, mock_dispatch_event.call_count)
Expand Down