Skip to content

Commit cd09d20

Browse files
rashidspmikeproeng37
authored andcommitted
Event builder: adds revision (#111)
1 parent a669f63 commit cd09d20

File tree

3 files changed

+45
-16
lines changed

3 files changed

+45
-16
lines changed

optimizely/event_builder.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ def _get_project_id(self):
4949

5050
return self.config.get_project_id()
5151

52+
def _get_revision(self):
53+
""" Get revision.
54+
55+
Returns:
56+
Revision of the datafile.
57+
"""
58+
59+
return self.config.get_revision()
60+
5261
def _get_account_id(self):
5362
""" Get account ID.
5463
@@ -112,6 +121,7 @@ def _get_common_params(self, user_id, attributes):
112121
commonParams[self.EventParams.SOURCE_SDK_TYPE] = 'python-sdk'
113122
commonParams[self.EventParams.SOURCE_SDK_VERSION] = version.__version__
114123
commonParams[self.EventParams.ANONYMIZE_IP] = self._get_anonymize_ip()
124+
commonParams[self.EventParams.REVISION] = self._get_revision()
115125

116126
return commonParams
117127

@@ -145,6 +155,7 @@ class EventParams(object):
145155
SOURCE_SDK_VERSION = 'client_version'
146156
CUSTOM = 'custom'
147157
ANONYMIZE_IP = 'anonymize_ip'
158+
REVISION = 'revision'
148159

149160
def _get_attributes(self, attributes):
150161
""" Get attribute(s) information.

tests/test_event_builder.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def test_create_impression_event(self):
8080
'client_name': 'python-sdk',
8181
'client_version': version.__version__,
8282
'anonymize_ip': False,
83+
'revision': '42'
8384
}
8485

8586
with mock.patch('time.time', return_value=42.123), \
@@ -125,7 +126,8 @@ def test_create_impression_event__with_attributes(self):
125126
}],
126127
'client_name': 'python-sdk',
127128
'client_version': version.__version__,
128-
'anonymize_ip': False
129+
'anonymize_ip': False,
130+
'revision': '42'
129131
}
130132

131133
with mock.patch('time.time', return_value=42.123), \
@@ -166,7 +168,8 @@ def test_create_impression_event_when_attribute_is_not_in_datafile(self):
166168
}],
167169
'client_name': 'python-sdk',
168170
'client_version': version.__version__,
169-
'anonymize_ip': False
171+
'anonymize_ip': False,
172+
'revision': '42'
170173
}
171174

172175
with mock.patch('time.time', return_value=42.123), \
@@ -207,7 +210,8 @@ def test_create_conversion_event(self):
207210
}],
208211
'client_name': 'python-sdk',
209212
'client_version': version.__version__,
210-
'anonymize_ip': False
213+
'anonymize_ip': False,
214+
'revision': '42'
211215
}
212216

213217
with mock.patch('time.time', return_value=42.123), \
@@ -252,7 +256,8 @@ def test_create_conversion_event__with_attributes(self):
252256
}],
253257
'client_name': 'python-sdk',
254258
'client_version': version.__version__,
255-
'anonymize_ip': False
259+
'anonymize_ip': False,
260+
'revision': '42'
256261
}
257262

258263
with mock.patch('time.time', return_value=42.123), \
@@ -304,7 +309,8 @@ def test_create_conversion_event__with_event_tags(self):
304309
}],
305310
'account_id': '12001',
306311
'client_name': 'python-sdk',
307-
'anonymize_ip': False
312+
'anonymize_ip': False,
313+
'revision': '42'
308314
}
309315

310316
with mock.patch('time.time', return_value=42.123), \
@@ -358,7 +364,8 @@ def test_create_conversion_event__with_invalid_event_tags(self):
358364
}],
359365
'account_id': '12001',
360366
'client_name': 'python-sdk',
361-
'anonymize_ip': False
367+
'anonymize_ip': False,
368+
'revision': '42'
362369
}
363370

364371
with mock.patch('time.time', return_value=42.123), \

