@@ -1398,29 +1398,6 @@ def side_effect(*args, **kwargs):
1398
1398
mock_is_feature_enabled .assert_any_call ('test_feature_in_group' , 'user_1' , None )
1399
1399
mock_is_feature_enabled .assert_any_call ('test_feature_in_experiment_and_rollout' , 'user_1' , None )
1400
1400
1401
- def test_get_enabled_features_returns_a_sorted_list (self ):
1402
- """ Test that get_enabled_features returns a sorted list of enabled feature keys. """
1403
-
1404
- opt_obj = optimizely .Optimizely (json .dumps (self .config_dict_with_features ))
1405
-
1406
- with mock .patch ('optimizely.optimizely.Optimizely.is_feature_enabled' ,
1407
- return_value = True ) as mock_is_feature_enabled :
1408
- received_features = opt_obj .get_enabled_features ('user_1' )
1409
-
1410
- mock_is_feature_enabled .assert_any_call ('test_feature_in_experiment' , 'user_1' , None )
1411
- mock_is_feature_enabled .assert_any_call ('test_feature_in_rollout' , 'user_1' , None )
1412
- mock_is_feature_enabled .assert_any_call ('test_feature_in_group' , 'user_1' , None )
1413
- mock_is_feature_enabled .assert_any_call ('test_feature_in_experiment_and_rollout' , 'user_1' , None )
1414
-
1415
- expected_sorted_features = [
1416
- 'test_feature_in_experiment' ,
1417
- 'test_feature_in_experiment_and_rollout' ,
1418
- 'test_feature_in_group' ,
1419
- 'test_feature_in_rollout'
1420
- ]
1421
-
1422
- self .assertEqual (expected_sorted_features , received_features )
1423
-
1424
1401
def test_get_enabled_features__invalid_object (self ):
1425
1402
""" Test that get_enabled_features returns empty list if Optimizely object is not valid. """
1426
1403
@@ -1447,7 +1424,7 @@ def test_get_feature_variable_boolean(self):
1447
1424
1448
1425
mock_logger .assert_called_once_with (
1449
1426
enums .LogLevels .INFO ,
1450
- 'Value for variable "is_working" of feature flag "test_feature_in_experiment " is true for user "test_user ".'
1427
+ 'Value for variable "is_working" for variation "variation " is "true ".'
1451
1428
)
1452
1429
1453
1430
def test_get_feature_variable_double (self ):
@@ -1465,7 +1442,7 @@ def test_get_feature_variable_double(self):
1465
1442
1466
1443
mock_logger .assert_called_once_with (
1467
1444
enums .LogLevels .INFO ,
1468
- 'Value for variable "cost" of feature flag "test_feature_in_experiment " is 10.02 for user "test_user ".'
1445
+ 'Value for variable "cost" for variation "variation " is " 10.02".'
1469
1446
)
1470
1447
1471
1448
def test_get_feature_variable_integer (self ):
@@ -1483,7 +1460,7 @@ def test_get_feature_variable_integer(self):
1483
1460
1484
1461
mock_logger .assert_called_once_with (
1485
1462
enums .LogLevels .INFO ,
1486
- 'Value for variable "count" of feature flag "test_feature_in_experiment " is 4243 for user "test_user ".'
1463
+ 'Value for variable "count" for variation "variation " is "4243 ".'
1487
1464
)
1488
1465
1489
1466
def test_get_feature_variable_string (self ):
@@ -1502,10 +1479,71 @@ def test_get_feature_variable_string(self):
1502
1479
1503
1480
mock_logger .assert_called_once_with (
1504
1481
enums .LogLevels .INFO ,
1505
- 'Value for variable "environment" of feature flag "test_feature_in_experiment" is staging for user "test_user".'
1482
+ 'Value for variable "environment" for variation "variation" is "staging".'
1483
+ )
1484
+
1485
+ def test_get_feature_variable__returns_default_value_if_variable_usage_not_in_variation (self ):
1486
+ """ Test that get_feature_variable_* returns default value if variable usage not present in variation. """
1487
+
1488
+ opt_obj = optimizely .Optimizely (json .dumps (self .config_dict_with_features ))
1489
+ mock_experiment = opt_obj .config .get_experiment_from_key ('test_experiment' )
1490
+ mock_variation = opt_obj .config .get_variation_from_id ('test_experiment' , '111129' )
1491
+
1492
+ # Empty variable usage map for the mocked variation
1493
+ opt_obj .config .variation_variable_usage_map ['111129' ] = None
1494
+
1495
+ # Boolean
1496
+ with mock .patch ('optimizely.decision_service.DecisionService.get_variation_for_feature' ,
1497
+ return_value = decision_service .Decision (mock_experiment , mock_variation ,
1498
+ decision_service .DECISION_SOURCE_EXPERIMENT )), \
1499
+ mock .patch ('optimizely.logger.NoOpLogger.log' ) as mock_logger :
1500
+ self .assertTrue (opt_obj .get_feature_variable_boolean ('test_feature_in_experiment' , 'is_working' , 'test_user' ))
1501
+
1502
+ mock_logger .assert_called_once_with (
1503
+ enums .LogLevels .INFO ,
1504
+ 'Variable "is_working" is not used in variation "variation". Assinging default value "true".'
1505
+ )
1506
+
1507
+ # Double
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 .assertEqual (10.99 ,
1513
+ opt_obj .get_feature_variable_double ('test_feature_in_experiment' , 'cost' , 'test_user' ))
1514
+
1515
+ mock_logger .assert_called_once_with (
1516
+ enums .LogLevels .INFO ,
1517
+ 'Variable "cost" is not used in variation "variation". Assinging default value "10.99".'
1518
+ )
1519
+
1520
+ # Integer
1521
+ with mock .patch ('optimizely.decision_service.DecisionService.get_variation_for_feature' ,
1522
+ return_value = decision_service .Decision (mock_experiment , mock_variation ,
1523
+ decision_service .DECISION_SOURCE_EXPERIMENT )), \
1524
+ mock .patch ('optimizely.logger.NoOpLogger.log' ) as mock_logger :
1525
+ self .assertEqual (999 ,
1526
+ opt_obj .get_feature_variable_integer ('test_feature_in_experiment' , 'count' , 'test_user' ))
1527
+
1528
+ mock_logger .assert_called_once_with (
1529
+ enums .LogLevels .INFO ,
1530
+ 'Variable "count" is not used in variation "variation". Assinging default value "999".'
1531
+ )
1532
+
1533
+ # String
1534
+ with mock .patch ('optimizely.decision_service.DecisionService.get_variation_for_feature' ,
1535
+ return_value = decision_service .Decision (mock_experiment , mock_variation ,
1536
+ decision_service .DECISION_SOURCE_EXPERIMENT )), \
1537
+ mock .patch ('optimizely.logger.NoOpLogger.log' ) as mock_logger :
1538
+ self .assertEqual ('devel' ,
1539
+ opt_obj .get_feature_variable_string ('test_feature_in_experiment' , 'environment' , 'test_user' ))
1540
+
1541
+ mock_logger .assert_called_once_with (
1542
+ enums .LogLevels .INFO ,
1543
+ 'Variable "environment" is not used in variation "variation". Assinging default value "devel".'
1506
1544
)
1507
1545
1508
- def test_get_feature_variable__returns_default_value (self ):
1546
+ def test_get_feature_variable__returns_default_value_if_no_variation (self ):
1509
1547
""" Test that get_feature_variable_* returns default value if no variation. """
1510
1548
1511
1549
opt_obj = optimizely .Optimizely (json .dumps (self .config_dict_with_features ))
0 commit comments