def test_flush_once_max_timeout(self): event_dispatcher = TestEventDispatcher() self.optimizely.logger = SimpleLogger(enums.LogLevels.DEBUG) with mock.patch.object(self.optimizely, 'logger') as mock_config_logging: self._set_event_processor(event_dispatcher, mock_config_logging) user_event = self._build_conversion_event(self.event_name) self.event_processor.process(user_event) event_dispatcher.expect_conversion(self.event_name, self.test_user_id) time.sleep(1.75) self.assertStrictTrue(event_dispatcher.compare_events()) self.assertEqual(0, self.event_processor.event_queue.qsize()) self.assertTrue(mock_config_logging.debug.called) mock_config_logging.debug.assert_any_call( 'Received event of type ConversionEvent for user test_user.') mock_config_logging.debug.assert_any_call('Flushing batch size 1') mock_config_logging.debug.assert_any_call( 'Flush interval deadline. Flushed batch.') self.assertTrue(mock_config_logging.debug.call_count == 3) self.optimizely.logger = SimpleLogger()
def setUp(self, *args, **kwargs): base.BaseTest.setUp(self, 'config_dict_with_multiple_experiments') self.test_user_id = 'test_user' self.event_name = 'test_event' self.event_queue = queue.Queue(maxsize=self.DEFAULT_QUEUE_CAPACITY) self.optimizely.logger = SimpleLogger() self.notification_center = self.optimizely.notification_center
def set_obj(self, url=None): if not url: url = 'https://cdn.optimizely.com/json/{0}.json'.format( self.project_id) datafile = self.retrieve_datafile(url) self.obj = optimizely.Optimizely(datafile, None, SimpleLogger())
def set_obj(self, url=None): if not url: url = 'https://cdn.optimizely.com/json/{0}.json'.format( self.project_id) datafile = self.retrieve_datafile(url) self.obj = optimizely.Optimizely( datafile, logger=SimpleLogger(), event_dispatcher=RedisDeferredDispatcher())
def set_instance(self): """Initializing the Optimizely instance.""" if self.sdk_key is None: self.datafile = open('datafile.json', 'r').read() else: url = 'https://cdn.optimizely.com/datafiles/{0}.json'.format( self.sdk_key) self.datafile = requests.get(url).text self.instance = optimizely.Optimizely(self.datafile, None, SimpleLogger()) return self.datafile
def setUp(self, *args, **kwargs): base.BaseTest.setUp(self, 'config_dict_with_multiple_experiments') self.test_user_id = 'test_user' self.event_name = 'test_event' self.optimizely.logger = SimpleLogger() self.notification_center = self.optimizely.notification_center self.event_dispatcher = TestForwardingEventDispatcher(is_updated=False) with mock.patch.object(self.optimizely, 'logger') as mock_config_logging: self.event_processor = ForwardingEventProcessor( self.event_dispatcher, mock_config_logging, self.notification_center )