@@ -701,7 +701,7 @@ def test_activate__bucketer_returns_none(self):
701
701
def test_activate__invalid_object (self ):
702
702
""" Test that activate logs error if Optimizely object is not created correctly. """
703
703
704
- opt_obj = optimizely .Optimizely ('invalid_datafile ' )
704
+ opt_obj = optimizely .Optimizely ('invalid_file ' )
705
705
706
706
with mock .patch ('optimizely.logger.SimpleLogger.log' ) as mock_logging :
707
707
self .assertIsNone (opt_obj .activate ('test_experiment' , 'test_user' ))
@@ -1156,7 +1156,7 @@ def test_track__whitelisted_user_overrides_audience_check(self):
1156
1156
def test_track__invalid_object (self ):
1157
1157
""" Test that track logs error if Optimizely object is not created correctly. """
1158
1158
1159
- opt_obj = optimizely .Optimizely ('invalid_datafile ' )
1159
+ opt_obj = optimizely .Optimizely ('invalid_file ' )
1160
1160
1161
1161
with mock .patch ('optimizely.logger.SimpleLogger.log' ) as mock_logging :
1162
1162
opt_obj .track ('test_event' , 'test_user' )
@@ -1166,7 +1166,7 @@ def test_track__invalid_object(self):
1166
1166
def test_get_variation__invalid_object (self ):
1167
1167
""" Test that get_variation logs error if Optimizely object is not created correctly. """
1168
1168
1169
- opt_obj = optimizely .Optimizely ('invalid_datafile ' )
1169
+ opt_obj = optimizely .Optimizely ('invalid_file ' )
1170
1170
1171
1171
with mock .patch ('optimizely.logger.SimpleLogger.log' ) as mock_logging :
1172
1172
self .assertIsNone (opt_obj .get_variation ('test_experiment' , 'test_user' ))
@@ -1175,42 +1175,34 @@ def test_get_variation__invalid_object(self):
1175
1175
1176
1176
def test_is_feature_enabled__returns_false_for_invalid_feature (self ):
1177
1177
""" Test that the feature is not enabled for the user if the provided feature key is invalid. """
1178
+ optimizely_instance = optimizely .Optimizely (json .dumps (self .config_dict_with_features ))
1179
+ project_config = optimizely_instance .config
1178
1180
1179
- opt_obj = optimizely . Optimizely ( json . dumps ( self . config_dict_with_features ))
1180
-
1181
- with mock . patch ( 'optimizely.decision_service.DecisionService.get_variation_for_feature' ) as mock_decision :
1182
- self .assertFalse (opt_obj .is_feature_enabled ('invalid_feature' , 'user1' ))
1181
+ with mock . patch (
1182
+ 'optimizely.decision_service.DecisionService.get_variation_for_feature'
1183
+ ) as mock_decision :
1184
+ self .assertFalse (optimizely_instance .is_feature_enabled ('invalid_feature' , 'user1' ))
1183
1185
1184
1186
self .assertFalse (mock_decision .called )
1185
1187
1186
1188
def test_is_feature_enabled__returns_true_if_user_is_bucketed_into_a_variation (self ):
1187
1189
""" Test that the feature is not enabled for the user if the provided feature key is invalid. """
1188
-
1189
- opt_obj = optimizely .Optimizely (json .dumps (self .config_dict_with_features ))
1190
- project_config = opt_obj .config
1190
+ optimizely_instance = optimizely .Optimizely (json .dumps (self .config_dict_with_features ))
1191
+ project_config = optimizely_instance .config
1191
1192
feature = project_config .get_feature_from_key ('test_feature_1' )
1192
1193
1193
- with mock .patch ('optimizely.decision_service.DecisionService.get_variation_for_feature' ,
1194
- return_value = project_config .get_variation_from_id ('test_experiment' , '111129' )) as mock_decision :
1195
- self .assertTrue (opt_obj .is_feature_enabled ('test_feature_1' , 'user1' ))
1194
+ with mock .patch (
1195
+ 'optimizely.decision_service.DecisionService.get_variation_for_feature' ,
1196
+ return_value = project_config .get_variation_from_id ('test_experiment' , '111129' )
1197
+ ) as mock_decision :
1198
+ self .assertTrue (optimizely_instance .is_feature_enabled ('test_feature_1' , 'user1' ))
1196
1199
1197
1200
mock_decision .assert_called_once_with (feature , 'user1' , None )
1198
1201
1199
- def test_is_feature_enabled__invalid_object (self ):
1200
- """ Test that is_feature_enabled returns False if Optimizely object is not valid. """
1201
-
1202
- opt_obj = optimizely .Optimizely ('invalid_file' )
1203
-
1204
- with mock .patch ('optimizely.logger.SimpleLogger.log' ) as mock_logging :
1205
- self .assertFalse (opt_obj .is_feature_enabled ('test_feature_1' , 'user_1' ))
1206
-
1207
- mock_logging .assert_called_once_with (enums .LogLevels .ERROR ,
1208
- 'Datafile has invalid format. Failing "is_feature_enabled".' )
1209
-
1210
1202
def test_get_enabled_features (self ):
1211
1203
""" Test that get_enabled_features only returns features that are enabled for the specified user. """
1212
-
1213
- opt_obj = optimizely . Optimizely ( json . dumps ( self . config_dict_with_features ))
1204
+ optimizely_instance = optimizely . Optimizely ( json . dumps ( self . config_dict_with_features ))
1205
+ project_config = optimizely_instance . config
1214
1206
1215
1207
def side_effect (* args , ** kwargs ):
1216
1208
feature_key = args [0 ]
@@ -1219,9 +1211,10 @@ def side_effect(*args, **kwargs):
1219
1211
1220
1212
return False
1221
1213
1222
- with mock .patch ('optimizely.optimizely.Optimizely.is_feature_enabled' ,
1223
- side_effect = side_effect ) as mock_is_feature_enabled :
1224
- received_features = opt_obj .get_enabled_features ('user_1' )
1214
+ with mock .patch (
1215
+ 'optimizely.optimizely.Optimizely.is_feature_enabled' ,
1216
+ side_effect = side_effect ) as mock_is_feature_enabled :
1217
+ received_features = optimizely_instance .get_enabled_features ('user_1' )
1225
1218
1226
1219
expected_enabled_features = ['test_feature_1' , 'test_feature_2' ]
1227
1220
self .assertEqual (sorted (expected_enabled_features ), sorted (received_features ))
@@ -1230,17 +1223,6 @@ def side_effect(*args, **kwargs):
1230
1223
mock_is_feature_enabled .assert_any_call ('test_feature_in_group' , 'user_1' , None )
1231
1224
mock_is_feature_enabled .assert_any_call ('test_feature_in_experiment_and_rollout' , 'user_1' , None )
1232
1225
1233
- def test_get_enabled_features__invalid_object (self ):
1234
- """ Test that get_enabled_features returns empty list if Optimizely object is not valid. """
1235
-
1236
- opt_obj = optimizely .Optimizely ('invalid_file' )
1237
-
1238
- with mock .patch ('optimizely.logger.SimpleLogger.log' ) as mock_logging :
1239
- self .assertEqual ([], opt_obj .get_enabled_features ('user_1' ))
1240
-
1241
- mock_logging .assert_called_once_with (enums .LogLevels .ERROR ,
1242
- 'Datafile has invalid format. Failing "get_enabled_features".' )
1243
-
1244
1226
1245
1227
class OptimizelyWithExceptionTest (base .BaseTest ):
1246
1228
def setUp (self ):
0 commit comments