Skip to content

Commit

Permalink
cleanup comments from mike and matt. prepare for merge
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaszurkan-optimizely committed Nov 20, 2017
1 parent 65a180c commit e10389f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
11 changes: 10 additions & 1 deletion optimizely/helpers/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,17 @@ class Errors(object):
class NotificationTypes(object):
""" NotificationTypes for the notification_center.NotificationCenter
format is NOTIFICATION TYPE: list of parameters to callback.
ACTIVATE notification listener has the following parameters:
Experiment experiment, str user_id, dict attributes (can be None), Variation variation, Event event
TRACK notification listener has the following parameters:
str event_key, str user_id, dict attributes (can be None), event_tags (can be None), Event event
FEATURE_ROLLOUT notification listener has the following parameters:
str feature_key,, str user_id, dict attributes, [Audiences] audiences
FEATURE_EXPERIMENT notification listener has the following parameters:
str feature_key, str user_id, dic attributes (can be None), Experiment experiment, Variation variation
"""
ACTIVATE = "ACTIVATE:experiment, user_id,attributes, variation, event"
ACTIVATE = "ACTIVATE:experiment, user_id, attributes, variation, event"
TRACK = "TRACK:event_key, user_id, attributes, event_tags, event"
FEATURE_ROLLOUT = "FEATURE_ROLLOUT:feature_key, user_id, attributes, audiences"
FEATURE_EXPERIMENT = "FEATURE_EXPERIMENT:feature_key, user_id, attributes, experiment, variation"
2 changes: 1 addition & 1 deletion optimizely/notification_center.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def remove_notification_listener(self, notification_id):

return False

def clean_all_notifications(self):
def clear_all_notifications(self):
""" Remove all notifications """
for key in self.notifications.keys():
self.notifications[key] = []
Expand Down
18 changes: 9 additions & 9 deletions tests/test_optimizely.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def on_activate(experiment, user_id, attributes, variation, event):
self.assertTrue(isinstance(attributes, dict))
self.assertTrue(isinstance(variation, entities.Variation))
self.assertTrue(isinstance(event, event_builder.Event))
print("Here for experiment {0}".format(experiment.key))
print("Activated experiment {0}".format(experiment.key))
callbackhit[0] = True

notification_id = self.optimizely.notification_center.add_notification_listener(enums.NotificationTypes.ACTIVATE,
Expand All @@ -219,7 +219,7 @@ def on_activate(experiment, user_id, attributes, variation, event):
self.assertEqual(True, callbackhit[0])
self.optimizely.notification_center.remove_notification_listener(notification_id)
self.assertEqual(0, len(self.optimizely.notification_center.notifications[enums.NotificationTypes.ACTIVATE]))
self.optimizely.notification_center.clean_all_notifications()
self.optimizely.notification_center.clear_all_notifications()
self.assertEqual(0, len(self.optimizely.notification_center.notifications[enums.NotificationTypes.ACTIVATE]))

def test_add_track_remove_clear_listener(self):
Expand All @@ -234,7 +234,7 @@ def on_track(event_key, user_id, attributes, event_tags, event):
if event_tags is not None:
self.assertTrue(isinstance(event_tags, dict))
self.assertTrue(isinstance(event, event_builder.Event))
print('event_key={0}'.format(event_key))
print('Track event with event_key={0}'.format(event_key))
callback_hit[0] = True

note_id = self.optimizely.notification_center.add_notification_listener(
Expand All @@ -251,7 +251,7 @@ def on_track(event_key, user_id, attributes, event_tags, event):
self.assertEqual(1, len(self.optimizely.notification_center.notifications[enums.NotificationTypes.TRACK]))
self.optimizely.notification_center.remove_notification_listener(note_id)
self.assertEqual(0, len(self.optimizely.notification_center.notifications[enums.NotificationTypes.TRACK]))
self.optimizely.notification_center.clean_all_notifications()
self.optimizely.notification_center.clear_all_notifications()
self.assertEqual(0, len(self.optimizely.notification_center.notifications[enums.NotificationTypes.TRACK]))

def test_add_same_listener(self):
Expand All @@ -275,7 +275,7 @@ def test_add_listener_custom_type(self):

def on_custom_event(test_string):
custom_called[0] = True
print('test_string={}', test_string)
print('Custom notification event tracked with parameter test_string={}', test_string)

notification_id = self.optimizely.notification_center.add_notification_listener(custom_type, on_custom_event)

Expand All @@ -300,7 +300,7 @@ def test_invalid_notification_send(self):

def on_custom_event(test_string):
custom_called[0] = True
print('test_string={}', test_string)
print('Custom notification event tracked with parameter test_string={}', test_string)

with mock.patch('optimizely.logger.SimpleLogger.log') as mock_logging:
notification_center = NotificationCenter(SimpleLogger())
Expand All @@ -318,10 +318,10 @@ def test_add_invalid_listener(self):
def test_add_multi_listener(self):
""" Test adding a 2 listeners """
def on_track(event_key, *args):
print("here we are")
print("on track 1 called")

def on_track2(event_key, *args):
print("here we are 2")
print("on track 2 called")

self.optimizely.notification_center.add_notification_listener(enums.NotificationTypes.TRACK, on_track)

Expand All @@ -330,7 +330,7 @@ def on_track2(event_key, *args):

self.assertEqual(2, len(self.optimizely.notification_center.notifications[enums.NotificationTypes.TRACK]))

self.optimizely.notification_center.clean_all_notifications()
self.optimizely.notification_center.clear_all_notifications()
self.assertEqual(0, len(self.optimizely.notification_center.notifications[enums.NotificationTypes.TRACK]))

def test_remove_listener(self):
Expand Down

0 comments on commit e10389f

Please sign in to comment.