tests/test_optimizely.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ def test_activate(self):
186186
}],
187187
'client_version': version.__version__,
188188
'client_name': 'python-sdk',
189-
'anonymize_ip': False
189+
'anonymize_ip': False,
190+
'revision': '42'
190191
}
191192
mock_decision.assert_called_once_with(
192193
self.project_config.get_experiment_from_key('test_experiment'), 'test_user', None
@@ -535,7 +536,8 @@ def test_activate__with_attributes__audience_match(self):
535536
}],
536537
'client_version': version.__version__,
537538
'client_name': 'python-sdk',
538-
'anonymize_ip': False
539+
'anonymize_ip': False,
540+
'revision': '42'
539541
}
540542
mock_get_variation.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'),
541543
'test_user', {'test_attribute': 'test_value'})
@@ -582,7 +584,8 @@ def test_activate__with_attributes__audience_match__forced_bucketing(self):
582584
}],
583585
'client_version': version.__version__,
584586
'client_name': 'python-sdk',
585-
'anonymize_ip': False
587+
'anonymize_ip': False,
588+
'revision': '42'
586589
}
587590

588591
self.assertEqual(1, mock_dispatch_event.call_count)
@@ -630,7 +633,8 @@ def test_activate__with_attributes__audience_match__bucketing_id_provided(self):
630633
}],
631634
'client_version': version.__version__,
632635
'client_name': 'python-sdk',
633-
'anonymize_ip': False
636+
'anonymize_ip': False,
637+
'revision': '42'
634638
}
635639
mock_get_variation.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'),
636640
'test_user', {'test_attribute': 'test_value',
@@ -747,7 +751,8 @@ def test_track__with_attributes(self):
747751
}],
748752
'client_version': version.__version__,
749753
'client_name': 'python-sdk',
750-
'anonymize_ip': False
754+
'anonymize_ip': False,
755+
'revision': '42'
751756
}
752757
mock_get_variation.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'),
753758
'test_user', {'test_attribute': 'test_value'})
@@ -796,7 +801,8 @@ def test_track__with_attributes__bucketing_id_provided(self):
796801
}],
797802
'client_version': version.__version__,
798803
'client_name': 'python-sdk',
799-
'anonymize_ip': False
804+
'anonymize_ip': False,
805+
'revision': '42'
800806
}
801807
mock_get_variation.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'),
802808
'test_user', {'test_attribute': 'test_value',
@@ -876,7 +882,8 @@ def test_track__with_event_tags(self):
876882
}],
877883
'client_version': version.__version__,
878884
'client_name': 'python-sdk',
879-
'anonymize_ip': False
885+
'anonymize_ip': False,
886+
'revision': '42'
880887
}
881888
mock_get_variation.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'),
882889
'test_user', {'test_attribute': 'test_value'})
@@ -930,7 +937,8 @@ def test_track__with_event_tags_revenue(self):
930937
'project_id': '111001',
931938
'client_version': version.__version__,
932939
'account_id': '12001',
933-
'anonymize_ip': False
940+
'anonymize_ip': False,
941+
'revision': '42'
934942
}
935943
mock_get_variation.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'),
936944
'test_user', {'test_attribute': 'test_value'})
@@ -1014,7 +1022,8 @@ def test_track__with_event_tags__forced_bucketing(self):
10141022
}],
10151023
'client_version': version.__version__,
10161024
'client_name': 'python-sdk',
1017-
'anonymize_ip': False
1025+
'anonymize_ip': False,
1026+
'revision': '42'
10181027
}
10191028

10201029
self.assertEqual(1, mock_dispatch_event.call_count)
@@ -1066,7 +1075,8 @@ def test_track__with_invalid_event_tags(self):
10661075
'project_id': '111001',
10671076
'client_version': version.__version__,
10681077
'account_id': '12001',
1069-
'anonymize_ip': False
1078+
'anonymize_ip': False,
1079+
'revision': '42'
10701080
}
10711081
mock_get_variation.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'),
10721082
'test_user', {'test_attribute': 'test_value'})
@@ -1207,6 +1217,7 @@ def test_is_feature_enabled__returns_true_for_feature_experiment_if_property_fea
12071217
'client_version': version.__version__,
12081218
'client_name': 'python-sdk',
12091219
'anonymize_ip': False,
1220+
'revision': '1'
12101221
}
12111222
# Check that impression event is sent
12121223
self.assertEqual(1, mock_dispatch_event.call_count)

0 commit comments

Comments
 (0)