@@ -23,43 +23,43 @@ def _validate_event_object(self, event_obj, expected_url, expected_params, expec
23
23
def test_init__invalid_datafile__logs_error (self ):
24
24
""" Test that invalid datafile logs error on init. """
25
25
26
- with mock .patch ('logging.error ' ) as mock_log_error :
26
+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
27
27
optimizely .Optimizely ('invalid_datafile' )
28
28
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.' )
30
30
31
31
def test_init__invalid_event_dispatcher__logs_error (self ):
32
32
""" Test that invalid event_dispatcher logs error on init. """
33
33
34
34
class InvalidDispatcher (object ):
35
35
pass
36
36
37
- with mock .patch ('logging.error ' ) as mock_log_error :
37
+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
38
38
optimizely .Optimizely (json .dumps (self .config_dict ), event_dispatcher = InvalidDispatcher )
39
39
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.' )
41
41
42
42
def test_init__invalid_logger__raises (self ):
43
43
""" Test that invalid logger logs error on init. """
44
44
45
45
class InvalidLogger (object ):
46
46
pass
47
47
48
- with mock .patch ('logging.error ' ) as mock_log_error :
48
+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
49
49
optimizely .Optimizely (json .dumps (self .config_dict ), logger = InvalidLogger )
50
50
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.' )
52
52
53
53
def test_init__invalid_error_handler__raises (self ):
54
54
""" Test that invalid error_handler logs error on init. """
55
55
56
56
class InvalidErrorHandler (object ):
57
57
pass
58
58
59
- with mock .patch ('logging.error ' ) as mock_log_error :
59
+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
60
60
optimizely .Optimizely (json .dumps (self .config_dict ), error_handler = InvalidErrorHandler )
61
61
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.' )
63
63
64
64
def test_skip_json_validation_true (self ):
65
65
""" 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):
73
73
""" Test that invalid JSON logs error if schema validation is turned off. """
74
74
75
75
# Not JSON
76
- with mock .patch ('logging.error ' ) as mock_log_error :
76
+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
77
77
optimizely .Optimizely ('invalid_json' , skip_json_validation = True )
78
78
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.' )
80
80
81
81
# 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 :
83
83
optimizely .Optimizely (json .dumps ({'some_field' : 'some_value' }), skip_json_validation = True )
84
84
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 )
86
86
87
87
# 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 :
89
89
optimizely .Optimizely ({'version' : '2' , 'events' : 'invalid_value' , 'experiments' : 'invalid_value' },
90
90
skip_json_validation = True )
91
91
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.' )
93
93
94
94
def test_activate (self ):
95
95
""" Test that activate calls dispatch_event with right params and returns expected variation. """
@@ -213,10 +213,10 @@ def test_activate__invalid_object(self):
213
213
214
214
opt_obj = optimizely .Optimizely ('invalid_file' )
215
215
216
- with mock .patch ('logging.error ' ) as mock_logging_error :
216
+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
217
217
self .assertIsNone (opt_obj .activate ('test_experiment' , 'test_user' ))
218
218
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".' )
220
220
221
221
def test_track__with_attributes (self ):
222
222
""" Test that track calls dispatch_event with right params when attributes are provided. """
@@ -337,10 +337,10 @@ def test_track__invalid_object(self):
337
337
338
338
opt_obj = optimizely .Optimizely ('invalid_file' )
339
339
340
- with mock .patch ('logging.error ' ) as mock_logging_error :
340
+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
341
341
opt_obj .track ('test_event' , 'test_user' )
342
342
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".' )
344
344
345
345
def test_get_variation__audience_match_and_experiment_running (self ):
346
346
""" Test that get variation retrieves expected variation
@@ -409,10 +409,10 @@ def test_get_variation__invalid_object(self):
409
409
410
410
opt_obj = optimizely .Optimizely ('invalid_file' )
411
411
412
- with mock .patch ('logging.error ' ) as mock_logging_error :
412
+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
413
413
self .assertIsNone (opt_obj .get_variation ('test_experiment' , 'test_user' ))
414
414
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".' )
416
416
417
417
def test_custom_logger (self ):
418
418
""" Test creating Optimizely object with a custom logger. """
@@ -450,10 +450,10 @@ def _validate_event_object(self, event_obj, expected_url, expected_params, expec
450
450
def test_init__invalid_datafile__raises (self ):
451
451
""" Test that invalid datafile raises Exception on init. """
452
452
453
- with mock .patch ('logging.error ' ) as mock_log_error :
453
+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
454
454
optimizely .Optimizely ('invalid_datafile' )
455
455
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.' )
457
457
458
458
def test_activate (self ):
459
459
""" Test that activate calls dispatch_event with right params and returns expected variation. """
@@ -598,10 +598,10 @@ def test_activate__invalid_object(self):
598
598
599
599
opt_obj = optimizely .Optimizely ('invalid_file' )
600
600
601
- with mock .patch ('logging.error ' ) as mock_logging_error :
601
+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
602
602
self .assertIsNone (opt_obj .activate ('test_experiment' , 'test_user' ))
603
603
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".' )
605
605
606
606
def test_track__with_attributes (self ):
607
607
""" Test that track calls dispatch_event with right params when attributes are provided. """
@@ -755,20 +755,20 @@ def test_track__invalid_object(self):
755
755
756
756
opt_obj = optimizely .Optimizely ('invalid_file' )
757
757
758
- with mock .patch ('logging.error ' ) as mock_logging_error :
758
+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
759
759
opt_obj .track ('test_event' , 'test_user' )
760
760
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".' )
762
762
763
763
def test_get_variation__invalid_object (self ):
764
764
""" Test that get_variation logs error if Optimizely object is not created correctly. """
765
765
766
766
opt_obj = optimizely .Optimizely ('invalid_file' )
767
767
768
- with mock .patch ('logging.error ' ) as mock_logging_error :
768
+ with mock .patch ('optimizely.logger.SimpleLogger.log ' ) as mock_logging :
769
769
self .assertIsNone (opt_obj .get_variation ('test_experiment' , 'test_user' ))
770
770
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".' )
772
772
773
773
774
774
class OptimizelyWithExceptionTest (base .BaseTestV1 ):
0 commit comments