@@ -1387,29 +1387,6 @@ def side_effect(*args, **kwargs):
1387
1387
mock_is_feature_enabled .assert_any_call ('test_feature_in_group' , 'user_1' , None )
1388
1388
mock_is_feature_enabled .assert_any_call ('test_feature_in_experiment_and_rollout' , 'user_1' , None )
1389
1389
1390
- def test_get_enabled_features_returns_a_sorted_list (self ):
1391
- """ Test that get_enabled_features returns a sorted list of enabled feature keys. """
1392
-
1393
- opt_obj = optimizely .Optimizely (json .dumps (self .config_dict_with_features ))
1394
-
1395
- with mock .patch ('optimizely.optimizely.Optimizely.is_feature_enabled' ,
1396
- return_value = True ) as mock_is_feature_enabled :
1397
- received_features = opt_obj .get_enabled_features ('user_1' )
1398
-
1399
- mock_is_feature_enabled .assert_any_call ('test_feature_in_experiment' , 'user_1' , None )
1400
- mock_is_feature_enabled .assert_any_call ('test_feature_in_rollout' , 'user_1' , None )
1401
- mock_is_feature_enabled .assert_any_call ('test_feature_in_group' , 'user_1' , None )
1402
- mock_is_feature_enabled .assert_any_call ('test_feature_in_experiment_and_rollout' , 'user_1' , None )
1403
-
1404
- expected_sorted_features = [
1405
- 'test_feature_in_experiment' ,
1406
- 'test_feature_in_experiment_and_rollout' ,
1407
- 'test_feature_in_group' ,
1408
- 'test_feature_in_rollout'
1409
- ]
1410
-
1411
- self .assertEqual (expected_sorted_features , received_features )
1412
-
1413
1390
def test_get_enabled_features__invalid_object (self ):
1414
1391
""" Test that get_enabled_features returns empty list if Optimizely object is not valid. """
1415
1392
@@ -1436,7 +1413,7 @@ def test_get_feature_variable_boolean(self):
1436
1413
1437
1414
mock_logger .assert_called_once_with (
1438
1415
enums .LogLevels .INFO ,
1439
- 'Value for variable "is_working" of feature flag "test_feature_in_experiment " is true for user "test_user ".'
1416
+ 'Value for variable "is_working" for variation "variation " is "true ".'
1440
1417
)
1441
1418
1442
1419
def test_get_feature_variable_double (self ):
@@ -1454,7 +1431,7 @@ def test_get_feature_variable_double(self):
1454
1431
1455
1432
mock_logger .assert_called_once_with (
1456
1433
enums .LogLevels .INFO ,
1457
- 'Value for variable "cost" of feature flag "test_feature_in_experiment " is 10.02 for user "test_user ".'
1434
+ 'Value for variable "cost" for variation "variation " is " 10.02".'
1458
1435
)
1459
1436
1460
1437
def test_get_feature_variable_integer (self ):
@@ -1472,7 +1449,7 @@ def test_get_feature_variable_integer(self):
1472
1449
1473
1450
mock_logger .assert_called_once_with (
1474
1451
enums .LogLevels .INFO ,
1475
- 'Value for variable "count" of feature flag "test_feature_in_experiment " is 4243 for user "test_user ".'
1452
+ 'Value for variable "count" for variation "variation " is "4243 ".'
1476
1453
)
1477
1454
1478
1455
def test_get_feature_variable_string (self ):
@@ -1491,10 +1468,71 @@ def test_get_feature_variable_string(self):
1491
1468
1492
1469
mock_logger .assert_called_once_with (
1493
1470
enums .LogLevels .INFO ,
1494
- 'Value for variable "environment" of feature flag "test_feature_in_experiment" is staging for user "test_user".'
1471
+ 'Value for variable "environment" for variation "variation" is "staging".'
1472
+ )
1473
+
1474
+ def test_get_feature_variable__returns_default_value_if_variable_usage_not_in_variation (self ):
1475
+ """ Test that get_feature_variable_* returns default value if variable usage not present in variation. """
1476
+
1477
+ opt_obj = optimizely .Optimizely (json .dumps (self .config_dict_with_features ))
1478
+ mock_experiment = opt_obj .config .get_experiment_from_key ('test_experiment' )
1479
+ mock_variation = opt_obj .config .get_variation_from_id ('test_experiment' , '111129' )
1480
+
1481
+ # Empty variable usage map for the mocked variation
1482
+ opt_obj .config .variation_variable_usage_map ['111129' ] = None
1483
+
1484
+ # Boolean
1485
+ with mock .patch ('optimizely.decision_service.DecisionService.get_variation_for_feature' ,
1486
+ return_value = decision_service .Decision (mock_experiment , mock_variation ,
1487
+ decision_service .DECISION_SOURCE_EXPERIMENT )), \
1488
+ mock .patch ('optimizely.logger.NoOpLogger.log' ) as mock_logger :
1489
+ self .assertTrue (opt_obj .get_feature_variable_boolean ('test_feature_in_experiment' , 'is_working' , 'test_user' ))
1490
+
1491
+ mock_logger .assert_called_once_with (
1492
+ enums .LogLevels .INFO ,
1493
+ 'Variable "is_working" is not used in variation "variation". Assinging default value "true".'
1494
+ )
1495
+
1496
+ # Double
1497
+ with mock .patch ('optimizely.decision_service.DecisionService.get_variation_for_feature' ,
1498
+ return_value = decision_service .Decision (mock_experiment , mock_variation ,
1499
+ decision_service .DECISION_SOURCE_EXPERIMENT )), \
1500
+ mock .patch ('optimizely.logger.NoOpLogger.log' ) as mock_logger :
1501
+ self .assertEqual (10.99 ,
1502
+ opt_obj .get_feature_variable_double ('test_feature_in_experiment' , 'cost' , 'test_user' ))
1503
+
1504
+ mock_logger .assert_called_once_with (
1505
+ enums .LogLevels .INFO ,
1506
+ 'Variable "cost" is not used in variation "variation". Assinging default value "10.99".'
1507
+ )
1508
+
1509
+ # Integer
1510
+ with mock .patch ('optimizely.decision_service.DecisionService.get_variation_for_feature' ,
1511
+ return_value = decision_service .Decision (mock_experiment , mock_variation ,
1512
+ decision_service .DECISION_SOURCE_EXPERIMENT )), \
1513
+ mock .patch ('optimizely.logger.NoOpLogger.log' ) as mock_logger :
1514
+ self .assertEqual (999 ,
1515
+ opt_obj .get_feature_variable_integer ('test_feature_in_experiment' , 'count' , 'test_user' ))
1516
+
1517
+ mock_logger .assert_called_once_with (
1518
+ enums .LogLevels .INFO ,
1519
+ 'Variable "count" is not used in variation "variation". Assinging default value "999".'
1520
+ )
1521
+
1522
+ # String
1523
+ with mock .patch ('optimizely.decision_service.DecisionService.get_variation_for_feature' ,
1524
+ return_value = decision_service .Decision (mock_experiment , mock_variation ,
1525
+ decision_service .DECISION_SOURCE_EXPERIMENT )), \
1526
+ mock .patch ('optimizely.logger.NoOpLogger.log' ) as mock_logger :
1527
+ self .assertEqual ('devel' ,
1528
+ opt_obj .get_feature_variable_string ('test_feature_in_experiment' , 'environment' , 'test_user' ))
1529
+
1530
+ mock_logger .assert_called_once_with (
1531
+ enums .LogLevels .INFO ,
1532
+ 'Variable "environment" is not used in variation "variation". Assinging default value "devel".'
1495
1533
)
1496
1534
1497
- def test_get_feature_variable__returns_default_value (self ):
1535
+ def test_get_feature_variable__returns_default_value_if_no_variation (self ):
1498
1536
""" Test that get_feature_variable_* returns default value if no variation. """
1499
1537
1500
1538
opt_obj = optimizely .Optimizely (json .dumps (self .config_dict_with_features ))
0 commit comments