18
18
from optimizely import exceptions
19
19
from optimizely import logger
20
20
from optimizely import optimizely
21
+ from optimizely import project_config
21
22
from optimizely import version
22
23
from optimizely .helpers import enums
23
24
from . import base
@@ -37,9 +38,10 @@ def test_init__invalid_datafile__logs_error(self):
37
38
""" Test that invalid datafile logs error on init. """
38
39
39
40
with mock .patch ('optimizely.logger.SimpleLogger.log' ) as mock_logging :
40
- optimizely .Optimizely ('invalid_datafile' )
41
+ opt_obj = optimizely .Optimizely ('invalid_datafile' )
41
42
42
43
mock_logging .assert_called_once_with (enums .LogLevels .ERROR , 'Provided "datafile" is in an invalid format.' )
44
+ self .assertFalse (opt_obj .is_valid )
43
45
44
46
def test_init__invalid_event_dispatcher__logs_error (self ):
45
47
""" Test that invalid event_dispatcher logs error on init. """
@@ -48,31 +50,47 @@ class InvalidDispatcher(object):
48
50
pass
49
51
50
52
with mock .patch ('optimizely.logger.SimpleLogger.log' ) as mock_logging :
51
- optimizely .Optimizely (json .dumps (self .config_dict ), event_dispatcher = InvalidDispatcher )
53
+ opt_obj = optimizely .Optimizely (json .dumps (self .config_dict ), event_dispatcher = InvalidDispatcher )
52
54
53
55
mock_logging .assert_called_once_with (enums .LogLevels .ERROR , 'Provided "event_dispatcher" is in an invalid format.' )
56
+ self .assertFalse (opt_obj .is_valid )
54
57
55
- def test_init__invalid_logger__raises (self ):
58
+ def test_init__invalid_logger__logs_error (self ):
56
59
""" Test that invalid logger logs error on init. """
57
60
58
61
class InvalidLogger (object ):
59
62
pass
60
63
61
64
with mock .patch ('optimizely.logger.SimpleLogger.log' ) as mock_logging :
62
- optimizely .Optimizely (json .dumps (self .config_dict ), logger = InvalidLogger )
65
+ opt_obj = optimizely .Optimizely (json .dumps (self .config_dict ), logger = InvalidLogger )
63
66
64
67
mock_logging .assert_called_once_with (enums .LogLevels .ERROR , 'Provided "logger" is in an invalid format.' )
68
+ self .assertFalse (opt_obj .is_valid )
65
69
66
- def test_init__invalid_error_handler__raises (self ):
70
+ def test_init__invalid_error_handler__logs_error (self ):
67
71
""" Test that invalid error_handler logs error on init. """
68
72
69
73
class InvalidErrorHandler (object ):
70
74
pass
71
75
72
76
with mock .patch ('optimizely.logger.SimpleLogger.log' ) as mock_logging :
73
- optimizely .Optimizely (json .dumps (self .config_dict ), error_handler = InvalidErrorHandler )
77
+ opt_obj = optimizely .Optimizely (json .dumps (self .config_dict ), error_handler = InvalidErrorHandler )
74
78
75
79
mock_logging .assert_called_once_with (enums .LogLevels .ERROR , 'Provided "error_handler" is in an invalid format.' )
80
+ self .assertFalse (opt_obj .is_valid )
81
+
82
+ def test_init__v1_datafile__logs_error (self ):
83
+ """ Test that v1 datafile logs error on init. """
84
+
85
+ self .config_dict ['version' ] = project_config .V1_CONFIG_VERSION
86
+ with mock .patch ('optimizely.logger.SimpleLogger.log' ) as mock_logging :
87
+ opt_obj = optimizely .Optimizely (json .dumps (self .config_dict ))
88
+
89
+ mock_logging .assert_called_once_with (
90
+ enums .LogLevels .ERROR ,
91
+ 'Provided datafile has unsupported version. Please use SDK version 1.1.0 or earlier for datafile version 1.'
92
+ )
93
+ self .assertFalse (opt_obj .is_valid )
76
94
77
95
def test_skip_json_validation_true (self ):
78
96
""" Test that on setting skip_json_validation to true, JSON schema validation is not performed. """
0 commit comments