@@ -1478,3 +1478,99 @@ def test_apply_experiment_rollout__update_flag_fails__rolls_back(
14781478 rule__segment = experiment .rollout_segment , operator = PERCENTAGE_SPLIT
14791479 )
14801480 assert condition .value == "20.0"
1481+
1482+
1483+ def test_get_experiment_rollout__rollout_exists__returns_representation (
1484+ experiment_with_rollout : Experiment ,
1485+ multivariate_options : list [MultivariateFeatureOption ],
1486+ ) -> None :
1487+ # Given a rollout (20%, options split 50/50, value "control") from the fixture
1488+ option_a , option_b , _ = multivariate_options
1489+
1490+ # When
1491+ rollout = services .get_experiment_rollout (experiment_with_rollout )
1492+
1493+ # Then
1494+ assert rollout is not None
1495+ assert rollout ["enabled" ] is True
1496+ assert rollout ["rollout_percentage" ] == 20.0
1497+ assert rollout ["feature_state_value" ] == {"type" : "string" , "value" : "control" }
1498+ assert {
1499+ (mv ["multivariate_feature_option" ], mv ["percentage_allocation" ])
1500+ for mv in rollout ["multivariate_feature_state_values" ]
1501+ } == {(option_a .id , 50.0 ), (option_b .id , 50.0 )}
1502+
1503+
1504+ def test_get_experiment_rollout__no_rollout__returns_none (
1505+ experiment : Experiment ,
1506+ ) -> None :
1507+ # Given an experiment without a rollout
1508+ # When / Then
1509+ assert services .get_experiment_rollout (experiment ) is None
1510+
1511+
1512+ def test_get_experiment_rollout__v2_versioning__returns_representation (
1513+ environment_v2_versioning : Environment ,
1514+ multivariate_feature : Feature ,
1515+ multivariate_options : list [MultivariateFeatureOption ],
1516+ admin_user : FFAdminUser ,
1517+ ) -> None :
1518+ # Given a rollout on a v2 environment
1519+ option_a , option_b , _ = multivariate_options
1520+ experiment = Experiment .objects .create (
1521+ environment = environment_v2_versioning ,
1522+ feature = multivariate_feature ,
1523+ name = "exp" ,
1524+ hypothesis = "h" ,
1525+ status = ExperimentStatus .CREATED ,
1526+ )
1527+ services .apply_experiment_rollout (
1528+ experiment ,
1529+ RolloutSpec (
1530+ enabled = True ,
1531+ rollout_percentage = 30.0 ,
1532+ feature_state_value = "control" ,
1533+ value_type = "string" ,
1534+ multivariate_values = [
1535+ MultivariateValueChangeSet (option_a .id , 60.0 ),
1536+ MultivariateValueChangeSet (option_b .id , 40.0 ),
1537+ ],
1538+ author = AuthorData (user = admin_user ),
1539+ ),
1540+ )
1541+
1542+ # When
1543+ rollout = services .get_experiment_rollout (experiment )
1544+
1545+ # Then
1546+ assert rollout is not None
1547+ assert rollout ["rollout_percentage" ] == 30.0
1548+ assert {
1549+ (mv ["multivariate_feature_option" ], mv ["percentage_allocation" ])
1550+ for mv in rollout ["multivariate_feature_state_values" ]
1551+ } == {(option_a .id , 60.0 ), (option_b .id , 40.0 )}
1552+
1553+
1554+ def test_get_experiment_rollout__boolean_value__returns_lowercase_string (
1555+ experiment : Experiment ,
1556+ admin_user : FFAdminUser ,
1557+ ) -> None :
1558+ # Given
1559+ services .apply_experiment_rollout (
1560+ experiment ,
1561+ RolloutSpec (
1562+ enabled = True ,
1563+ rollout_percentage = 20.0 ,
1564+ feature_state_value = "true" ,
1565+ value_type = "boolean" ,
1566+ multivariate_values = [],
1567+ author = AuthorData (user = admin_user ),
1568+ ),
1569+ )
1570+
1571+ # When
1572+ rollout = services .get_experiment_rollout (experiment )
1573+
1574+ # Then
1575+ assert rollout is not None
1576+ assert rollout ["feature_state_value" ] == {"type" : "boolean" , "value" : "true" }
0 commit comments