@@ -1436,7 +1436,7 @@ def test_get_feature_variable_boolean(self):
1436
1436
1437
1437
mock_logger .assert_called_once_with (
1438
1438
enums .LogLevels .INFO ,
1439
- 'Value for variable "is_working" of feature flag "test_feature_in_experiment " is true for user "test_user ".'
1439
+ 'Value for variable "is_working" for variation "variation " is "true ".'
1440
1440
)
1441
1441
1442
1442
def test_get_feature_variable_double (self ):
@@ -1454,7 +1454,7 @@ def test_get_feature_variable_double(self):
1454
1454
1455
1455
mock_logger .assert_called_once_with (
1456
1456
enums .LogLevels .INFO ,
1457
- 'Value for variable "cost" of feature flag "test_feature_in_experiment " is 10.02 for user "test_user ".'
1457
+ 'Value for variable "cost" for variation "variation " is " 10.02".'
1458
1458
)
1459
1459
1460
1460
def test_get_feature_variable_integer (self ):
@@ -1472,7 +1472,7 @@ def test_get_feature_variable_integer(self):
1472
1472
1473
1473
mock_logger .assert_called_once_with (
1474
1474
enums .LogLevels .INFO ,
1475
- 'Value for variable "count" of feature flag "test_feature_in_experiment " is 4243 for user "test_user ".'
1475
+ 'Value for variable "count" for variation "variation " is "4243 ".'
1476
1476
)
1477
1477
1478
1478
def test_get_feature_variable_string (self ):
@@ -1491,10 +1491,71 @@ def test_get_feature_variable_string(self):
1491
1491
1492
1492
mock_logger .assert_called_once_with (
1493
1493
enums .LogLevels .INFO ,
1494
- 'Value for variable "environment" of feature flag "test_feature_in_experiment " is staging for user "test_user ".'
1494
+ 'Value for variable "environment" for variation "variation " is "staging ".'
1495
1495
)
1496
1496
1497
- def test_get_feature_variable__returns_default_value (self ):
1497
+ def test_get_feature_variable__returns_default_value_if_variable_usage_not_in_variation (self ):
1498
+ """ Test that get_feature_variable_* returns default value if variable usage not present in variation. """
1499
+
1500
+ opt_obj = optimizely .Optimizely (json .dumps (self .config_dict_with_features ))
1501
+ mock_experiment = opt_obj .config .get_experiment_from_key ('test_experiment' )
1502
+ mock_variation = opt_obj .config .get_variation_from_id ('test_experiment' , '111129' )
1503
+
1504
+ # Empty variable usage map for the mocked variation
1505
+ opt_obj .config .variation_variable_usage_map ['111129' ] = None
1506
+
1507
+ # Boolean
1508
+ with mock .patch ('optimizely.decision_service.DecisionService.get_variation_for_feature' ,
1509
+ return_value = decision_service .Decision (mock_experiment , mock_variation ,
1510
+ decision_service .DECISION_SOURCE_EXPERIMENT )), \
1511
+ mock .patch ('optimizely.logger.NoOpLogger.log' ) as mock_logger :
1512
+ self .assertTrue (opt_obj .get_feature_variable_boolean ('test_feature_in_experiment' , 'is_working' , 'test_user' ))
1513
+
1514
+ mock_logger .assert_called_once_with (
1515
+ enums .LogLevels .INFO ,
1516
+ 'Variable "is_working" is not used in variation "variation". Assinging default value "true".'
1517
+ )
1518
+
1519
+ # Double
1520
+ with mock .patch ('optimizely.decision_service.DecisionService.get_variation_for_feature' ,
1521
+ return_value = decision_service .Decision (mock_experiment , mock_variation ,
1522
+ decision_service .DECISION_SOURCE_EXPERIMENT )), \
1523
+ mock .patch ('optimizely.logger.NoOpLogger.log' ) as mock_logger :
1524
+ self .assertEqual (10.99 ,
1525
+ opt_obj .get_feature_variable_double ('test_feature_in_experiment' , 'cost' , 'test_user' ))
1526
+
1527
+ mock_logger .assert_called_once_with (
1528
+ enums .LogLevels .INFO ,
1529
+ 'Variable "cost" is not used in variation "variation". Assinging default value "10.99".'
1530
+ )
1531
+
1532
+ # Integer
1533
+ with mock .patch ('optimizely.decision_service.DecisionService.get_variation_for_feature' ,
1534
+ return_value = decision_service .Decision (mock_experiment , mock_variation ,
1535
+ decision_service .DECISION_SOURCE_EXPERIMENT )), \
1536
+ mock .patch ('optimizely.logger.NoOpLogger.log' ) as mock_logger :
1537
+ self .assertEqual (999 ,
1538
+ opt_obj .get_feature_variable_integer ('test_feature_in_experiment' , 'count' , 'test_user' ))
1539
+
1540
+ mock_logger .assert_called_once_with (
1541
+ enums .LogLevels .INFO ,
1542
+ 'Variable "count" is not used in variation "variation". Assinging default value "999".'
1543
+ )
1544
+
1545
+ # String
1546
+ with mock .patch ('optimizely.decision_service.DecisionService.get_variation_for_feature' ,
1547
+ return_value = decision_service .Decision (mock_experiment , mock_variation ,
1548
+ decision_service .DECISION_SOURCE_EXPERIMENT )), \
1549
+ mock .patch ('optimizely.logger.NoOpLogger.log' ) as mock_logger :
1550
+ self .assertEqual ('devel' ,
1551
+ opt_obj .get_feature_variable_string ('test_feature_in_experiment' , 'environment' , 'test_user' ))
1552
+
1553
+ mock_logger .assert_called_once_with (
1554
+ enums .LogLevels .INFO ,
1555
+ 'Variable "environment" is not used in variation "variation". Assinging default value "devel".'
1556
+ )
1557
+
1558
+ def test_get_feature_variable__returns_default_value_if_no_variation (self ):
1498
1559
""" Test that get_feature_variable_* returns default value if no variation. """
1499
1560
1500
1561
opt_obj = optimizely .Optimizely (json .dumps (self .config_dict_with_features ))
0 commit comments