@@ -2371,6 +2371,48 @@ def test_is_feature_enabled__returns_false_when_user_is_not_bucketed_into_any_va
2371
2371
# Check that impression event is sent for rollout and send_flag_decisions = True
2372
2372
self .assertEqual (1 , mock_process .call_count )
2373
2373
2374
+ def test_is_feature_enabled__returns_false_when_variation_is_nil (self ,):
2375
+ """ Test that the feature is not enabled with nil variation
2376
+ Also confirm that impression event is processed. """
2377
+
2378
+ opt_obj = optimizely .Optimizely (json .dumps (self .config_dict_with_features ))
2379
+ project_config = opt_obj .config_manager .get_config ()
2380
+ feature = project_config .get_feature_from_key ('test_feature_in_experiment_and_rollout' )
2381
+ with mock .patch (
2382
+ 'optimizely.decision_service.DecisionService.get_variation_for_feature' ,
2383
+ return_value = decision_service .Decision (None , None , enums .DecisionSources .ROLLOUT ),
2384
+ ) as mock_decision , mock .patch (
2385
+ 'optimizely.event.event_processor.ForwardingEventProcessor.process'
2386
+ ) as mock_process , mock .patch (
2387
+ 'optimizely.notification_center.NotificationCenter.send_notifications'
2388
+ ) as mock_broadcast_decision , mock .patch (
2389
+ 'uuid.uuid4' , return_value = 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c'
2390
+ ), mock .patch (
2391
+ 'time.time' , return_value = 42
2392
+ ):
2393
+ self .assertFalse (opt_obj .is_feature_enabled ("test_feature_in_experiment_and_rollout" , 'test_user' ))
2394
+
2395
+ # Check that impression event is sent for rollout and send_flag_decisions = True
2396
+ self .assertEqual (1 , mock_process .call_count )
2397
+
2398
+ mock_decision .assert_called_once_with (opt_obj .config_manager .get_config (), feature , 'test_user' , None )
2399
+
2400
+ mock_broadcast_decision .assert_called_with (
2401
+ enums .NotificationTypes .DECISION ,
2402
+ 'feature' ,
2403
+ 'test_user' ,
2404
+ {},
2405
+ {
2406
+ 'feature_key' : 'test_feature_in_experiment_and_rollout' ,
2407
+ 'feature_enabled' : False ,
2408
+ 'source' : 'rollout' ,
2409
+ 'source_info' : {},
2410
+ },
2411
+ )
2412
+
2413
+ # Check that impression event is sent for rollout and send_flag_decisions = True
2414
+ self .assertEqual (1 , mock_process .call_count )
2415
+
2374
2416
def test_is_feature_enabled__invalid_object (self ):
2375
2417
""" Test that is_feature_enabled returns False and logs error if Optimizely instance is invalid. """
2376
2418
0 commit comments