@@ -23,43 +23,43 @@ def _validate_event_object(self, event_obj, expected_url, expected_params, expec
2323 def test_init__invalid_datafile__logs_error (self ):
2424 """ Test that invalid datafile logs error on init. """
2525
26- with mock .patch ('logging.error ' ) as mock_log_error :
26+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
2727 optimizely .Optimizely ('invalid_datafile' )
2828
29- mock_log_error .assert_called_once_with ('Provided "datafile" is in an invalid format.' )
29+ mock_logging .assert_called_once_with (enums . LogLevels . ERROR , 'Provided "datafile" is in an invalid format.' )
3030
3131 def test_init__invalid_event_dispatcher__logs_error (self ):
3232 """ Test that invalid event_dispatcher logs error on init. """
3333
3434 class InvalidDispatcher (object ):
3535 pass
3636
37- with mock .patch ('logging.error ' ) as mock_log_error :
37+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
3838 optimizely .Optimizely (json .dumps (self .config_dict ), event_dispatcher = InvalidDispatcher )
3939
40- mock_log_error .assert_called_once_with ('Provided "event_dispatcher" is in an invalid format.' )
40+ mock_logging .assert_called_once_with (enums . LogLevels . ERROR , 'Provided "event_dispatcher" is in an invalid format.' )
4141
4242 def test_init__invalid_logger__raises (self ):
4343 """ Test that invalid logger logs error on init. """
4444
4545 class InvalidLogger (object ):
4646 pass
4747
48- with mock .patch ('logging.error ' ) as mock_log_error :
48+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
4949 optimizely .Optimizely (json .dumps (self .config_dict ), logger = InvalidLogger )
5050
51- mock_log_error .assert_called_once_with ('Provided "logger" is in an invalid format.' )
51+ mock_logging .assert_called_once_with (enums . LogLevels . ERROR , 'Provided "logger" is in an invalid format.' )
5252
5353 def test_init__invalid_error_handler__raises (self ):
5454 """ Test that invalid error_handler logs error on init. """
5555
5656 class InvalidErrorHandler (object ):
5757 pass
5858
59- with mock .patch ('logging.error ' ) as mock_log_error :
59+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
6060 optimizely .Optimizely (json .dumps (self .config_dict ), error_handler = InvalidErrorHandler )
6161
62- mock_log_error .assert_called_once_with ('Provided "error_handler" is in an invalid format.' )
62+ mock_logging .assert_called_once_with (enums . LogLevels . ERROR , 'Provided "error_handler" is in an invalid format.' )
6363
6464 def test_skip_json_validation_true (self ):
6565 """ Test that on setting skip_json_validation to true, JSON schema validation is not performed. """
@@ -73,23 +73,23 @@ def test_invalid_json_raises_schema_validation_off(self):
7373 """ Test that invalid JSON logs error if schema validation is turned off. """
7474
7575 # Not JSON
76- with mock .patch ('logging.error ' ) as mock_log_error :
76+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
7777 optimizely .Optimizely ('invalid_json' , skip_json_validation = True )
7878
79- mock_log_error .assert_called_once_with ('Provided "datafile" is in an invalid format.' )
79+ mock_logging .assert_called_once_with (enums . LogLevels . ERROR , 'Provided "datafile" is in an invalid format.' )
8080
8181 # JSON, but missing version
82- with mock .patch ('logging.error ' ) as mock_log_error :
82+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
8383 optimizely .Optimizely (json .dumps ({'some_field' : 'some_value' }), skip_json_validation = True )
8484
85- mock_log_error .assert_called_once_with (enums .Errors .UNSUPPORTED_DATAFILE_VERSION )
85+ mock_logging .assert_called_once_with (enums . LogLevels . ERROR , enums .Errors .UNSUPPORTED_DATAFILE_VERSION )
8686
8787 # JSON having valid version, but entities have invalid format
88- with mock .patch ('logging.error ' ) as mock_log_error :
88+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
8989 optimizely .Optimizely ({'version' : '2' , 'events' : 'invalid_value' , 'experiments' : 'invalid_value' },
9090 skip_json_validation = True )
9191
92- mock_log_error .assert_called_once_with ('Provided "datafile" is in an invalid format.' )
92+ mock_logging .assert_called_once_with (enums . LogLevels . ERROR , 'Provided "datafile" is in an invalid format.' )
9393
9494 def test_activate (self ):
9595 """ Test that activate calls dispatch_event with right params and returns expected variation. """
@@ -213,10 +213,10 @@ def test_activate__invalid_object(self):
213213
214214 opt_obj = optimizely .Optimizely ('invalid_file' )
215215
216- with mock .patch ('logging.error ' ) as mock_logging_error :
216+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
217217 self .assertIsNone (opt_obj .activate ('test_experiment' , 'test_user' ))
218218
219- mock_logging_error .assert_called_once_with ('Datafile has invalid format. Failing "activate".' )
219+ mock_logging .assert_called_once_with (enums . LogLevels . ERROR , 'Datafile has invalid format. Failing "activate".' )
220220
221221 def test_track__with_attributes (self ):
222222 """ Test that track calls dispatch_event with right params when attributes are provided. """
@@ -337,10 +337,10 @@ def test_track__invalid_object(self):
337337
338338 opt_obj = optimizely .Optimizely ('invalid_file' )
339339
340- with mock .patch ('logging.error ' ) as mock_logging_error :
340+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
341341 opt_obj .track ('test_event' , 'test_user' )
342342
343- mock_logging_error .assert_called_once_with ('Datafile has invalid format. Failing "track".' )
343+ mock_logging .assert_called_once_with (enums . LogLevels . ERROR , 'Datafile has invalid format. Failing "track".' )
344344
345345 def test_get_variation__audience_match_and_experiment_running (self ):
346346 """ Test that get variation retrieves expected variation
@@ -409,10 +409,10 @@ def test_get_variation__invalid_object(self):
409409
410410 opt_obj = optimizely .Optimizely ('invalid_file' )
411411
412- with mock .patch ('logging.error ' ) as mock_logging_error :
412+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
413413 self .assertIsNone (opt_obj .get_variation ('test_experiment' , 'test_user' ))
414414
415- mock_logging_error .assert_called_once_with ('Datafile has invalid format. Failing "get_variation".' )
415+ mock_logging .assert_called_once_with (enums . LogLevels . ERROR , 'Datafile has invalid format. Failing "get_variation".' )
416416
417417 def test_custom_logger (self ):
418418 """ Test creating Optimizely object with a custom logger. """
@@ -450,10 +450,10 @@ def _validate_event_object(self, event_obj, expected_url, expected_params, expec
450450 def test_init__invalid_datafile__raises (self ):
451451 """ Test that invalid datafile raises Exception on init. """
452452
453- with mock .patch ('logging.error ' ) as mock_log_error :
453+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
454454 optimizely .Optimizely ('invalid_datafile' )
455455
456- mock_log_error .assert_called_once_with ('Provided "datafile" is in an invalid format.' )
456+ mock_logging .assert_called_once_with (enums . LogLevels . ERROR , 'Provided "datafile" is in an invalid format.' )
457457
458458 def test_activate (self ):
459459 """ Test that activate calls dispatch_event with right params and returns expected variation. """
@@ -598,10 +598,10 @@ def test_activate__invalid_object(self):
598598
599599 opt_obj = optimizely .Optimizely ('invalid_file' )
600600
601- with mock .patch ('logging.error ' ) as mock_logging_error :
601+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
602602 self .assertIsNone (opt_obj .activate ('test_experiment' , 'test_user' ))
603603
604- mock_logging_error .assert_called_once_with ('Datafile has invalid format. Failing "activate".' )
604+ mock_logging .assert_called_once_with (enums . LogLevels . ERROR , 'Datafile has invalid format. Failing "activate".' )
605605
606606 def test_track__with_attributes (self ):
607607 """ Test that track calls dispatch_event with right params when attributes are provided. """
@@ -755,20 +755,20 @@ def test_track__invalid_object(self):
755755
756756 opt_obj = optimizely .Optimizely ('invalid_file' )
757757
758- with mock .patch ('logging.error ' ) as mock_logging_error :
758+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
759759 opt_obj .track ('test_event' , 'test_user' )
760760
761- mock_logging_error .assert_called_once_with ('Datafile has invalid format. Failing "track".' )
761+ mock_logging .assert_called_once_with (enums . LogLevels . ERROR , 'Datafile has invalid format. Failing "track".' )
762762
763763 def test_get_variation__invalid_object (self ):
764764 """ Test that get_variation logs error if Optimizely object is not created correctly. """
765765
766766 opt_obj = optimizely .Optimizely ('invalid_file' )
767767
768- with mock .patch ('logging.error ' ) as mock_logging_error :
768+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
769769 self .assertIsNone (opt_obj .get_variation ('test_experiment' , 'test_user' ))
770770
771- mock_logging_error .assert_called_once_with ('Datafile has invalid format. Failing "get_variation".' )
771+ mock_logging .assert_called_once_with (enums . LogLevels . ERROR , 'Datafile has invalid format. Failing "get_variation".' )
772772
773773
774774class OptimizelyWithExceptionTest (base .BaseTestV1 ):
0 commit comments