@@ -20,8 +20,9 @@ def test_flag_from_evaluation_result() -> None:
2020 flag_result : SDKFlagResult = {
2121 "enabled" : True ,
2222 "name" : "test_feature" ,
23- "reason" : "DEFAULT " ,
23+ "reason" : "SPLIT; weight=30 " ,
2424 "value" : "test-value" ,
25+ "variant" : "control" ,
2526 "metadata" : {"id" : 123 },
2627 }
2728
@@ -34,6 +35,25 @@ def test_flag_from_evaluation_result() -> None:
3435 assert flag .feature_name == "test_feature"
3536 assert flag .feature_id == 123
3637 assert flag .is_default is False
38+ assert flag .variant == "control"
39+
40+
41+ def test_flag_from_evaluation_result__no_variant__is_none () -> None :
42+ # Given
43+ flag_result : SDKFlagResult = {
44+ "enabled" : True ,
45+ "name" : "test_feature" ,
46+ "reason" : "DEFAULT" ,
47+ "value" : "test-value" ,
48+ "variant" : None ,
49+ "metadata" : {"id" : 123 },
50+ }
51+
52+ # When
53+ flag = Flag .from_evaluation_result (flag_result )
54+
55+ # Then
56+ assert flag .variant is None
3757
3858
3959@pytest .mark .parametrize (
@@ -47,6 +67,7 @@ def test_flag_from_evaluation_result() -> None:
4767 "name" : "feature1" ,
4868 "reason" : "DEFAULT" ,
4969 "value" : "value1" ,
70+ "variant" : None ,
5071 "metadata" : {"id" : 1 },
5172 }
5273 },
@@ -59,6 +80,7 @@ def test_flag_from_evaluation_result() -> None:
5980 "name" : "feature1" ,
6081 "reason" : "DEFAULT" ,
6182 "value" : "value1" ,
83+ "variant" : None ,
6284 "metadata" : {"id" : 1 },
6385 }
6486 },
@@ -71,20 +93,23 @@ def test_flag_from_evaluation_result() -> None:
7193 "name" : "feature1" ,
7294 "reason" : "DEFAULT" ,
7395 "value" : "value1" ,
96+ "variant" : None ,
7497 "metadata" : {"id" : 1 },
7598 },
7699 "feature2" : {
77100 "enabled" : True ,
78101 "name" : "feature2" ,
79102 "reason" : "DEFAULT" ,
80103 "value" : "value2" ,
104+ "variant" : None ,
81105 "metadata" : {"id" : 2 },
82106 },
83107 "feature3" : {
84108 "enabled" : True ,
85109 "name" : "feature3" ,
86110 "reason" : "DEFAULT" ,
87111 "value" : 42 ,
112+ "variant" : None ,
88113 "metadata" : {"id" : 3 },
89114 },
90115 },
@@ -136,6 +161,7 @@ def test_flag_from_evaluation_result_value_types(
136161 "name" : "test_feature" ,
137162 "reason" : "DEFAULT" ,
138163 "value" : value ,
164+ "variant" : None ,
139165 "metadata" : {"id" : 123 },
140166 }
141167
@@ -153,13 +179,45 @@ def test_flag_from_evaluation_result_missing_metadata__raises_expected() -> None
153179 "name" : "test_feature" ,
154180 "reason" : "DEFAULT" ,
155181 "value" : "test-value" ,
182+ "variant" : None ,
156183 }
157184
158185 # When & Then
159186 with pytest .raises (ValueError ):
160187 Flag .from_evaluation_result (flag_result )
161188
162189
190+ def test_flag_from_api_flag__sets_variant () -> None :
191+ # Given
192+ flag_data = {
193+ "enabled" : True ,
194+ "feature_state_value" : "test-value" ,
195+ "feature" : {"name" : "test_feature" , "id" : 123 },
196+ "variant" : "control" ,
197+ }
198+
199+ # When
200+ flag = Flag .from_api_flag (flag_data )
201+
202+ # Then
203+ assert flag .variant == "control"
204+
205+
206+ def test_flag_from_api_flag__no_variant__is_none () -> None :
207+ # Given - the REST API may not include `variant`
208+ flag_data = {
209+ "enabled" : True ,
210+ "feature_state_value" : "test-value" ,
211+ "feature" : {"name" : "test_feature" , "id" : 123 },
212+ }
213+
214+ # When
215+ flag = Flag .from_api_flag (flag_data )
216+
217+ # Then
218+ assert flag .variant is None
219+
220+
163221def test_get_flag_without_pipeline_processor () -> None :
164222 flags = Flags (
165223 flags = {
@@ -197,6 +255,7 @@ def make(
197255 "name" : "target" ,
198256 "enabled" : False ,
199257 "value" : "base-value" ,
258+ "variant" : None ,
200259 "metadata" : {"id" : 1 },
201260 },
202261 }
@@ -206,6 +265,7 @@ def make(
206265 "name" : f"noise_{ i } " ,
207266 "enabled" : True ,
208267 "value" : f"noise-value-{ i } " ,
268+ "variant" : None ,
209269 "metadata" : {"id" : 100 + i },
210270 }
211271 return {
0 commit comments