Skip to content

Commit 071460a

Browse files
mjamal@folio3.commjamal@folio3.com
authored andcommitted
fix: addressed minor feedback.
1 parent d4f2c66 commit 071460a

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

optimizely/event/payload.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ class EventBatch(object):
1818
""" Class respresenting Event Batch. """
1919

2020
def __init__(self, account_id, project_id, revision, client_name, client_version,
21-
anonymize_ip, enrich_decisions, visitors=None):
21+
anonymize_ip, enrich_decisions=True, visitors=None):
2222
self.account_id = account_id
2323
self.project_id = project_id
2424
self.revision = revision
2525
self.client_name = client_name
2626
self.client_version = client_version
2727
self.anonymize_ip = anonymize_ip
2828
self.enrich_decisions = enrich_decisions
29-
self.visitors = visitors
29+
self.visitors = visitors or []
3030

3131
def __eq__(self, other):
3232
batch_obj = json.loads(json.dumps(self.__dict__, default=lambda o: o.__dict__),

optimizely/event/user_event.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
class UserEvent(object):
2323
""" Class respresenting User Event. """
2424

25-
def __init__(self, event_context):
25+
def __init__(self, event_context, user_id, visitor_attributes, bot_filtering=None):
2626
self.event_context = event_context
27+
self.user_id = user_id
28+
self.visitor_attributes = visitor_attributes
29+
self.bot_filtering = bot_filtering
2730
self.uuid = self._get_uuid()
2831
self.timestamp = self._get_time()
2932

@@ -38,26 +41,18 @@ class ImpressionEvent(UserEvent):
3841
""" Class representing Impression Event. """
3942

4043
def __init__(self, event_context, user_id, experiment, visitor_attributes, variation, bot_filtering=None):
41-
super(ImpressionEvent, self).__init__(event_context)
42-
self.event_context = event_context
43-
self.user_id = user_id
44+
super(ImpressionEvent, self).__init__(event_context, user_id, visitor_attributes, bot_filtering)
4445
self.experiment = experiment
45-
self.visitor_attributes = visitor_attributes
4646
self.variation = variation
47-
self.bot_filtering = bot_filtering
4847

4948

5049
class ConversionEvent(UserEvent):
5150
""" Class representing Conversion Event. """
5251

5352
def __init__(self, event_context, event, user_id, visitor_attributes, event_tags, bot_filtering=None):
54-
super(ConversionEvent, self).__init__(event_context)
55-
self.event_context = event_context
53+
super(ConversionEvent, self).__init__(event_context, user_id, visitor_attributes, bot_filtering)
5654
self.event = event
57-
self.user_id = user_id
58-
self.visitor_attributes = visitor_attributes
5955
self.event_tags = event_tags
60-
self.bot_filtering = bot_filtering
6156

6257

6358
class EventContext(object):

tests/test_event_payload.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# limitations under the License.
1313

1414
from optimizely import version
15-
from optimizely.event.payload import Decision, EventBatch, Snapshot, SnapshotEvent, Visitor, VisitorAttribute
15+
from optimizely.event import payload
1616
from . import base
1717

1818

@@ -51,15 +51,15 @@ def test_impression_event_equals_serialized_payload(self):
5151
'revision': '42'
5252
}
5353

54-
batch = EventBatch('12001', '111001', '42', 'python-sdk', version.__version__,
54+
batch = payload.EventBatch('12001', '111001', '42', 'python-sdk', version.__version__,
5555
False, True)
56-
visitor_attr = VisitorAttribute('111094', 'test_attribute', 'custom', 'test_value')
57-
event = SnapshotEvent('111182', 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c', 'campaign_activated',
56+
visitor_attr = payload.VisitorAttribute('111094', 'test_attribute', 'custom', 'test_value')
57+
event = payload.SnapshotEvent('111182', 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c', 'campaign_activated',
5858
42123)
59-
event_decision = Decision('111182', '111127', '111129')
59+
event_decision = payload.Decision('111182', '111127', '111129')
6060

61-
snapshots = Snapshot([event], [event_decision])
62-
user = Visitor([snapshots], [visitor_attr], 'test_user')
61+
snapshots = payload.Snapshot([event], [event_decision])
62+
user = payload.Visitor([snapshots], [visitor_attr], 'test_user')
6363

6464
batch.visitors = [user]
6565

@@ -105,15 +105,15 @@ def test_conversion_event_equals_serialized_payload(self):
105105
'revision': '42'
106106
}
107107

108-
batch = EventBatch('12001', '111001', '42', 'python-sdk', version.__version__,
108+
batch = payload.EventBatch('12001', '111001', '42', 'python-sdk', version.__version__,
109109
False, True)
110-
visitor_attr_1 = VisitorAttribute('111094', 'test_attribute', 'custom', 'test_value')
111-
visitor_attr_2 = VisitorAttribute('111095', 'test_attribute2', 'custom', 'test_value2')
112-
event = SnapshotEvent('111182', 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c', 'campaign_activated',
110+
visitor_attr_1 = payload.VisitorAttribute('111094', 'test_attribute', 'custom', 'test_value')
111+
visitor_attr_2 = payload.VisitorAttribute('111095', 'test_attribute2', 'custom', 'test_value2')
112+
event = payload.SnapshotEvent('111182', 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c', 'campaign_activated',
113113
42123, 4200, 1.234, {'revenue': 4200, 'value': 1.234, 'non-revenue': 'abc'})
114114

115-
snapshots = Snapshot([event])
116-
user = Visitor([snapshots], [visitor_attr_1, visitor_attr_2], 'test_user')
115+
snapshots = payload.Snapshot([event])
116+
user = payload.Visitor([snapshots], [visitor_attr_1, visitor_attr_2], 'test_user')
117117

118118
batch.visitors = [user]
119119

0 commit comments

Comments
 (0)