From e10389fd720d7c6861103b219bfecbd2ffd7cbab Mon Sep 17 00:00:00 2001 From: Thomas Zurkan Date: Mon, 20 Nov 2017 14:32:19 -0800 Subject: [PATCH] cleanup comments from mike and matt. prepare for merge --- optimizely/helpers/enums.py | 11 ++++++++++- optimizely/notification_center.py | 2 +- tests/test_optimizely.py | 18 +++++++++--------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/optimizely/helpers/enums.py b/optimizely/helpers/enums.py index e99b0731..52b16cff 100644 --- a/optimizely/helpers/enums.py +++ b/optimizely/helpers/enums.py @@ -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" diff --git a/optimizely/notification_center.py b/optimizely/notification_center.py index a81d11d3..c305e7d2 100644 --- a/optimizely/notification_center.py +++ b/optimizely/notification_center.py @@ -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] = [] diff --git a/tests/test_optimizely.py b/tests/test_optimizely.py index 4847ecdb..0d5f8b37 100644 --- a/tests/test_optimizely.py +++ b/tests/test_optimizely.py @@ -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, @@ -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): @@ -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( @@ -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): @@ -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) @@ -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()) @@ -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) @@ -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):